olmocr README

The project's README from github.com/allenai/olmocr. As one markdown file: README.md.

olmocr-2-full@2x

GitHub License GitHub release Tech Report v1 Tech Report v2 Demo Discord

A toolkit for converting PDFs and other image-based document formats into clean, readable, plain text format.

Try the online demo: https://olmocr.allenai.org/

Features:

News

Benchmark

olmOCR-Bench: We also ship a comprehensive benchmark suite covering over 7,000 test cases across 1,400 documents to help measure performance of OCR systems.

ArXiv Old
scans
math
Tables Old
scans
Headers
&
footers
Multi
column
Long
tiny
text
Base Overall
Mistral OCR API 77.2 67.5 60.6 29.3 93.6 71.3 77.1 99.4 72.0±1.1
Marker 1.10.1 83.8 66.8 72.9 33.5 86.6 80.0 85.7 99.3 76.1±1.1
MinerU 2.5.4* 76.6 54.6 84.9 33.7 96.6 78.2 83.5 93.7 75.2±1.1
DeepSeek-OCR 77.2 73.6 80.2 33.3 96.1 66.4 79.4 99.8 75.7±1.0
Nanonets-OCR2-3B 75.4 46.1 86.8 40.9 32.1 81.9 93.0 99.6 69.5±1.1
PaddleOCR-VL* 85.7 71.0 84.1 37.8 97.0 79.9 85.7 98.5 80.0±1.0
Infinity-Parser 7B* 84.4 83.8 85.0 47.9 88.7 84.2 86.4 99.8 82.5±?
Chandra OCR 0.1.0* 82.2 80.3 88.0 50.4 90.8 81.2 92.3 99.9 83.1±0.9

olmOCR v0.4.0 83.0 82.3 84.9 47.7 96.1 83.7 81.9 99.7 82.4±1.1

Installation

System Dependencies

You will need to install poppler-utils and additional fonts for rendering PDF images.

Install dependencies (Ubuntu/Debian):

sudo apt-get update
sudo apt-get install poppler-utils ttf-mscorefonts-installer msttcorefonts fonts-crosextra-caladea fonts-crosextra-carlito gsfonts lcdf-typetools

Python Installation

Set up a conda environment and install olmocr. The requirements for running olmOCR are difficult to install in an existing python environment, so please do make a clean python environment to install into.

conda create -n olmocr python=3.11
conda activate olmocr

Choose the installation option that matches your use case:

Option 1: Remote Inference (Lightweight)

If you plan to use a remote vLLM server with the --server flag, install the base package:

pip install olmocr

This avoids installing heavy GPU dependencies like PyTorch (~2GB+).

Option 2: Local GPU Inference

Requirements:

For running inference with your own GPU:

pip install olmocr[gpu] --extra-index-url https://download.pytorch.org/whl/cu128

# Recommended: Install flash infer for faster inference on GPU
pip install https://download.pytorch.org/whl/cu128/flashinfer/flashinfer_python-0.2.5%2Bcu128torch2.7-cp38-abi3-linux_x86_64.whl

Option 3: Beaker Cluster Execution

For submitting jobs to Beaker clusters with the --beaker flag:

pip install olmocr[beaker]

Option 4: Benchmark Suite

For running the olmOCR benchmark suite:

pip install olmocr[bench]

Combined Installation

You can combine multiple options:

# GPU + Beaker support
pip install olmocr[gpu,beaker] --extra-index-url https://download.pytorch.org/whl/cu128

# GPU + Benchmark support
pip install olmocr[gpu,bench] --extra-index-url https://download.pytorch.org/whl/cu128

Troubleshooting

If you run into errors about too many open files, update your ulimit:

ulimit -n 65536

Usage Examples

For quick testing, try the web demo.

Convert a Single PDF (Local GPU):

# Download a sample PDF
curl -o olmocr-sample.pdf https://olmocr.allenai.org/papers/olmocr_3pg_sample.pdf

# Convert it to markdown
olmocr ./localworkspace --markdown --pdfs olmocr-sample.pdf

Convert an Image file:

olmocr ./localworkspace --markdown --pdfs random_page.png

Convert Multiple PDFs:

olmocr ./localworkspace --markdown --pdfs tests/gnarly_pdfs/*.pdf

Use Remote Inference Server:

olmocr ./localworkspace --server http://remote-server:8000/v1 --model allenai/olmOCR-2-7B-1025-FP8 --markdown --pdfs *.pdf

With the --markdown flag, results will be stored as markdown files inside of ./localworkspace/markdown/.

Note: You can also use python -m olmocr.pipeline instead of olmocr if you prefer.

Viewing Results

The ./localworkspace/ workspace folder will then have both Dolma and markdown files (if using --markdown).

cat localworkspace/markdown/olmocr-sample.md 
olmOCR: Unlocking Trillions of Tokens in PDFs with Vision Language Models
...

Using an Inference Provider or External Server

If you have a vLLM server already running elsewhere (or any inference platform implementing the OpenAI API), you can point olmOCR to use it instead of spawning a local instance.

Installation for Remote Inference:

# Lightweight installation - no GPU dependencies needed
pip install olmocr

Using an External Server:

# Use external vLLM server instead of local one
olmocr ./localworkspace --server http://remote-server:8000/v1 --model allenai/olmOCR-2-7B-1025-FP8 --markdown --pdfs tests/gnarly_pdfs/*.pdf

The served model name in vLLM needs to match the value provided in --model.

Example vLLM Server Launch:

vllm serve allenai/olmOCR-2-7B-1025-FP8 --max-model-len 16384

Verified External Providers

We have tested olmOCR-2-7B-1025-FP8 on these external model providers and confirmed that they work

$/1M Input tokens $/1M Output tokens Example Command
Cirrascale $0.07 $0.15 olmocr ./workspace --server https://ai2endpoints.cirrascale.ai/api --api_key sk-XXXXXXX --workers 1 --max_concurrent_requests 20 --model olmOCR-2-7B-1025 --pdfs tests/gnarly_pdfs/*.pdf
DeepInfra $0.09 $0.19 olmocr ./workspace --server https://api.deepinfra.com/v1/openai --api_key DfXXXXXXX --workers 1 --max_concurrent_requests 20 --model allenai/olmOCR-2-7B-1025 --pdfs tests/gnarly_pdfs/*.pdf
Parasail $0.10 $0.20 olmocr ./workspace --server https://api.parasail.io/v1 --api_key psk-XXXXX --workers 1 --max_concurrent_requests 20 --model allenai/olmOCR-2-7B-1025 --pdfs tests/gnarly_pdfs/*.pdf

Notes on arguments

Multi-node / Cluster Usage

If you want to convert millions of PDFs using multiple nodes running in parallel, olmOCR supports reading PDFs from AWS S3 and coordinating work using an AWS S3 output bucket.

Start the first worker node:

olmocr s3://my_s3_bucket/pdfworkspaces/exampleworkspace --pdfs s3://my_s3_bucket/jakep/gnarly_pdfs/*.pdf

This sets up a simple work queue in your AWS bucket and starts converting PDFs.

On subsequent worker nodes:

olmocr s3://my_s3_bucket/pdfworkspaces/exampleworkspace

They will automatically start grabbing items from the same workspace queue.

Using Beaker for Cluster Execution

If you are at Ai2 and want to linearize millions of PDFs efficiently using beaker, install with Beaker support:

pip install olmocr[gpu,beaker] --extra-index-url https://download.pytorch.org/whl/cu128

Then use the --beaker flag to prepare the workspace locally and launch N GPU workers in the cluster:

olmocr s3://my_s3_bucket/pdfworkspaces/exampleworkspace --pdfs s3://my_s3_bucket/jakep/gnarly_pdfs/*.pdf --beaker --beaker_gpus 4

Using Docker

Pull the Docker image (large, includes the model, ~30GB):

docker pull alleninstituteforai/olmocr:latest-with-model

For advanced users who want to manage their own model downloads, we also provide a base image without the model:

docker pull alleninstituteforai/olmocr:latest

Quick Start - Process PDFs

Process a single PDF in your current directory:

docker run --gpus all \
  -v $(pwd):/workspace \
  alleninstituteforai/olmocr:latest-with-model \
  -c "olmocr /workspace/output --markdown --pdfs /workspace/sample.pdf"

Process multiple PDFs:

docker run --gpus all \
  -v /path/to/pdfs:/input \
  -v /path/to/output:/output \
  alleninstituteforai/olmocr:latest-with-model \
  -c "olmocr /output --markdown --pdfs /input/*.pdf"

Interactive Mode

Run the container interactively for exploration and debugging:

docker run -it --gpus all alleninstituteforai/olmocr:latest-with-model

Visit our Docker repository on Docker Hub for more information.

Full Documentation

To see all available options:

olmocr --help
usage: pipeline.py [-h] [--pdfs [PDFS ...]] [--model MODEL] [--workspace_profile WORKSPACE_PROFILE] [--pdf_profile PDF_PROFILE] [--pages_per_group PAGES_PER_GROUP] [--max_page_retries MAX_PAGE_RETRIES] [--max_page_error_rate MAX_PAGE_ERROR_RATE] [--workers WORKERS]
                   [--apply_filter] [--stats] [--markdown] [--target_longest_image_dim TARGET_LONGEST_IMAGE_DIM] [--target_anchor_text_len TARGET_ANCHOR_TEXT_LEN] [--guided_decoding] [--gpu-memory-utilization GPU_MEMORY_UTILIZATION] [--max_model_len MAX_MODEL_LEN]
                   [--tensor-parallel-size TENSOR_PARALLEL_SIZE] [--data-parallel-size DATA_PARALLEL_SIZE] [--port PORT] [--server SERVER] [--beaker] [--beaker_workspace BEAKER_WORKSPACE] [--beaker_cluster BEAKER_CLUSTER] [--beaker_gpus BEAKER_GPUS] [--beaker_priority BEAKER_PRIORITY]
                   workspace

Manager for running millions of PDFs through a batch inference pipeline

positional arguments:
  workspace             The filesystem path where work will be stored, can be a local folder, or an s3 path if coordinating work with many workers, s3://bucket/prefix/

options:
  -h, --help            show this help message and exit
  --pdfs [PDFS ...]     Path to add pdfs stored in s3 to the workspace, can be a glob path s3://bucket/prefix/*.pdf or path to file containing list of pdf paths
  --model MODEL         Path where the model is located, allenai/olmOCR-7B-0725-FP8 is the default, can be local, s3, or hugging face.
  --workspace_profile WORKSPACE_PROFILE
                        S3 configuration profile for accessing the workspace
  --pdf_profile PDF_PROFILE
                        S3 configuration profile for accessing the raw pdf documents
  --pages_per_group PAGES_PER_GROUP
                        Aiming for this many pdf pages per work item group
  --max_page_retries MAX_PAGE_RETRIES
                        Max number of times we will retry rendering a page
  --max_page_error_rate MAX_PAGE_ERROR_RATE
                        Rate of allowable failed pages in a document, 1/250 by default
  --workers WORKERS     Number of workers to run at a time
  --apply_filter        Apply basic filtering to English pdfs which are not forms, and not likely seo spam
  --stats               Instead of running any job, reports some statistics about the current workspace
  --markdown            Also write natural text to markdown files preserving the folder structure of the input pdfs
  --target_longest_image_dim TARGET_LONGEST_IMAGE_DIM
                        Dimension on longest side to use for rendering the pdf pages
  --target_anchor_text_len TARGET_ANCHOR_TEXT_LEN
                        Maximum amount of anchor text to use (characters), not used for new models
  --guided_decoding     Enable guided decoding for model YAML type outputs

VLLM arguments:
  --gpu-memory-utilization GPU_MEMORY_UTILIZATION
                        Fraction of VRAM vLLM may pre-allocate for KV-cache (passed through to vllm serve).
  --max_model_len MAX_MODEL_LEN
                        Upper bound (tokens) vLLM will allocate KV-cache for, lower if VLLM won't start
  --tensor-parallel-size TENSOR_PARALLEL_SIZE, -tp TENSOR_PARALLEL_SIZE
                        Tensor parallel size for vLLM
  --data-parallel-size DATA_PARALLEL_SIZE, -dp DATA_PARALLEL_SIZE
                        Data parallel size for vLLM
  --port PORT           Port to use for the VLLM server
  --server SERVER       URL of external vLLM (or other compatible provider)
                        server (e.g., http://hostname:port). If provided,
                        skips spawning local vLLM instance

beaker/cluster execution:
  --beaker              Submit this job to beaker instead of running locally
  --beaker_workspace BEAKER_WORKSPACE
                        Beaker workspace to submit to
  --beaker_cluster BEAKER_CLUSTER
                        Beaker clusters you want to run on
  --beaker_gpus BEAKER_GPUS
                        Number of gpu replicas to run
  --beaker_priority BEAKER_PRIORITY
                        Beaker priority level for the job

Code overview

There are some nice reusable pieces of the code that may be useful for your own projects:

olmocr (allenai/olmocr)

Searching Database…

19.8K ·GitHub
这是什么?olmOCR 是一个工具包,可以把 PDF、PNG 和 JPEG 转换成干净的 Markdown 或纯文本,并保持自然的阅读顺序,同时保留公式、表格和手写内容。它主要是为了生成大语言模型的训练数据集而构建的。
它是 Python 库、命令行流水线,还是托管服务?它是一个 Python 命令行工具/流水线(通过 pip 装入干净的 conda 环境),基于一个 70 亿参数的视觉语言模型构建。你可以直接用本地 GPU 运行,也可以指向远程的 OpenAI 兼容 vLLM 服务器,或者使用提供的 Docker 镜像。
怎样用它处理我自己的 PDF?创建一个干净的 conda 环境,然后根据你的使用场景选择对应的安装选项(轻量的仅远程推理版、完整的本地 GPU 推理版、Beaker 版或基准测试套件),再运行 olmocr 命令行并指定你的 PDF,例如加上 --markdown 参数,就能在 ./localworkspace/ 中得到 Markdown 输出。
安装时有哪些需要注意的坑?这些安装依赖很难和现有的 Python 环境兼容,因此项目强烈建议新建一个全新的干净 conda 环境,而不是复用已有环境。
整个流程能不调用任何外部 API 就跑起来吗?可以。默认方式会完全在你自己的 GPU 上运行 70 亿参数的视觉语言模型,不需要任何外部调用;指向远程服务器(--server)只是一个可选方案,并非必需。
olmOCR-Bench 是什么?它是 olmOCR 自家的评测套件,涵盖 1400 多份文档中的 7000 多个测试用例(包括数学公式、老旧扫描件、表格、多栏排版等),用于给 OCR 系统打分。最新的 olmOCR v0.4.0 综合得分为 82.4,与 PaddleOCR-VL、Chandra OCR 等其他领先的 OCR/视觉语言模型引擎处于同一水平。
我能不买硬件,改用云端 GPU 服务商吗?可以。olmOCR 可以调用任何 OpenAI 兼容的 vLLM 接口。经过验证的外部服务商包括 Cirrascale、DeepInfra 和 Parasail,大约每百万输入 token 收费 0.07 至 0.10 美元。
olmOCR 能否在多台机器上处理数百万份 PDF?可以。它支持多节点处理:从 AWS S3 存储桶读取 PDF,并通过 S3 输出存储桶协调共享的任务队列。新增的工作节点只需加入,就会自动开始领取任务。
用 olmOCR 转换文档的成本有多低?项目官方宣称,在你自己的 GPU 上运行时,每百万页的转换成本低于 200 美元。原因是它依赖的是相对较小的 70 亿参数视觉语言模型,而不是庞大的专有大模型。
What are similar projects?lift, Unlimited-OCR, doctr, TeleOCR, chandra, surya, verl, OraRL
Creator
allenai
Size
349.1 MB
Stars
19.8K
Age
2y
Commits · 90 Days