VL Mode (VLM Backend) in MinerU#
VL (Vision-Language) mode is a document-parsing backend (-b vlm-engine) that delegates structural understanding to an end-to-end vision-language model — typically Qwen2-VL — rather than the traditional pipeline of layout detection + OCR + specialized models. The model processes page images directly and returns structured block data containing bounding boxes, block types, and extracted content in a single inference pass .
Architecture#
The entry point is vlm_analyze.py, which:
- Renders PDF pages into PIL images in windowed batches (default window: 64 pages)
- Calls
predictor.batch_two_step_extract()on each window via aMinerUClientwrapper - Passes raw model output to
model_output_to_middle_json.pyto produce themiddle.jsonintermediate artifact
The ModelSingleton caches loaded model instances keyed by (backend, model_path, server_url). Supported inference backends include transformers, vllm-engine, vllm-async-engine, lmdeploy-engine, and mlx-engine .
Output format validation happens in vlm_magic_model.py. Each block must have a bbox (x1,y1,x2,y2) and type field. Malformed blocks are caught, logged as warnings, and skipped rather than raising . Text blocks with null content are normalized to "" to prevent downstream failures . The recognized block types are: text, title, image, table, chart, code, algorithm, equation, ref_text, phonetic, header, footer, page_number, aside_text, page_footnote, list .
VLM-Specific Output Types (v2.5+)#
The VLM backend adds block types not present in the pipeline backend: code/algorithm, ref_text, phonetic, header/footer/page_number (routed to discarded_blocks), aside_text, page_footnote . The VLM backend output is not backward-compatible with the pipeline backend format.
Deprecation: VLM → Hybrid Mode#
VLM mode is actively being deprecated in favor of hybrid mode. A maintainer confirmed in June 2026:
"2605 的 merge_prev 标识被训废了,因此 vlm 模式不能合并都是正常的。建议使用 hybrid 模式,hybrid 模式硬件要求与 vlm 模式完全一致,且支持使用行 det 信息进行跨栏与跨页的合并。在线 saas 的 vlm 实际上已经是 hybrid 了,我们后面也会考虑直接移除 vlm backend。"
(Themerge_prevmarker in model v2605 was "training wasted," so VLM mode's inability to merge is expected. Hybrid mode has identical hardware requirements and supports cross-column/cross-page merging via line detection. The online SaaS VLM is already hybrid; we will consider removing the VLM backend entirely.)
The official online service (opendatalab.com) already uses hybrid mode by default, confirmed by a maintainer reply in July 2026 .
Migration path: Replace -b vlm-engine with -b hybrid-engine (or hybrid-auto-engine). Hardware requirements are identical .
Known Quality and Hallucination Issues#
| Issue | Affected Version | Detail |
|---|---|---|
| Cross-column/cross-page paragraph merging broken | v3.4.0 / model v2605 | merge_prev flag was corrupted during training; paragraphs that span columns or pages are not joined |
| Chinese text layout detection failures | All VLM versions | Large blocks of Chinese text may not be detected or correctly framed |
| Character misrecognition in mixed-language text | All VLM versions | Chinese-English mixed content produces character-level errors, especially visually similar characters |
| Content hallucination and duplication | All VLM versions | Generative model can produce non-existent content or repeat text, especially on low-quality scans |
| Malformed layout output tokens | Reported on RTX 3090 | Model produces ]]<|txtMask fill:#> token sequences instead of valid layout JSON; the MagicModel parser logs "Invalid block format" and skips the block |
A maintainer stated: "如果严格要求无幻觉,推荐使用 pipeline 模式" — If strict hallucination-free output is required, use pipeline mode . For occasional dropped characters (often caused by abnormal fonts), enabling the OCR switch may help .
VLM vs. hybrid trade-offs: VLM handles complex/borderless tables best and is immune to PP-DocLayoutV2 detection failures (since the VLM processes layout end-to-end). It is approximately 40% slower than hybrid . For dense layouts where hybrid misses text blocks, VLM correctly detects all records .
VRAM / Memory Management#
OOM Pattern on High-VRAM Devices (NPU/GPU)#
The primary OOM trigger is PyTorch memory fragmentation, not actual exhaustion. After many alloc/free cycles, reserved memory far exceeds allocated memory, leaving no contiguous block for the next allocation. A representative error from a 60.96 GiB Ascend 910B :
RuntimeError: NPU out of memory. Tried to allocate 20.00 MiB
(total capacity: 60.96 GiB; allocated: 729.95 MiB; free: 10.81 MiB; reserved: 764.00 MiB)
The clean_vram() utility only fires when total VRAM ≤ 8 GB, so high-VRAM devices skip cache cleanup entirely unless MINERU_VIRTUAL_VRAM_SIZE overrides the threshold .
Key Mitigations#
| Environment Variable | Recommended Value | Effect |
|---|---|---|
MINERU_VIRTUAL_VRAM_SIZE | 8 | Forces clean_vram to run after every inference stage by spoofing a low-VRAM device |
MINERU_HYBRID_BATCH_RATIO | 1 | Disables aggressive auto-batching on ≥32 GB devices |
PYTORCH_NPU_ALLOC_CONF | max_split_size_mb:128 | Reduces allocator block granularity on NPU |
MINERU_PROCESSING_WINDOW_SIZE | 4–8 | Lowers peak per-batch memory by processing fewer pages per window |
Device exclusivity: Hybrid/VLM engine modes require the GPU/NPU to be dedicated to MinerU. Sharing the device with other processes exacerbates fragmentation .
ModelSingleton leak: The VLM ModelSingleton never evicts cached model instances across requests. Unlike the pipeline/hybrid singletons, vlm_analyze.py registers atexit shutdown hooks — but these only fire on process exit. Periodic service restart or running mineru-vllm-server as a separate process remains the most reliable mitigation .
Key Files and References#
| Resource | Purpose |
|---|---|
mineru/backend/vlm/vlm_analyze.py | Main entry points: doc_analyze() and aio_doc_analyze(), ModelSingleton, shutdown hooks |
mineru/backend/vlm/vlm_magic_model.py | Block format validation and type mapping (MagicModel class) |
mineru/utils/model_utils.py#L208-L214 | clean_vram() — memory cleanup with VRAM threshold logic |
| Issue #5181 | Paragraph merge failure root cause (merge_prev corrupted in v2605) and maintainer deprecation statement |
| Issue #5185 | Frequent OOM on Ascend 910B; maintainer advice on device exclusivity |
| Issue #5224 | NPU memory fragmentation error trace and mitigation env vars |
| Discussion #5155 | Mode comparison (pipeline vs. VLM vs. hybrid), hallucination trade-offs, maintainer confirming online service uses hybrid |