标准流水线与 VLM 流水线#
| 标准流水线 | VLM 流水线 | |
|---|---|---|
| 方式 | 解析器 + 版面模型 + TableFormer + OCR | 每页图像交给一个视觉语言模型 |
| 使用 PDF 自带文本 | 是——原生数字 PDF 的字符完全准确 | 否——模型读取渲染后的页面 |
| CPU 速度 | 我们的测试中每页 2.3 秒(关闭 OCR) | 我们测试中 Granite-Docling 处理 2 页节选耗时 310 秒(含模型加载)——请准备 GPU 或 Apple Silicon |
| 优势 | 快、文字忠实、每个元素都有边界框 | 公式、代码、图表、特殊版面;只需部署一个模型 |
| 风险 | 复杂表格可能合并行(见我们的表格测试) | 生成式错误:漏字或重复,长页面尤甚 |
运行#
pip install "docling[vlm]"
docling convert report.pdf --pipeline vlm # 默认预设:granite_docling
docling convert report.pdf --pipeline vlm --vlm-model smoldocling
docling convert report.pdf --pipeline vlm --to html_split_page --show-layoutfrom docling.datamodel.base_models import InputFormat
from docling.datamodel.pipeline_options import VlmConvertOptions, VlmPipelineOptions
from docling.document_converter import DocumentConverter, PdfFormatOption
from docling.pipeline.vlm_pipeline import VlmPipeline
opts = VlmPipelineOptions()
opts.vlm_options = VlmConvertOptions.from_preset("granite_docling")
converter = DocumentConverter(format_options={
InputFormat.PDF: PdfFormatOption(pipeline_cls=VlmPipeline, pipeline_options=opts)
})
doc = converter.convert("report.pdf").document
print(doc.export_to_markdown())VlmConvertOptions.list_presets() 返回每个预设及其模型和说明;CLI 处理 --vlm-model 时调用的正是 from_preset()。
Granite-Docling-258M 简介#
- 开发者:IBM Research · 许可证:Apache 2.0 · 发布:2025 年 9 月 17 日。
- 架构:Idefics3 设计,视觉编码器为
siglip2-base-patch16-512,语言模型为 Granite 165M。 - 输出:DocTags——描述版面、文字、表格、代码、公式和图表的紧凑标记,可映射为 DoclingDocument。
- 语言:英语;日语、阿拉伯语和中文标注为实验性。
- 提示词:整页用 “Convert this page to docling.”;单个元素用简短指令,如 “Convert chart to table.”。
来源: ibm-granite/granite-docling-258M model card
查看数据表
| SmolDocling-256M-preview | Granite-Docling-258M | |
|---|---|---|
| Layout F1 | 0.85 | 0.86 |
| Layout recall | 0.84 | 0.88 |
| Layout precision | 0.9 | 0.92 |
| MMStar | 0.17 | 0.3 |
| OCRBench ÷ 1000 | 0.338 | 0.5 |
全部 22 个预设#
读取自 Docling 2.143.1 中的 VlmConvertOptions.list_presets()。标为“远程代码”的预设必须加 --trust-remote-code 才能运行——请先审阅模型代码。
读取自 VlmConvertOptions.list_presets()。
查看数据表
| 十亿参数 | |
|---|---|
| smoldocling | 0.26B |
| granite_docling | 0.26B |
| falcon_ocr | 0.30B |
| nemotron_parse_v3_5 | 0.60B |
| nemotron_parse_v2 | 0.90B |
| glm_ocr | 0.90B |
| lightonocr | 1.00B |
| mineru2_pro | 1.20B |
| granite_vision | 2.00B |
| deepseek_ocr | 3.00B |
| qwen | 3.00B |
| nanonets_ocr2 | 3.00B |
| dots_ocr | 3.00B |
| dots_mocr | 3.00B |
| unlimited_ocr | 3.34B |
| chandra_ocr2 | 5.30B |
| pixtral | 12.00B |
| gemma_12b | 12.00B |
| gemma_27b | 27.00B |
--vlm-model | 模型 | 大小 | 输出 | 备注 |
|---|---|---|---|---|
granite_docling | ibm-granite/granite-docling-258M | 258M | DocTags | 默认 · 有 MLX 版本 |
smoldocling | docling-project/SmolDocling-256M-preview | 256M | DocTags | 前代模型 · 有 MLX 版本 |
falcon_ocr | tiiuae/Falcon-OCR | 0.3B | Markdown | 远程代码 · MLX |
glm_ocr | zai-org/GLM-OCR | 0.9B | Markdown | MLX |
lightonocr | lightonai/LightOnOCR-2-1B | 1B | Markdown | MLX |
mineru2_pro | opendatalab/MinerU2.5-Pro-2604-1.2B | 1.2B | MinerU 两步法 | Transformers、MLX、API |
granite_vision | ibm-granite/granite-vision-3.3-2b | 2B | Markdown | Transformers、vLLM、Ollama、LM Studio |
deepseek_ocr | deepseek-ocr:3b | 3B | Markdown | 仅通过 Ollama 或 LM Studio |
qwen | Qwen/Qwen2.5-VL-3B-Instruct | 3B | Markdown | MLX |
nanonets_ocr2 | nanonets/Nanonets-OCR2-3B | 3B | Markdown | MLX |
dots_ocr | rednote-hilab/dots.ocr | 3B | 带边界框的 JSON | 远程代码 |
dots_mocr | rednote-hilab/dots.mocr | 3B | 带边界框的 JSON | 远程代码;Transformers 下需 flash-attn |
unlimited_ocr | baidu/Unlimited-OCR | 3.34B MoE | 带边界框的 Markdown | |
chandra_ocr2 | datalab-to/chandra-ocr-2 | 5.3B | 带边界框的 HTML | 远程代码 · MLX |
pixtral | mistral-community/pixtral-12b | 12B | Markdown | MLX |
gemma_12b | google/gemma-3-12b-it | 12B | Markdown | 仅 MLX |
gemma_27b | google/gemma-3-27b-it | 27B | Markdown | 仅 MLX |
phi4 | microsoft/Phi-4-multimodal-instruct | — | Markdown | 远程代码 · Transformers、vLLM |
got_ocr | stepfun-ai/GOT-OCR-2.0-hf | — | Markdown | Transformers |
dolphin | ByteDance/Dolphin | — | Markdown | |
nemotron_parse_v2 | nvidia/NVIDIA-Nemotron-Parse-2.0 | — | Nemotron Parse | 远程代码 · Transformers、MLX、vLLM |
nemotron_parse_v3_5 | nvidia/Nemotron-3.5-Parse | — | Nemotron Parse | Transformers、API |
“仅 MLX”等备注来自每个预设支持的推理引擎列表。各模型许可证不同——商用前请查看模型卡。
如何在标准流水线和 VLM 之间选择#
- 先用标准流水线。它是默认选项是有原因的:快,原生数字 PDF 的文字准确,每个元素都有来源信息。
- 目视检查结果。
--to html_split_page --show-layout会把每页原图和 Docling 提取的内容并排显示。 - 对失败的页面试用 Granite-Docling。配合
--page-range先测几页,再决定是否投入 GPU 时间。 - 用你自己的文档比较。公开分数是别人文档上的平均值;你自己的十份文档更有参考价值。
图片描述与图表提取#
不必启用完整的 VLM 流水线也能用上视觉模型。标准流水线可以只对图片调用一个小型 VLM:
docling convert report.pdf --enrich-picture-description # 为插图生成说明
docling convert report.pdf --enrich-chart-extraction # 柱状图/饼图/折线图 → 表格
docling convert report.pdf --enrich-chart-extraction --chart-extraction-preset granite_vision_v42.143.1 中的图表提取预设:granite_vision_v3_3、granite_vision_v4(默认)和 granite_vision_v4_mlx。默认预设对应 IBM Granite-Vision-4.1-4B(ibm-granite/granite-vision-4.1-4b),granite_vision_v3_3 对应一个 2B 的图表转 CSV 模型——请准备 GPU 或 Apple Silicon。我们核对了这些预设名称(2.143.1),但没有在 CPU 测试机上实际运行图表提取。
常见问题
Granite-Docling 是什么?
Granite-Docling-258M 是 IBM Research 于 2025 年 9 月 17 日以 Apache 2.0 发布的小型视觉语言模型。它把页面图像转换为 DocTags 标记,再由 Docling 转成 DoclingDocument。它基于 Idefics3 架构,使用 SigLIP2 视觉编码器和 Granite 165M 语言模型。
如何在 Docling 中使用 Granite-Docling?
安装 docling[vlm],运行 docling convert file.pdf --pipeline vlm --vlm-model granite_docling。在 Python 中设置 VlmPipelineOptions().vlm_options = VlmConvertOptions.from_preset('granite_docling'),并以 VlmPipeline 作为流水线类。
VLM 流水线比标准流水线更好吗?
不一定。标准流水线更快,对原生数字 PDF 效果很好。VLM 在复杂版面、公式和代码上可能更好,单一模型也更易部署,但没有 GPU 时慢得多,还可能出现幻觉或重复文字。
SmolDocling 被什么取代了?
Granite-Docling-258M 是 SmolDocling-256M-preview 的继任者,也是默认的 VLM 预设。smoldocling 预设仍然可用。
能在 Mac 上运行 VLM 流水线吗?
可以。大多数 DocTags 预设和部分 Markdown 预设有 MLX 版本,Docling 会在 Apple Silicon 上自动使用,例如 ibm-granite/granite-docling-258M-mlx。
资料来源
- ibm-granite/granite-docling-258M 模型卡
- SmolDocling 论文(arXiv 2503.11576)——DocTags
- Docling 源码:VlmConvertOptions 预设(docling/datamodel)
- IBM 公告:Granite-Docling