Most optical character recognition tools stop at one page. They treat a document as a collection of independent images, and they lose the structure that only becomes visible across pages, such as tables that span a fold, footnotes that continue, or headings that belong to a section started earlier. Unlimited-OCR, released by Baidu in 2026 with a second version in October of that year, is built around a different idea. It parses an entire document in one request, using cross-page context, and it does so with a three billion parameter model released under the MIT license. The model runs on a single NVIDIA GPU, which makes it a practical choice for teams that cannot send documents to a cloud API.
What the model actually does
Unlimited-OCR is a vision language model trained for document parsing. It extends the approach of DeepSeek-OCR, and the second version introduces Sparse Reference Sliding Window Attention, a mechanism that compresses long attention interactions into a fixed set of working references, so that decoding cost stays nearly constant as documents grow. This is what the project calls unlimited horizon parsing. In practical terms, a multi page PDF is converted to images, all pages are passed in one request, and the output is marked with page separators so that text, tables, and layout can be reconstructed in order. The model reports state of the art results on long document benchmarks, including documents of one hundred pages, though such lengths require more graphics memory than a single page.
Two inference modes are provided. The gundam mode uses dynamic tiling for a single page and is the default for one image. The base mode encodes each page as one global view and is used for multi page documents and PDFs. Choosing the wrong mode does not break the run, but it changes accuracy and memory use, so the distinction matters in production.
What you need before installing
The local path requires three things. Python 3.10, an NVIDIA GPU with CUDA and at least eight gigabytes of memory for the three billion parameter model in bfloat16, and enough disk space for the model weights, which download automatically on first run. A CPU only setup is not practical for this model. The commands below use the native Transformers path, which is the simplest way to verify the model on one machine. For a production service with concurrency, the project recommends SGLang, and vLLM is also supported.
Step by step local installation
Each command below is on its own line so it can be selected and copied directly. Open a terminal and follow them in order.
python3.10 -m venv venv
source venv/bin/activate
pip install torch==2.13.0 torchvision pillow transformers==4.52.1 huggingface-hub==0.36.0 tokenizers==0.21.4 addict==2.4.0 einops==0.8.2 easydict==1.13 pymupdf==1.27.2.2
These versions are the ones tested by the project. Mixing other versions can produce silent errors in the custom model code, so pinning them is recommended. Next, create a file named ocr.py and copy the following lines into it, in order.
import torch
from transformers import AutoModel, AutoTokenizer
model_name = "baidu/Unlimited-OCR-2"
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()
text = model.infer(tokenizer, image_file="your_page.jpg", output_path="output/single", save_results=True)
print(text)
Run it with the command below. The first run downloads the model weights from Hugging Face, which can take several minutes depending on the connection.
python ocr.py
For a multi page document, replace the inference line with infer_multi and pass a list of page images in page order. The model builds the prompt automatically and returns one text block with page markers. For a PDF, convert each page to an image with PyMuPDF, which is installed as pymupdf in the command above, then pass the list of image paths to infer_multi. The repository also includes infer.py, which starts a batch server and processes a directory of images or a PDF with configurable concurrency. To use it, clone the repository with the command below and run infer.py with the arguments shown in its README.
git clone https://github.com/baidu/Unlimited-OCR.git
When to use the serving paths instead
The Transformers path is correct for testing and small volumes. For a service that receives concurrent requests, SGLang is recommended. It requires a custom wheel shipped in the repository's wheel directory, and it exposes an OpenAI compatible API on port 10000. The launch command sets the page window, the per page token cap, and memory fractions that must be tuned to the GPU. vLLM is the third option, with a one line serve command and official Docker images. Both serving paths trade setup complexity for throughput, and neither is necessary for a first local run.
Limits to keep in mind
Three caveats matter. First, the model loads with trust_remote_code=True, which means it executes custom code from the model repository. This is standard for vision language models, but it should be considered when the model is run inside a sensitive network. Second, the raw output contains layout markers such as detection tags that must be stripped before the text is usable, and the repository provides a post processing function for this. Third, very long documents require more graphics memory, and the project's own serving notes document several environment variables that control memory peaks. A single page is comfortable on a modest GPU. A one hundred page book is not.
Further notes on applied AI engineering are published on the blog, and deployment questions can be sent through the contact page. The code and model are published at github.com/baidu/Unlimited-OCR and huggingface.co/baidu/Unlimited-OCR-2, with the research paper at arXiv:2606.23050.


