Maestro OCR

How to run Unlimited-OCR locally

You need an NVIDIA GPU, Python 3.12 and the pinned Transformers stack; then three lines load baidu/Unlimited-OCR and one call reads an image or a whole PDF. Commands below are copied from Baidu's official README (checked 16 October 2026).

No GPU? Try the model in Baidu's free Hugging Face demo, or use our in-browser OCR tool (Tesseract, not Unlimited-OCR) for private documents.

What hardware do I need?

An NVIDIA GPU with CUDA; Baidu tested Python 3.12.3 with CUDA 12.9. The model has 3.34B parameters in BF16 (about 6.7 GB of weights), so we suggest 12 GB or more of VRAM for full precision (our estimate; Baidu publishes no minimum). Because R-SWA keeps the KV cache flat, memory does not grow much with document length.

The official code calls .cuda(), so it does not run on a Mac or CPU as published.

Run with Hugging Face Transformers

Install the pinned versions, load the model with trust_remote_code=True, and call model.infer(). Pinning matters: the model ships custom code that was tested against these exact versions.

pip install torch==2.10.0 torchvision==0.25.0 transformers==4.57.1 \
  Pillow==12.1.1 matplotlib==3.10.8 einops==0.8.2 addict==2.4.0 \
  easydict==1.13 pymupdf==1.27.2.2 psutil==7.2.2
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,
).eval().cuda()

# One image. "gundam" config: base_size=1024, image_size=640, crop_mode=True
model.infer(
    tokenizer,
    prompt='<image>document parsing.',
    image_file='your_image.jpg',
    output_path='out',
    base_size=1024, image_size=640, crop_mode=True,
    max_length=32768,
    no_repeat_ngram_size=35, ngram_window=128,
    save_results=True,
)

For a single image you can also use the “base” config: base_size=1024, image_size=1024, crop_mode=False.

How do I OCR a PDF?

Render each page to PNG at 300 dpi with PyMuPDF, then pass all page images to model.infer_multi(). Multi-page input uses only the base config (image_size=1024) and a wider n-gram window.

import os, tempfile, fitz  # PyMuPDF

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)
    return paths

model.infer_multi(
    tokenizer,
    prompt='<image>Multi page parsing.',
    image_files=pdf_to_images('your_doc.pdf'),
    output_path='out',
    image_size=1024,
    max_length=32768,
    no_repeat_ngram_size=35, ngram_window=1024,
    save_results=True,
)

Serve with vLLM

Baidu points to the official vLLM recipe and publishes two Docker images: the default for CUDA 13.0 and one for Hopper GPUs on CUDA 12.9.

docker pull vllm/vllm-openai:unlimited-ocr        # CUDA 13.0
docker pull vllm/vllm-openai:unlimited-ocr-cu129  # Hopper, CUDA 12.9

Serve with SGLang (batch PDFs and folders)

SGLang gives an OpenAI-compatible server, and the repo's infer.py starts it for you and OCRs a whole folder or PDF concurrently. It needs the SGLang wheel shipped in the repo, so clone it first.

git clone https://github.com/baidu/Unlimited-OCR && cd Unlimited-OCR
uv venv --python 3.12 && source .venv/bin/activate
uv pip install wheel/sglang-*.whl
uv pip install kernels==0.11.7 pymupdf==1.27.2.2

python infer.py --pdf ./examples/document.pdf --output_dir ./outputs \
  --concurrency 8 --image_mode gundam

Use --image_dir instead of --pdf for a folder of images, and --gpu 0 to choose a GPU. Note the README text says kernels==0.9.0 but its command pins 0.11.7; we follow the command.

Quantised GGUF and Ollama builds

Hugging Face lists dozens of community quantisations (GGUF for llama.cpp, LM Studio and Ollama). They need less VRAM and may run on Apple Silicon, but Baidu does not publish or test them, so check accuracy on your own documents before relying on one.

Watch for lookalikes: the official repository is github.com/baidu/Unlimited-OCR. Other organisations using the same name are not Baidu.

What does the output look like?

The model emits text grouped into layout blocks with <|det|>type [bbox]<|/det|> markers (paragraphs, tables, figures). Strip the markers if you only want text; the README includes a remove_det() helper used for OmniDocBench evaluation.

Can I use it commercially?

Yes. The code and weights are under the standard MIT licence (“Copyright (c) 2026 Baidu”): keep the copyright and licence notice and you may use, modify and sell products built on it.