Unlimited-OCR: One-shot Long-horizon Document Parsing from Baidu

Baidu's Unlimited-OCR enables one-shot parsing of long documents and PDFs with a single forward pass, supporting up to 32K context length.

What is Unlimited-OCR?

Unlimited-OCR is a new open-source OCR model from Baidu that aims to push the boundaries of document parsing — specifically, it targets one-shot long-horizon parsing. Unlike traditional OCR systems that process pages one by one or rely on sliding windows, Unlimited-OCR can take an entire multi-page document (or a high-resolution single image) and produce structured text output in a single forward pass.

This is a significant step forward for document understanding, especially for long-form content like research papers, legal contracts, or multi-page reports.

Why It Matters

Most OCR pipelines break documents into individual pages or regions, process them independently, and then stitch results back together. This approach has several drawbacks:

  • Context loss: Information spanning page boundaries is lost.
  • Slow inference: Each page requires a separate model call.
  • Complex pipeline: You need page detection, ordering, and merging logic.

Unlimited-OCR solves these by accepting multiple images (or a PDF converted to images) and generating a single coherent output. The model supports a context length of 32,768 tokens, which is enough to cover dozens of dense pages.

Key Features

  • One-shot long-horizon parsing: Feed multiple pages at once, get a single output.
  • Two inference modes: gundam (crop-based, 640px image size) for single images with fine detail, and base (1024px image size) for multi-page or PDF parsing.
  • vLLM and SGLang support: Deploy with production-grade inference engines.
  • Open source: MIT license, available on GitHub and Hugging Face.
  • 32K context length: Handles long documents without truncation.

How to Use Unlimited-OCR

Quick Start with Transformers

The simplest way to get started is with Hugging Face Transformers. Here's a minimal example:

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,
    use_safetensors=True,
    torch_dtype=torch.bfloat16,
)
model = model.eval().cuda()

# Single image parsing (gundam mode for high detail)
model.infer(
    tokenizer,
    prompt='<image>document parsing.',
    image_file='your_image.jpg',
    output_path='./output',
    base_size=1024, image_size=640, crop_mode=True,
    max_length=32768,
    no_repeat_ngram_size=35, ngram_window=128,
    save_results=True,
)

Multi-page / PDF Parsing

For multi-page documents, you convert each page to an image and use infer_multi:

import fitz  # PyMuPDF

def pdf_to_images(pdf_path, dpi=300):
    doc = fitz.open(pdf_path)
    mat = fitz.Matrix(dpi / 72, dpi / 72)
    paths = []
    for i, page in enumerate(doc):
        out = 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('your_doc.pdf', dpi=300),
    output_path='./output',
    image_size=1024,
    max_length=32768,
    no_repeat_ngram_size=35, ngram_window=1024,
    save_results=True,
)

Deployment with vLLM

For production, vLLM is the recommended inference engine. Baidu provides pre-built Docker images:

# Default (CUDA 13.0)
docker pull vllm/vllm-openai:unlimited-ocr

# For Hopper GPUs (CUDA 12.9)
docker pull vllm/vllm-openai:unlimited-ocr-cu129

Then follow the official recipe: https://recipes.vllm.ai/baidu/Unlimited-OCR

SGLang Deployment

SGLang is also supported. Set up the environment and start the server:

uv venv --python 3.12
source .venv/bin/activate
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

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 \
    --skip-server-warmup \
    --host 0.0.0.0 \
    --port 10000

Then send requests via the OpenAI-compatible API:

import requests

response = requests.post(
    "http://127.0.0.1:10000/v1/chat/completions",
    json={
        "model": "Unlimited-OCR",
        "messages": [
            {
                "role": "user",
                "content": [
                    {"type": "text", "text": "document parsing."},
                    {"type": "image_url", "image_url": {"url": "data:image/png;base64,..."}}
                ]
            }
        ],
        "temperature": 0,
        "images_config": {"image_mode": "gundam"},
        "custom_logit_processor": "DeepseekOCRNoRepeatNGramLogitProcessor",
        "custom_params": {"ngram_size": 35, "window_size": 128},
        "stream": True,
    },
    timeout=1200,
    stream=True,
)

Performance and Benchmarks

While the README doesn't include detailed benchmarks, the model's architecture is designed for long-horizon parsing. The 32K context length and the no_repeat_ngram_size parameter (set to 35) help avoid repetition in long outputs — a common problem in autoregressive models.

The gundam mode uses a crop-based approach with image_size=640, which is ideal for single images where fine detail matters (e.g., a dense page of text). The base mode uses image_size=1024 without cropping, better suited for multi-page documents where global layout is important.

Comparison with DeepSeek-OCR

Unlimited-OCR explicitly positions itself as pushing "DeepSeek-OCR one step further." The key improvements appear to be:

  • Longer context: 32K tokens vs. earlier models.
  • Multi-page support: Native handling of multiple images in one pass.
  • Production-ready: vLLM and SGLang support out of the box.
  • Open source: MIT license, fully reproducible.

Use Cases

  • Research paper parsing: Feed an entire PDF, get structured text.
  • Legal document analysis: Contracts, agreements, and forms.
  • Invoice and receipt processing: Batch processing of documents.
  • Historical document digitization: Long documents with complex layouts.
  • RAG pipelines: Use Unlimited-OCR as a document parser before indexing.

Getting Started

  1. Clone the repo: git clone https://github.com/baidu/Unlimited-OCR
  2. Install dependencies: pip install torch transformers pillow pymupdf
  3. Run inference with the examples above.
  4. For production, use the vLLM Docker images.

Conclusion

Unlimited-OCR is a practical, open-source solution for one-shot long-horizon document parsing. Its support for multi-page inputs, 32K context, and production-grade inference engines makes it a strong choice for developers building document understanding pipelines. The MIT license and active community support (13k+ stars on GitHub) suggest it will continue to evolve.

If you're working on OCR, document parsing, or RAG pipelines, this is a project worth trying.

Source

baidu/Unlimited-OCR: Unlimited OCR Works: Welcome the Era of One-shot Long-horizon Parsing.