GPU Accelerator Support#
Docling supports hardware-accelerated inference across four device backends: CUDA (NVIDIA), MPS (Apple Silicon via Metal Performance Shaders), XPU (Intel GPU), and CPU. Device selection is centralized in two files:
accelerator_options.py— definesAcceleratorDeviceandAcceleratorOptionsaccelerator_utils.py— implementsdecide_device(), the runtime resolution function
Configuration#
AcceleratorOptions is a Pydantic BaseSettings model, meaning fields can be set programmatically or via environment variables (prefix: DOCLING_) :
| Field | Default | Env var |
|---|---|---|
device | "auto" | DOCLING_DEVICE |
num_threads | 4 | DOCLING_NUM_THREADS or OMP_NUM_THREADS |
cuda_use_flash_attention2 | False | DOCLING_CUDA_USE_FLASH_ATTENTION2 |
Valid device values: auto, cpu, cuda, cuda:N (specific GPU index), mps, xpu .
Flash Attention 2 requires the flash-attn package and a compatible NVIDIA Ampere-or-newer GPU .
Device Resolution (decide_device)#
decide_device(accelerator_device, supported_devices) is called by each model at initialization. It:
- Probes availability: checks
torch.cuda.is_available(),torch.backends.mps.is_available(), andtorch.xpu.is_available(). - Filters by
supported_devices: if a model passes asupported_deviceslist, unavailable-or-excluded accelerators are silently removed from consideration . - Resolves in AUTO mode: priority order is CUDA → MPS → XPU → CPU .
- Raises
AcceleratorDeviceNotAvailableErrorif an explicitly requested device is unavailable or not in the model'ssupported_devices.
Recommendation: Use device="auto" unless targeting a specific GPU index. Explicit device values will raise hard errors if the hardware is absent.
Per-Component Accelerator Support Matrix#
Support is inconsistent across Docling's inference components:
| Component | CUDA | MPS | XPU | CPU | Notes |
|---|---|---|---|---|---|
Layout detection (LayoutPredictor) | ✅ | ✅ | ✅ | ✅ | All accelerators supported |
| TableFormer V1 | ✅ | ❌→CPU | ✅ | ✅ | MPS silently downgraded to CPU at init |
| TableFormer V2 | ✅ | ❌→CPU | ✅ | ✅ | Same forced MPS→CPU override |
| VLM / Transformers engine | ✅ | ❌ | ✅ | ✅ | MPS not in supported_devices; raises error if forced |
| VLM / MLX engine | ❌ | ✅ (via MLX) | ❌ | ❌ | Apple Silicon only; uses MLX, not raw MPS |
| ASR / MLX Whisper | ❌ | ✅ | ❌ | ❌ | Auto-selected when mps.is_available() and mlx-whisper installed |
| Chart extraction (GraniteVision) | ✅ | ❌ | ❌ | ✅ | CPU and CUDA only |
| Nemotron OCR | ✅ (CUDA 13.x) | ❌ | ❌ | ❌ | Linux x86_64 + Python 3.12 only |
| EasyOCR | ✅ | ✅ | ❌ | ✅ | GPU via MPS |
Key distinction on Apple Silicon: VLM workloads use MLX (via MlxVlmEngine) rather than raw MPS. The AUTO_INLINE VLM engine selects MLX automatically on macOS when the model has an MLX export and mlx-vlm is installed; otherwise it falls back to Transformers on CPU .
CUDA-Specific Options#
- Multi-GPU: Use
cuda:N(e.g.,cuda:1) to target a specific GPU.decide_devicevalidates the index againsttorch.cuda.device_count(). - Flash Attention 2: Enable via
AcceleratorOptions(cuda_use_flash_attention2=True)orDOCLING_CUDA_USE_FLASH_ATTENTION2=true. Requires Ampere+ GPU andflash-attn. - vLLM for VLM inference: On CUDA,
AUTO_INLINEcan route to vLLM ifprefer_vllm=Trueis set inAutoInlineVlmEngineOptionsand the model supports it . - Nemotron OCR: Requires CUDA 13.x, Linux x86_64, Python 3.12 exactly. Install with
pip install "docling[feat-ocr-nemotron]".
Known Limitations#
- TableFormer MPS disabled: Both V1 and V2 override MPS → CPU at init. The reason is documented as "until we know why it makes things slower" — this is a known open issue, not a resolved one .
- Transformers VLM + MPS: Setting
device=mpswith a VLM preset that has no MLX export raisesAcceleratorDeviceNotAvailableError. Usedevice=autofor safe fallback . - MLX thread safety:
MlxVlmEngineand MLX Whisper serialize on a process-wide_MLX_GLOBAL_LOCK. Avoid MLX-based models in high-concurrency scenarios . - Third-party models with hardcoded
.cuda()will fail on MPS/CPU without upstream changes .
Quick Reference: Environment Variables#
DOCLING_DEVICE=auto|cpu|cuda|cuda:N|mps|xpu
DOCLING_NUM_THREADS=4 # also reads OMP_NUM_THREADS as fallback
DOCLING_CUDA_USE_FLASH_ATTENTION2=true