- Notifications
You must be signed in to change notification settings - Fork1.2k
Toolkit for linearizing PDFs for LLM datasets/training
License
allenai/olmocr
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
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:
- Convert PDF, PNG, and JPEG based documents into clean Markdown
- Support for equations, tables, handwriting, and complex formatting
- Automatically removes headers and footers
- Convert into text with a natural reading order, even in the presence offigures, multi-column layouts, and insets
- Efficient, less than $200 USD per million pages converted
- (Based on a 7B parameter VLM, so it requires a GPU)
- October 21, 2025 - v0.4.0 -New model release, boosts olmOCR-bench score by ~4 points using synthetic data and introduces RL training.
- August 13, 2025 - v0.3.0 -New model release, fixes auto-rotation detection, and hallucinations on blank documents.
- July 24, 2025 - v0.2.1 -New model release, scores 3 points higher onolmOCR-Bench, also runs significantly faster because it's default FP8, and needs much fewer retries per document.
- July 23, 2025 - v0.2.0 - New cleaned uptrainer code, makes it much simpler to train olmOCR models yourself.
- June 17, 2025 - v0.1.75 - Switch from sglang to vllm based inference pipeline, updated docker image to CUDA 12.8.
- May 23, 2025 - v0.1.70 - Official docker support and images are now available!See Docker usage
- May 19, 2025 - v0.1.68 -olmOCR-Bench launch, scoring 77.4. Launch includes 2 point performance boost in olmOCR pipeline due to bug fixes with prompts.
- Mar 17, 2025 - v0.1.60 - Performance improvements due to better temperature selection in sampling.
- Feb 25, 2025 - v0.1.58 - Initial public launch and demo.
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 |
Requirements:
- Recent NVIDIA GPU (tested on RTX 4090, L40S, A100, H100) with at least 15 GB of GPU RAM
- 30GB of free disk space
You will need to install poppler-utils and additional fonts for rendering PDF images.
Install dependencies (Ubuntu/Debian)
sudo apt-get updatesudo apt-get install poppler-utils ttf-mscorefonts-installer msttcorefonts fonts-crosextra-caladea fonts-crosextra-carlito gsfonts lcdf-typetools
Set up a conda environment and install olmocr. The requirements for running olmOCRare 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.11conda activate olmocr# For CPU-only operations, ex running the benchmarkpip install olmocr[bench]# For actually converting the files with your own GPUpip install olmocr[gpu] --extra-index-url https://download.pytorch.org/whl/cu128# Recommended: Install flash infer for faster inference on GPUpip install https://download.pytorch.org/whl/cu128/flashinfer/flashinfer_python-0.2.5%2Bcu128torch2.7-cp38-abi3-linux_x86_64.whl
For quick testing, try theweb demo. To run locally, a GPU is required, as inference is powered bysglang under the hood.
Convert a Single PDF:
# Download a sample PDFcurl -o olmocr-sample.pdf https://olmocr.allenai.org/papers/olmocr_3pg_sample.pdf# Convert it to markdownpython -m olmocr.pipeline ./localworkspace --markdown --pdfs olmocr-sample.pdf
Convert an Image file:
python -m olmocr.pipeline ./localworkspace --markdown --pdfs random_page.png
Convert Multiple PDFs:
python -m olmocr.pipeline ./localworkspace --markdown --pdfs tests/gnarly_pdfs/*.pdfWith the addition of the--markdown flag, results will be stored as markdown files inside of./localworkspace/markdown/.
The./localworkspace/ workspace folder will then have bothDolma and markdown files (if using--markdown).
cat localworkspace/markdown/olmocr-sample.md
olmOCR: Unlocking Trillions of Tokens in PDFs with Vision Language Models...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:
# Use external vLLM server instead of local onepython -m olmocr.pipeline ./localworkspace --server http://remote-server:8000/v1 --markdown --pdfs tests/gnarly_pdfs/*.pdf
The served model name should beolmocr. An example vLLM launch command would be:
vllm serve allenai/olmOCR-2-7B-1025-FP8 --served-model-name olmocr --max-model-len 16384
We have testedolmOCR-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 | python -m olmocr.pipeline ./localworkspace1 --server https://ai2endpoints.cirrascale.ai/api --api_key sk-XXXXXXX --model olmOCR-2-7B-1025 --pdfs tests/gnarly_pdfs/*.pdf |
| DeepInfra | $0.09 | $0.19 | python -m olmocr.pipeline ./localworkspace1 --server https://api.deepinfra.com/v1/openai --api_key DfXXXXXXX --model allenai/olmOCR-2-7B-1025 --pdfs tests/gnarly_pdfs/*.pdf |
| Parasail | $0.10 | $0.20 | python -m olmocr.pipeline ./localworkspace1 --server https://api.parasail.io/v1 --api_key psk-XXXXX --model allenai/olmOCR-2-7B-1025 --pdfs tests/gnarly_pdfs/*.pdf |
Notes on arguments
--server: Defines the OpenAI-compatible endpoint: exhttps://api.deepinfra.com/v1/openai--api_key: Your API key, bassed in via Authorization Bearer HTTP header--pages_per_group: You may want a smaller number of pages per group as many external provides have lower concurrent request limits--model: The model identifier, ex.allenai/olmOCR-2-7B-1025, different providers have different names, and if you run locally, you can useolmocr- Other arguments work the same as with local inference
If you want to convert millions of PDFs, using multiple nodes running in parallel, then olmOCR supportsreading your PDFs from AWS S3, and coordinating work using an AWS S3 output bucket.
For example, you can start this command on your first worker node, and it will set upa simple work queue in your AWS bucket and start converting PDFs.
python -m olmocr.pipeline s3://my_s3_bucket/pdfworkspaces/exampleworkspace --pdfs s3://my_s3_bucket/jakep/gnarly_pdfs/*.pdfNow on any subsequent nodes, just run this and they will start grabbing items from the same workspace queue.
python -m olmocr.pipeline s3://my_s3_bucket/pdfworkspaces/exampleworkspace
If you are at Ai2 and want to linearize millions of PDFs efficiently usingbeaker, just add the--beakerflag. This will prepare the workspace on your local machine, and then launch N GPU workers in the cluster to startconverting PDFs.
For example:
python -m olmocr.pipeline s3://my_s3_bucket/pdfworkspaces/exampleworkspace --pdfs s3://my_s3_bucket/jakep/gnarly_pdfs/*.pdf --beaker --beaker_gpus 4Pull the Docker image.
docker pull alleninstituteforai/olmocr:latest
To run the container interactively:
docker run -it --gpus all --name olmocr_container alleninstituteforai/olmocr:latest /bin/bash
If you want to access your local files inside the container, use volume mounting:
docker run -it --gpus all \ -v /path/to/your/local/files:/local_files \ --name olmocr_container \ alleninstituteforai/olmocr:latest /bin/bash
All dependencies are already installed. Once you’re inside the container, you can run olmOCR commands. For example:
curl -o olmocr-sample.pdf https://olmocr.allenai.org/papers/olmocr_3pg_sample.pdfpython -m olmocr.pipeline ./localworkspace --markdown --pdfs olmocr-sample.pdf
You can also visit our Docker repository onDocker Hub.
python -m olmocr.pipeline --helpusage: 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] workspaceManagerfor running millions of PDFs through a batch inference pipelinepositional arguments: workspace The filesystem path where work will be stored, can be alocal folder, or an s3 pathif coordinating work with many workers, s3://bucket/prefix/options: -h, --help show thishelp message andexit --pdfs [PDFS ...] Path to add pdfs storedin 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 profilefor accessing the workspace --pdf_profile PDF_PROFILE S3 configuration profilefor accessing the raw pdf documents --pages_per_group PAGES_PER_GROUP Aimingfor this many pdf pages per work item group --max_page_retries MAX_PAGE_RETRIES Max number oftimes we will retry rendering a page --max_page_error_rate MAX_PAGE_ERROR_RATE Rate of allowable failed pagesin a document, 1/250 by default --workers WORKERS Number of workers to run at atime --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 usefor rendering the pdf pages --target_anchor_text_len TARGET_ANCHOR_TEXT_LEN Maximum amount of anchor text to use (characters), not usedfor new models --guided_decoding Enable guided decodingfor model YAMLtype outputsVLLM arguments: --gpu-memory-utilization GPU_MEMORY_UTILIZATION Fraction of VRAM vLLM may pre-allocatefor KV-cache (passed through to vllm serve). --max_model_len MAX_MODEL_LEN Upper bound (tokens) vLLM will allocate KV-cache for, lowerif 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 instancebeaker/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
There are some nice reusable pieces of the code that may be useful for your own projects:
- A prompting strategy to get really good natural text parsing using ChatGPT 4o -buildsilver.py
- Basic filtering by language and SEO spam removal -filter.py
- SFT Finetuning code for Qwen2.5-VL -train.py
- GRPO RL Trainer -grpo_train.py
- Synthetic data generation -mine_html_templates.py
- Processing millions of PDFs through a finetuned model using VLLM -pipeline.py
- ViewingDolma docs created from PDFs -dolmaviewer.py
olmOCR is developed and maintained by the AllenNLP team, backed bythe Allen Institute for Artificial Intelligence (AI2).AI2 is a non-profit institute with the mission to contribute to humanity through high-impact AI research and engineering.To learn more about who specifically contributed to this codebase, seeour contributors page.
olmOCR is licensed underApache 2.0.A full copy of the license can be foundon GitHub.
For olmOCR v1 and OlmOCR-bench:
@misc{olmocrbench,title={{olmOCR: Unlocking Trillions of Tokens in PDFs with Vision Language Models}},author={Jake Poznanski and Jon Borchardt and Jason Dunkelberger and Regan Huff and Daniel Lin and Aman Rangapur and Christopher Wilhelm and Kyle Lo and Luca Soldaini},year={2025},eprint={2502.18443},archivePrefix={arXiv},primaryClass={cs.CL},url={https://arxiv.org/abs/2502.18443},}
For olmOCR v2 Unit Testing Rewards with RL:
@misc{olmocr2,title={olmOCR 2: Unit Test Rewards for Document OCR},author={Jake Poznanski and Luca Soldaini and Kyle Lo},year={2025},eprint={2510.19817},archivePrefix={arXiv},primaryClass={cs.CV},url={https://arxiv.org/abs/2510.19817}, }
About
Toolkit for linearizing PDFs for LLM datasets/training
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
