Baidu releases Unlimited OCR 2 for documents hundreds of pages long
Baidu has released Unlimited OCR 2, a 3.34-billion-parameter OCR model under the MIT license. It reads books, reports and business documents running to hundreds of pages in a single request. A sparse attention method called SR-SWA makes that possible by keeping the compute cost per step almost constant.

What this is about
Baidu has released Unlimited OCR 2, an open-source text recognition model (OCR, short for Optical Character Recognition) for very long documents. The model has 3.34 billion parameters, which are, roughly speaking, the dials it adjusted during training. It converts ordered page images into structured text: running text, tables, formulas, figures, headings and reading order. Books, annual reports or government filings running to hundreds of pages are meant to be processed in a single request. The weights are released under the MIT license, and the code is on GitHub. The model succeeds Unlimited-OCR, which came out in June 2026 and was meant as a further development of DeepSeek-OCR.
Model architecture
Unlimited OCR 2 is a vision-language model, meaning a model that processes images and text together. The configuration follows the DeepSeek-OCR layout: an image encoder built from SAM ViT-B and CLIP-L feeds a 12-layer decoder built as a Mixture-of-Experts (MoE). Each token is routed to only some of the "experts", here 6 of 64, plus 2 shared experts. In the DeepSeek-OCR paper, this decoder is called DeepSeek3B-MoE-A570M. For version 2, Baidu doesn't give a number of active parameters. In multi-page mode, each page costs 273 image tokens, so 100 pages already produce 27,300 input tokens before the model writes any output.
How SR-SWA works
Standard attention grows quadratically with input length. For every newly generated token, the model has to search an ever longer cache (KV cache). That makes long documents slow and memory-hungry.
Baidu's solution is called SR-SWA (Sparse Reference Sliding Window Attention). It compresses the attention between text and image into a fixed set of working references. The model card's example uses 512 tokens. The configuration combines a local window of 128 tokens with a top-16 selection over blocks of 32 tokens, meaning 16 blocks of 32 tokens, which matches the 512 budget. Latency and memory per step therefore stay almost constant even as the document grows. Baidu speaks of "unlimited-horizon" parsing within a finite context window. Image encoding and total runtime still grow with the number of pages, though.
Benchmarks
Baidu tests on two benchmarks: MPDocBench with dozens of pages per document and MarathonDocBench with hundreds. MPDocBench-Parse is public and covers 433 documents with 3,246 pages. MarkTechPost couldn't find a public version of MarathonDocBench.
According to Baidu's chart, Unlimited OCR 2 scores 84.6 on MPDocBench, followed by Qwen3.8-Max (78.3) and Qwen-3.8-Flash-Next (77.4). On MarathonDocBench it scores 77.1, followed by Kimi-K3 at 33.7 and Gemini-3.8-Flash at 28.6. The collapse of other models stands out: Qwen3.8-Max drops from 78.3 to 22.9, while Unlimited OCR 2 falls by just 7.5 points. The predecessor scores 0.0 on MarathonDocBench.
| Sub-score | MPDocBench | MarathonDocBench |
|---|---|---|
| Text | 94.8 | 89.6 |
| Formulas | 89.4 | 87.9 |
| Reading order | 92.3 | 85.3 |
| Tables | 87.8 | 74.8 |
| Heading hierarchy | 60.1 | 48.2 |
On some individual metrics, the lead on MPDocBench is slim: Qwen3.8-Max scores 94.3 on text and 89.2 on formulas.
Comparison with other open OCR models
| Unlimited OCR 2 | Unlimited-OCR | DeepSeek-OCR-2 | PaddleOCR-VL-1.6 | |
|---|---|---|---|---|
| Developer | Baidu | Baidu | DeepSeek | Baidu PaddlePaddle |
| Parameters | 3.34B | 3.34B | 3.39B | 0.96B |
| License | MIT | MIT | Apache 2.0 | Apache 2.0 |
| Long-document mechanism | SR-SWA | Multi-page without SR-SWA | not stated | not stated |
| MPDocBench | 84.6 | 61.9 | not reported | not reported |
| MarathonDocBench | 77.1 | 0.0 | not reported | not reported |
What you need to try it
The model runs on a single CUDA graphics card in BF16. Baidu tested on an NVIDIA A800 with 80 GB. The weights are around 6.7 GB, and long documents need extra memory for the cache and images. A card with 12–16 GB might be enough for short documents, but Baidu doesn't confirm this. Plan for a few GB of free disk space. The source says nothing about Mac or CPU-only operation. Google Colab with a GPU is conceivable but not confirmed.
The model card names Transformers for quick tests and SGLang for server operation. In Transformers, infer processes one page with dynamic tiling ("Gundam mode"), while infer_multi processes all pages of a document in one request, so cross-page context is preserved. Loading requires trust_remote_code=True, which executes Python code from the repository. For SGLang, Baidu uses a custom wheel instead of the upstream package. The example processes 10 pages per window and carries over the KV tail of the previous window. Smaller windows lower peak memory but weaken cross-page merging. According to Baidu, a default bias setting can trigger a 462 MiB allocation and cause out-of-memory errors.
Our take
If you want to digitize long PDFs or scans (contracts, reports, books) without splitting them up, a small, freely licensed model with constant decoding cost is interesting. The large gap to models such as Kimi-K3 and Qwen3.8-Max on hundred-page documents would be remarkable, but it hasn't been independently verified so far. All figures come from the vendor and exist only as an image, and MarathonDocBench isn't publicly available. A clear weakness is heading hierarchy (48.2), and the number of active parameters remains unknown. The cost of image encoding keeps growing with page count, so "unlimited" applies only with caveats. Running a custom SGLang build is also less convenient than with predecessors that support vLLM.
Sources
- MarkTechPost marktechpost.com
- Hugging Face Trending huggingface.co
- r/LocalLLaMA github.com
- Google News (FR) news.google.com
- QbitAI 量子位 (CN) qbitai.com
- AI Times (KR) aitimes.com
Try it yourself: Unlimited OCR 2
Explained step by step, no prior knowledge needed – on your own computer or free in your browser.
What can I do with it?
Unlimited OCR 2 reads page images and turns them into structured text. OCR stands for text recognition: a scan or photo becomes text you can copy and search. The model recognizes more than words. It also captures tables, formulas, headings and reading order. What's special: it is meant to process whole books, reports or government files running to hundreds of pages in a single request while keeping the connections between pages. SR-SWA makes that possible. It's a trick that keeps memory use per step almost constant even as the document grows. According to Baidu, the model clearly beats big competitors on hundred-page documents (77.1 points versus 33.7 for the runner-up). But those figures come only from the vendor and haven't been independently verified. Heading hierarchy recognition is weak (48.2 points on hundred-page documents). "Unlimited" also holds only with caveats: image encoding and total runtime keep growing with page count.
Who is it worth it for?
It's worth trying if you're tech-curious, a developer or anyone who wants to digitize long PDFs or scans and has access to a CUDA (NVIDIA) graphics card. You should know a little Python and the command line. If you don't have a suitable GPU, the easiest way to try it is Baidu's demo on Hugging Face Spaces. It's probably not for you if you expect a ready-made click-through interface or if the heading structure has to be reliably correct.
Ideas: What you can do with it
You scan letters, certificates or a printed family book page by page as images. Then you process all pages in one request with `infer_multi`. The result is searchable text in reading order. Spot-check names and numbers.
You convert the pages of an annual report into structured text. You can then process the tables further, for example for an analysis. According to Baidu, tables are a strength (74.8 on hundred-page documents), but check the numbers anyway.
You scan a lecture script or a textbook chapter and have text and formulas recognized. The result works as a basis for your own notes or for searching. According to Baidu, formulas are recognized well, but spot checks still make sense.
You digitize long contracts or filings without splitting them up first. With the full text, you search for deadlines or clauses. Don't rely on the recognized outline: heading hierarchy is the model's weakest discipline.
You start SGLang as a server with the OpenAI-compatible interface. Colleagues send PDFs by script and get text back. This is a project for the technically inclined, where you'll need to fine-tune memory settings.
What your computer needs
There is one variant, with 3.34 billion parameters in BF16 (a number format that saves memory). The weights are around 6.7 GB. The source doesn't mention quantized, meaning further shrunken, versions. Baidu tested on an NVIDIA A800 with 80 GB. A card with 12–16 GB might be enough for short documents. Baidu doesn't confirm this, so test it yourself with a few pages. For hundreds of pages, a large card makes more sense, because the cache and images need extra memory. Start with Transformers. For continuous operation as a server, the model card recommends SGLang.
- The model runs on a single CUDA graphics card in BF16. Baidu tested on an NVIDIA A800 with 80 GB.
- The weights are around 6.7 GB. On top of that comes memory for the cache (KV cache) and images. Also plan for a few GB of free disk space.
- In multi-page mode, each page costs 273 image tokens. So 100 pages are already 27,300 input tokens before the model writes anything.
- On the SGLang server, the page window (10 pages in the example) limits peak memory. Smaller windows save memory but weaken cross-page merging.
- For `--mem-fraction-static`, the model card says 0.7 is stable. With 0.75, there's too little reserve at 32 or more concurrent requests.
- The source says nothing about Mac (Apple Silicon) or CPU-only operation. Whether Google Colab with a GPU works hasn't been confirmed.
How do I find out what my computer has?
- Windows: Press Ctrl + Shift + Esc → Task Manager → Performance tab → click GPU on the left. At the bottom you'll see Dedicated GPU memory (that's your VRAM). You'll find system memory under Memory.
- Mac: Apple menu at the top left → About This Mac. You'll see your chip (e.g. M2) and memory (e.g. 16 GB). On Apple chips, graphics and processor share this memory.
- Linux: Type
nvidia-smiin the terminal (shows your graphics card and its memory) andfree -hfor system memory.
Guide
This model runs with its developers' own program (baidu/Unlimited-OCR on GitHub). The commands below come from the Model Card and the developers' instructions.
In the browser (no installation)
The developers have an online demo on Hugging Face. You can try the model right away there without installing anything. Sometimes you have to wait a moment for the demo to wake up.
Windows 10 / 11
Windows 10 / 11: not officially tested. The source lists only Linux with an NVIDIA A800 as tested. On Windows it should work with an NVIDIA graphics card and a matching driver, but this isn't verified. Alternatively, use WSL2 with Linux or the online demo on Hugging Face (Space baidu/Unlimited-OCR).
- Check the prerequisites. You need Python 3.10, an NVIDIA graphics card with a current NVIDIA driver (with CUDA support) and about 10 GB of free space. Open PowerShell and check that Python and the graphics card are detected.
py -3.10 --version nvidia-smi - Create a working folder. Create a new, empty folder and change into it. All your files will live there later.
mkdir unlimited-ocr cd unlimited-ocr - Create a virtual environment. A virtual environment (venv) keeps the packages separate from the rest of your system. If PowerShell blocks activation, the Set-ExecutionPolicy command helps (for this session only).
py -3.10 -m venv .venv Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass .venv\Scripts\Activate.ps1 - Install the packages. These are exactly the versions the developer tested with. The download is large and takes a while. If CUDA isn't detected afterwards, you need the CUDA build of torch.
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 - Download the model. The model is about 6.7 GB. The download also happens automatically on first start, but this way you can see the progress.
hf download baidu/Unlimited-OCR-2 - Prepare your own page image. Take a photo or screenshot of a document page and save it in the working folder as page_1.jpg.
- Save the script demo.py. Save this code as demo.py in the working folder. It loads the model and reads the page.
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="page_1.jpg", output_path="output/single", save_results=True) print(text) - Run the script. The first run takes a while because the model is loaded into VRAM (video memory). After that, the recognized text appears.
python demo.py - Result. The folder output/single contains the text recognition result for page_1.jpg, and the recognized text also appears in the terminal.
macOS
macOS: not supported. The source's guide requires an NVIDIA graphics card (CUDA; the code contains .cuda()). That doesn't run on a Mac as written. Try the online demo on Hugging Face (Space baidu/Unlimited-OCR) or Google Colab with an NVIDIA GPU instead.
Linux
Linux: supported. The tested setup is the Transformers variant with Python 3.10 on an NVIDIA A800 (80 GB). You need an NVIDIA graphics card with CUDA. For continuous operation as a server, the developer recommends SGLang. For a first test, Transformers is enough.
- Check the prerequisites. You need Python 3.10 with the venv module, an NVIDIA graphics card with the NVIDIA driver installed and about 10 GB of free space. Check that Python and the graphics card are detected.
python3.10 --version nvidia-smi - Create a working folder. Create a new, empty folder and change into it. All your files will live there later.
mkdir unlimited-ocr cd unlimited-ocr - Create a virtual environment. A virtual environment (venv) keeps the packages separate from the rest of your system.
python3.10 -m venv .venv source .venv/bin/activate - Install the packages. These are exactly the versions the developer tested with. The download is large and takes a while.
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 - Download the model. The model is about 6.7 GB. The download also happens automatically on first start, but this way you can see the progress.
hf download baidu/Unlimited-OCR-2 - Prepare your own page image. Take a photo or screenshot of a document page and save it in the working folder as page_1.jpg.
- Save the script demo.py. Save this code as demo.py in the working folder. It loads the model and reads the page.
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="page_1.jpg", output_path="output/single", save_results=True) print(text) - Run the script. The first run takes a while because the model is loaded into VRAM (video memory). After that, the recognized text appears.
python demo.py - Result. The folder output/single contains the text recognition result for page_1.jpg, and the recognized text also appears in the terminal.
Try it
Easy start: pass a single page (e.g. a photo of an invoice) to `infer` and have it converted to text.Pass a 7-page scanned PDF as images `page_1.jpg` to `page_7.jpg` to `infer_multi` and check that the pages come out in the right order (one `<PAGE>` marker per page).Take a scanned textbook chapter with formulas and check whether formulas and reading order are correct.Feed in a 40-page contract and check whether paragraphs and headings are cleanly separated. Pay special attention to the heading levels.Advanced: send a 120-page annual report through the SGLang server and check whether tables that span a page break are merged correctly. Compare window sizes of 10 pages and smaller.
Tips for better results
- Start small: test one page with `infer`, then 5–10 pages with `infer_multi`, before you start a whole book.
- Pass the pages in the right order. The output contains one `<PAGE>` marker per page, so you can quickly see whether everything arrived.
- For the server, Baidu's example uses 10 pages per window. If memory gets tight, shrink the window. If content spans page breaks, a larger window helps.
- Baidu's example converts PDFs to images at 300 dpi. That's a sensible starting point for clean scans.
- For reproducible results, Baidu's example uses a `temperature` of 0. It also sets a generous output buffer of 8000 tokens per page. The value must be positive.
If something goes wrong
Loading with Transformers requires `trust_remote_code=True`. That executes Python code from the repository. Check the source first and ideally use a separate environment.
The model card lists tested versions: Python 3.10, `torch==2.13.0`, `transformers==4.52.1`. If you deviate, errors can occur. Install the packages exactly as specified there.
For SGLang you need Baidu's custom wheel, not the regular SGLang package. You also need PyMuPDF for PDF conversion and `fastokens`.
If you run out of memory (OOM): set `SGLANG_OPT_UOCR_SAM_REL_POS_BIAS_MB=64`. The built-in default allows an allocation of about 462 MiB, which can trigger errors.
Other levers against out-of-memory errors, per the model card: `--mem-fraction-static 0.7`, `--max-prefill-tokens 2048` and `PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True`.
Multi-page documents belong in `infer_multi`. With `infer`, each page is read on its own, and the page context is lost.
“out of memory,” a crash, or your computer freezes
The model is too big for your VRAM (video memory). Pick a smaller variant from the table above and close other programs, especially games and browsers with lots of tabs.
It runs, but extremely slowly
Your CPU is probably doing the work instead of your graphics card. In Ollama, the PROCESSOR column of ollama ps shows how much runs on the GPU. If it says "100% CPU", update your graphics driver or pick a smaller variant that fits entirely into VRAM (video memory).
“ollama” or “python” is not found
Close the terminal window and open it again so it recognizes the newly installed program. For Python on Windows: reinstall it and check Add python.exe to PATH.
Windows: "Running scripts is disabled on this system"
Run the script with exactly the command above: powershell -ExecutionPolicy Bypass -File try_windows.ps1. This allows execution for this one time only.
Error message when loading the model (version, "trust_remote_code", unknown architecture)
Brand-new models often need the latest software version. With Ollama: update Ollama. With Python: pip install -U transformers in the activated environment. The Model Card usually lists the exact version.
Tokenstrom generates the scripts and notebook automatically. Please take a quick look before running them – they're plain, readable text. Mind the model's license: mit.
Ask the AI assistant
Questions about this article, installation or background? Our assistant knows this page and runs on our own machine, not in someone else's cloud.
The Assistant is an AI (Gemma 4) and can make mistakes – please check important details against the source. Questions are used only to generate an answer and are deleted after one hour. Please don't enter any personal data.
Comments
What do you think? Already tried it? Write it here, no sign-up needed.
Comments are public. Links aren't allowed, and we delete abusive posts. You can delete your own comment at any time in this browser. Learn more in the Privacy Policy.