marker in a docker with llama-swap and free vram on idle support
496
This guide explains how to deploy Marker PDF using Docker with both GPU and CPU support.
docker run -d \
--name marker-pdf-gpu \
--gpus all \
-p 8001:8001 \
-v marker-models:/root/.cache/huggingface \
-v marker-torch:/root/.cache/torch \
-v ./uploads:/app/uploads \
-v ./output:/app/output \
-e USE_LLM=true \
-e OPENAI_API_KEY=your-api-key \
marker-pdf:gpu
The following environment variables can be configured:
| Variable | Default | Description |
|---|---|---|
PORT | 8001 | Server port |
HOST | 0.0.0.0 | Server host |
TORCH_DEVICE | cuda/cpu | Device to use (auto-set by image) |
FREE_VRAM_ON_IDLE | false | Unload models after processing to free VRAM (slower first request, saves ~3-5GB VRAM) |
| Variable | Default | Description |
|---|---|---|
LLM_SERVICE | auto-detect | Explicitly specify LLM service (auto-detected from available API keys if not set) |
Note: The first available LLM provider (based on configured API keys) will be auto-selected in this priority order:
GEMINI_API_KEY → GoogleGeminiServiceOPENAI_API_KEY → OpenAIServiceCLAUDE_API_KEY → ClaudeServiceAZURE_API_KEY → AzureOpenAIServiceOLLAMA_BASE_URL → OllamaServiceOpenWebUI Control: Use the use_llm toggle in OpenWebUI to enable/disable LLM processing per request.
| Variable | Default | Description |
|---|---|---|
OPENAI_API_KEY | - | OpenAI API key |
OPENAI_MODEL | gpt-4o-mini | Model name |
OPENAI_BASE_URL | https://api.openai.com/v1 | API base URL |
OPENAI_IMAGE_FORMAT | png | Image format (png/webp/jpeg) - recommended for compatibility |
UNLOAD_LLAMA_SWAP_BASE_URL | - | Llama-swap service URL to unload models before OCR (e.g., http://172.17.0.1:9292). If set, unloads the llama-swap model before OCR to free VRAM. Requires llama-swap service running separately. |
| Variable | Default | Description |
|---|---|---|
GEMINI_API_KEY | - | Google Gemini API key |
GOOGLE_API_KEY | - | Alias for GEMINI_API_KEY |
GEMINI_MODEL_NAME | gemini-2.0-flash | Model name |
THINKING_BUDGET | - | Thinking token budget |
| Variable | Default | Description |
|---|---|---|
CLAUDE_API_KEY | - | Anthropic API key |
ANTHROPIC_API_KEY | - | Alias for CLAUDE_API_KEY |
CLAUDE_MODEL_NAME | claude-3-7-sonnet-20250219 | Model name |
MAX_CLAUDE_TOKENS | 8192 | Max output tokens |
| Variable | Default | Description |
|---|---|---|
AZURE_ENDPOINT | - | Azure endpoint URL |
AZURE_API_KEY | - | Azure API key |
AZURE_API_VERSION | - | API version |
DEPLOYMENT_NAME | - | Deployment name |
| Variable | Default | Description |
|---|---|---|
OLLAMA_BASE_URL | http://localhost:11434 | Ollama server URL |
OLLAMA_MODEL | llama3.2-vision | Model name |
| Variable | Default | Description |
|---|---|---|
SKIP_CACHE | false | Skip using cached results |
FORCE_OCR | false | Force OCR on all pages |
PAGINATE | false | Add page numbers to output |
DISABLE_IMAGE_EXTRACTION | false | Don't extract images |
OUTPUT_FORMAT | markdown | Output format (markdown/json/html) |
| Variable | Default | Description |
|---|---|---|
LANGS | en | Languages to support |
BATCH_MULTIPLIER | 1 | Batch size multiplier |
MAX_PAGES | - | Max pages to process |
TIMEOUT | 30 | LLM request timeout (seconds) |
MAX_RETRIES | 2 | Max retry attempts |
RETRY_WAIT_TIME | 3 | Wait between retries (seconds) |
MAX_OUTPUT_TOKENS | - | Max tokens to generate |
environment:
- USE_LLM=true
- LLM_SERVICE=marker.services.openai.OpenAIService
- OPENAI_API_KEY=sk-...
- OPENAI_MODEL=gpt-4o
- FORCE_OCR=true
- OUTPUT_FORMAT=json
- PAGINATE=true
environment:
- USE_LLM=true
- LLM_SERVICE=marker.services.ollama.OllamaService
- OLLAMA_BASE_URL=http://host.docker.internal:11434
- OLLAMA_MODEL=llama3.2-vision
- OUTPUT_FORMAT=markdown
environment:
- USE_LLM=true
- LLM_SERVICE=marker.services.claude.ClaudeService
- CLAUDE_API_KEY=sk-ant-...
- CLAUDE_MODEL_NAME=claude-3-7-sonnet-20250219
- MAX_CLAUDE_TOKENS=16384
Marker PDF is designed to work seamlessly with OpenWebUI. Here's how to configure it:
When integrated with OpenWebUI, the LLM feature works as follows:
use_llm: true/false in requests based on the toggleuse_llm is false, marker_server processes PDFs normally without LLMKey Advantage: Set up your LLM provider once in environment variables - OpenWebUI handles the rest with its toggle.
In OpenWebUI, add Marker PDF as an external tool with the following configuration:
Endpoint URL:
http://marker-pdf:8001/marker/upload
Method: POST
Content Type: multipart/form-data
services:
marker-pdf:
image: bankja/marker:cuda
networks:
- openwebui
environment:
- PORT=8001
- HOST=0.0.0.0
# Configure ONE LLM provider (first available will be used):
# - OPENAI_API_KEY=${OPENAI_API_KEY}
# - OPENAI_MODEL=gpt-4o-mini
# OR
- GEMINI_API_KEY=${GEMINI_API_KEY}
- GEMINI_MODEL_NAME=gemini-2.0-flash
# OR (uncomment for other providers)
# - CLAUDE_API_KEY=${CLAUDE_API_KEY}
# - OLLAMA_BASE_URL=http://host.docker.internal:11434
volumes:
- ./datalab:/root/.cache/datalab
openwebui:
image: ghcr.io/open-webui/open-webui:main
ports:
- "3000:8080"
networks:
- openwebui
environment:
- MARKER_API_URL=http://marker-pdf:8001
# Your API keys for the LLM provider
- OPENAI_API_KEY=${OPENAI_API_KEY} # Or GEMINI_API_KEY, etc.
networks:
openwebui:
driver: bridge
use_llm: true: Marker PDF will use the configured LLM provider (based on environment variables) for enhanced PDF processinguse_llm: false or not sent: Marker PDF processes PDFs normally without LLM, using original fast processingModel Cache (Highly Recommended):
-v ./datalab:/root/.cache/datalab
These volumes persist downloaded models across container restarts. Without them, models (~2-3GB) will be re-downloaded each time.
Uploads Directory:
-v ./uploads:/app/uploads
Persist uploaded files.
Output Directory:
-v ./output:/app/output
Access generated output files from the host.
Custom Configuration:
-v ./config:/app/config
Mount custom configuration files.
Once the container is running:
# Upload and convert a PDF
curl -X POST "http://localhost:8001/marker/upload" \
-F "[email protected]" \
-F "output_format=markdown"
# Convert from filepath (if mounted)
curl -X POST "http://localhost:8001/marker" \
-H "Content-Type: application/json" \
-d '{
"filepath": "/app/uploads/document.pdf",
"output_format": "markdown",
"use_llm": true
}'
Problem: Models are downloaded every time the container starts.
Solution: Ensure you're using volume mounts for model cache:
-v ./datalab:/root/.cache/datalab
Problem: Container can't access GPU.
Solution:
--gpus all flag or docker-compose GPU configurationdocker run --rm --gpus all marker-pdf:gpu nvidia-smiProblem: Container runs out of VRAM/RAM.
Solution:
BATCH_MULTIPLIER=0.5MAX_PAGES=100FREE_VRAM_ON_IDLE=true to unload models after processing (uses ~0GB idle VRAM, adds ~2-5s per request for model loading)Problem: Device has insufficient VRAM for standard operation (requires 5GB peak).
Solution: Enable dynamic VRAM management:
docker run -d \
--name marker-pdf-gpu \
--gpus all \
-p 8001:8001 \
-e FREE_VRAM_ON_IDLE=true \
-v marker-models:/root/.cache/huggingface \
-v marker-torch:/root/.cache/torch \
marker-pdf:gpu
For systems using llama-swap with USE_LLM=true, additionally unload the llama-swap model before OCR:
docker run -d \
--name marker-pdf-gpu \
--gpus all \
-p 8001:8001 \
-e FREE_VRAM_ON_IDLE=true \
-e USE_LLM=true \
-e UNLOAD_LLAMA_SWAP_BASE_URL=http://172.17.0.1:9292 \
-v marker-models:/root/.cache/huggingface \
-v marker-torch:/root/.cache/torch \
marker-pdf:gpu
Trade-offs:
Performance Impact:
FREE_VRAM_ON_IDLE=false (default): Fast processing, high idle VRAM usageFREE_VRAM_ON_IDLE=true: Slower first request per idle period, minimal idle VRAMUNLOAD_LLAMA_SWAP_BASE_URL set: LLM model unloaded before OCR, maximizing available VRAM for OCRProblem: Port 8001 is already in use.
Solution: Change the port mapping:
-p 8002:8001 # Use port 8002 on host
Or set PORT environment variable:
-e PORT=8002 -p 8002:8002
Problem: OpenWebUI can't connect to Marker PDF.
Solution:
http://marker-pdf:8001docker compose logs marker-gpudeploy:
resources:
reservations:
devices:
- driver: nvidia
count: 2 # Use 2 GPUs
capabilities: [gpu]
For full details:
This Docker setup follows the same license as the Marker project.
Content type
Image
Digest
sha256:e7dcaa3a0…
Size
7 GB
Last updated
10 months ago
docker pull bankja/marker:cuda