Unlimited-OCR: One-Shot Long-Horizon Document Parsing by Baidu
Introduction
Optical Character Recognition (OCR) has come a long way — from Tesseract's line-by-line extraction to modern vision-language models that understand document structure. But most tools still struggle with long-form documents, complex layouts, tables, and multi-page PDFs.
Unlimited-OCR by Baidu changes this entirely. Released on June 22, 2026, it's a vision-language model that performs one-shot long-horizon document parsing — meaning it can take an entire page (or 100+ pages) and produce structured text in a single inference pass. With over 11,000 GitHub stars in its first week, it's one of the fastest-growing open-source AI projects of 2026.
Unlimited-OCR builds on DeepSeek-OCR and DeepSeek-OCR-2, pushing further with larger context windows (32K tokens), better layout understanding, and a two-mode inference system (gundam for single pages, base for multi-page parsing). It supports vLLM and SGLang serving, making it deployable on any NVIDIA GPU via Docker.
This guide walks through what Unlimited-OCR is, why it matters, and how to self-host it on your own infrastructure.
Why Is Unlimited-OCR Trending?
The project exploded in popularity for several reasons:
- One-shot parsing — no chunking, no stitching, no post-processing. Feed a document in, get structured text out.
- Multi-page PDF support — converts entire PDFs to structured text with a single API call.
- Two inference modes —
gundammode (base_size=1024, image_size=640, crop_mode=True) for dense single-page documents, andbasemode (base_size=1024, image_size=1024) for multi-page parsing. - OpenAI-compatible API — deploy via vLLM or SGLang and use any OpenAI SDK client.
- 32K context window — handles long documents and books without losing coherence.
- Baidu backing — developed by one of the world's largest AI research teams (no Israeli links — safe for self-hosters who care about provenance).
- MIT license — free for personal and commercial use.
Architecture Overview
The processing pipeline breaks down into four stages:
-
Input Layer — accepts images (JPG, PNG) or PDFs. For PDFs, PyMuPDF converts each page to a PNG at 300 DPI. Two image modes control how the input is preprocessed:
gundam(crops dense content) for single-page documents, andbase(full resolution) for multi-page parsing. -
Vision Encoder — processes pixel data into visual tokens. The model uses a vision transformer backbone trained on document layouts, tables, handwriting, and mixed-content pages.
-
Language Model — a DeepSeek-based LLM with 32K token context window generates structured text from the visual tokens. The n-gram repetition avoidance processor (window size 35, ngram window 128–1024) ensures the output doesn't loop or repeat.
-
Output Layer — returns parsed text as plain text or structured markdown. The results preserve layout order, table structure, and heading hierarchy.
Prerequisites
To self-host Unlimited-OCR, you'll need:
- NVIDIA GPU with at least 16GB VRAM (RTX 4080, A10, A100, or better). The model runs in bfloat16.
- Docker installed (for vLLM or SGLang deployment)
- At least 32GB system RAM
- 50GB free disk space for the model weights
- CUDA 12.9 or 13.0 supported GPU drivers
- Python 3.12+ (if running without Docker)
Setup and Deployment
Option 1: Docker + vLLM (Recommended)
The fastest way to get Unlimited-OCR running is via the official vLLM Docker image:
# For CUDA 13.0 GPUs (default)
docker pull vllm/vllm-openai:unlimited-ocr
# For Hopper GPUs (H100/H200) with CUDA 12.9
docker pull vllm/vllm-openai:unlimited-ocr-cu129
Create a docker-compose.yml for persistent deployment:
version: "3.8"
services:
unlimited-ocr:
image: vllm/vllm-openai:unlimited-ocr
ports:
- "8000:8000"
volumes:
- ~/.cache/huggingface:/root/.cache/huggingface
command: >
--model baidu/Unlimited-OCR
--served-model-name Unlimited-OCR
--gpu-memory-utilization 0.85
--max-model-len 32768
--port 8000
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
restart: unless-stopped
Start the server:
docker compose up -d
Option 2: SGLang Deployment
SGLang offers better batch processing for multi-document workloads:
# Create a Python 3.12 virtual environment with uv
uv venv --python 3.12
source .venv/bin/activate
# Install SGLang wheel for Unlimited-OCR
uv pip install wheel/sglang-0.0.0.dev11416+g92e8bb79e-py3-none-any.whl
uv pip install kernels==0.11.7
uv pip install pymupdf==1.27.2.2
# Start the server
python -m sglang.launch_server \
--model baidu/Unlimited-OCR \
--served-model-name Unlimited-OCR \
--attention-backend fa3 \
--page-size 1 \
--mem-fraction-static 0.8 \
--context-length 32768 \
--enable-custom-logit-processor \
--disable-overlap-schedule \
--host 0.0.0.0 \
--port 10000
Option 3: Transformers (Python)
For direct integration without a serving layer:
pip install torch==2.10.0 torchvision==0.25.0 transformers==4.57.1 \
Pillow==12.1.1 pymupdf==1.27.2.2 einops==0.8.2 addict==2.4.0
import torch
from transformers import AutoModel, AutoTokenizer
model_name = "baidu/Unlimited-OCR"
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
model = AutoModel.from_pretrained(
model_name,
trust_remote_code=True,
torch_dtype=torch.bfloat16,
).eval().cuda()
# Single image — gundam mode for dense content
model.infer(
tokenizer,
prompt="<image>document parsing.",
image_file="invoice.jpg",
output_path="./ocr_output",
base_size=1024, image_size=640, crop_mode=True,
max_length=32768,
no_repeat_ngram_size=35, ngram_window=128,
)
# Multi-page PDF parsing
import fitz, os, tempfile
def pdf_to_images(pdf_path, dpi=300):
doc = fitz.open(pdf_path)
tmp = tempfile.mkdtemp(prefix="pdf_ocr_")
mat = fitz.Matrix(dpi / 72, dpi / 72)
paths = []
for i, page in enumerate(doc):
out = os.path.join(tmp, f"page_{i+1:04d}.png")
page.get_pixmap(matrix=mat).save(out)
paths.append(out)
doc.close()
return paths
model.infer_multi(
tokenizer,
prompt="<image>Multi page parsing.",
image_files=pdf_to_images("report.pdf", dpi=300),
output_path="./ocr_output",
image_size=1024,
max_length=32768,
no_repeat_ngram_size=35, ngram_window=1024,
)
Using the OpenAI-Compatible API
Once vLLM or SGLang is running, you can use any OpenAI SDK to call Unlimited-OCR:
import base64
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:8000/v1",
api_key="not-needed" # vLLM doesn't require an API key locally
)
with open("document.png", "rb") as f:
b64 = base64.b64encode(f.read()).decode()
response = client.chat.completions.create(
model="Unlimited-OCR",
messages=[{
"role": "user",
"content": [
{"type": "text", "text": "Parse this document completely."},
{"type": "image_url", "image_url": {
"url": f"data:image/png;base64,{b64}"
}}
]
}],
temperature=0,
max_tokens=32768
)
print(response.choices[0].message.content)
Batch Processing
For bulk OCR jobs, use the built-in infer.py script:
# Process an entire directory of images
python infer.py \
--image_dir ./scans \
--output_dir ./parsed \
--concurrency 8 \
--image_mode gundam
# Process a PDF
python infer.py \
--pdf ./annual_report.pdf \
--output_dir ./parsed \
--concurrency 8 \
--image_mode base
Configuration Reference
| Parameter | Default | Description |
|---|---|---|
base_size |
1024 | Base resolution for image preprocessing |
image_size |
640 (gundam), 1024 (base) | Input image resolution |
crop_mode |
True (gundam), False (base) | Whether to crop dense content |
max_length |
32768 | Maximum output token length |
no_repeat_ngram_size |
35 | N-gram window for repetition avoidance |
ngram_window |
128 (gundam), 1024 (base) | Context window for n-gram dedup |
Verification Checklist
After deployment, test that everything works:
- Single image OCR works: process an invoice or scanned page → verify structured text output
- Multi-page PDF: process a 5+ page document → verify all pages are parsed in order
- API endpoint responds:
curl http://localhost:8000/v1/modelsreturns the model list - GPU utilization:
nvidia-smishows the model using GPU memory - No repetition artifacts: output should not have repeated phrases (the n-gram processor prevents this)
- No broken links: all dependencies (PyMuPDF, torch, transformers) are installed correctly
Resources
- GitHub repo: github.com/baidu/Unlimited-OCR
- Hugging Face model: huggingface.co/baidu/Unlimited-OCR
- arXiv paper: arxiv.org/abs/2606.23050
- vLLM recipe: recipes.vllm.ai/baidu/Unlimited-OCR
- Hugging Face demo: huggingface.co/spaces/baidu/Unlimited-OCR
- DeepSeek-OCR (predecessor): github.com/deepseek-ai/DeepSeek-OCR