olmocr

命令行工具

allenai/olmocr

将PDF线性化为LLM数据集的工具包。

项目简介

一个将PDF和图片转换为干净Markdown文本的工具包,支持自然阅读顺序、复杂排版、表格、公式和手写。专为大型语言模型准备高质量训练数据而设计。

README 预览

\n  \n\n\n\n  \n    \n  \n  \n    \n  \n  \n    \n  \n  \n    \n  \n  \n    \n  \n  \n    \n  \n\n\nA toolkit for converting PDFs and other image-based document formats into clean, readable, plain text format.\n\nTry the online demo: [https://olmocr.allenai.org/](https://olmocr.allenai.org/)\n\nFeatures:\n - Convert PDF, PNG, and JPEG based documents into clean Markdown\n - Support for equations, tables, handwriting, and complex formatting\n - Automatically removes headers and footers\n - Convert into text with a natural reading order, even in the presence of\n   figures, multi-column layouts, and insets\n - Efficient, less than $200 USD per million pages converted\n - (Based on a 7B parameter VLM, so it requires a GPU)\n\n### News\n - October 21, 2025 - v0.4.0 - [New model release](https://huggingface.co/allenai/olmOCR-2-7B-1025-FP8), boosts olmOCR-bench score by ~4 points using synthetic data and introduces RL training.\n - August 13, 2025 - v0.3.0 - [New model release](https://huggingface.co/allenai/olmOCR-7B-0825-FP8), fixes auto-rotation detection, and hallucinations on blank documents.\n - July 24, 2025 - v0.2.1 - [New model release](https://huggingface.co/allenai/olmOCR-7B-0725-FP8), scores 3 points higher on [olmOCR-Bench](https://github.com/allenai/olmocr/tree/main/olmocr/bench), also runs significantly faster because it's default FP8, and needs much fewer retries per document.\n - July 23, 2025 - v0.2.0 - New cleaned up [trainer code](https://github.com/allenai/olmocr/tree/main/olmocr/train), makes it much simpler to train olmOCR models yourself.\n - June 17, 2025 - v0.1.75 - Switch from sglang to vllm based inference pipeline, updated docker image to CUDA 12.8.\n - May 23, 2025 - v0.1.70 - Official docker support and images are now available! [See Docker usage](#using-docker)\n - May 19, 2025 - v0.1.68 - [olmOCR-Bench](https://github.com/allenai/olmocr/tree/main/olmocr/bench) launch, scoring 77.4. Launch includes 2 point performance boost in olmOCR pipeli

常见问题 (3)

故障排除
为什么 olmOCR 0.4.4 在 OCR 完成后无限期挂起,始终不退出?

这是 olmOCR 0.4.4 中的一个回归问题,由缺失的信号量(semaphore)清理引起;通常在使用外部 vLLM/基于服务器的提供程序时发生。升级到修复版本:

pip install --upgrade olmocr==0.4.5

验证 CLI 在处理完成后正常返回,并且所有工作进程均已终止。如果无法立即升级,请降级到上一个正常工作的版本:

pip install olmocr==0.4.3

避免在脚本化或自动化工作流中使用 olmOCR 0.4.4,因为父进程可能会一直保持运行,直到使用 SIGTERM/SIGKILL 手动终止。

来源 Issue #383
故障排除
当 --pdfs 是绝对路径时,如何让 olmOCR 的 --markdown 输出保留在工作区内?

旧版 olmOCR 在推导 Markdown 输出路径时直接使用了 PDF 的绝对路径,因此将其与工作区拼接后会解析到 PDF 的原始目录。此问题已在 PR #400 中修复。请升级到包含该修复的发布版本或最新的 main 分支:

pip install -U git+https://github.com/allenai/olmocr.git

然后重新运行:

python -m olmocr.pipeline ./localworkspace --markdown \
  --pdfs /my/path/to/my/personal/pdf.pdf \
  --model allenai/olmOCR-2-7B-1025-FP8

现在输出会保留在工作区下,并保留绝对路径以避免文件名冲突:

./localworkspace/markdown/absolute/my/path/to/my/personal/pdf.md

旧版本的变通方法:在 PDF 所在目录中运行命令,并仅传入文件名:

cd /my/path/to/my/personal
python -m olmocr.pipeline /path/to/localworkspace --markdown \
  --pdfs pdf.pdf \
  --model allenai/olmOCR-2-7B-1025-FP8

这样会生成 localworkspace/markdown/pdf.md。

来源 Issue #391
故障排除
如何修复 olmOCR FP8 在 12 GB Blackwell GPU 上运行速度仅约 0.5 tokens/s 且溢出到共享内存的问题?

速度变慢的原因是 Transformers 推理路径会将 FP8 权重上转换为 FP16,使内存占用从约 7 GB 上升到约 20 GB。请改用 vLLM 后端;olmOCR 默认使用 vLLM,并且当安装的 GPU 软件栈支持时,vLLM 可以运行原生 FP8。请在 WSL2/Linux 中使用与 CUDA 12.8、Blackwell sm_120 兼容的 PyTorch 构建版本,然后安装或升级到支持 Blackwell FP8 的 vLLM 构建版本。使用 python -c "import torch; print(torch.cuda.get_device_capability())"(Blackwell 应报告 12.x 的计算能力)和 python -c "import vllm; print(vllm.__version__)" 来验证配置。确保模型确实是通过 vLLM 加载的;通过 Transformers 加载仍会上转换为 FP16。只有在确认原生 FP8 vLLM 推理正常运行之后,才可以临时降低或移除 olmocr/check.py 中单独硬编码的 15 GB 检查。在没有原生 FP8 支持的情况下修改该检查,并不能阻止 FP16 上转换或共享内存溢出。

来源 Issue #415