Baidu just built an OCR system that reads long documents without choking on its own memory, and the trick is teaching the model to forget. As detailed in The Decoder, the new “Unlimited OCR” model can process dozens of pages in a single pass by capping how much of its own output it holds in memory at any moment. It scores higher than the model it’s built on while using less compute per step.
Most end-to-end OCR systems use a language model as the decoder, and that decoder keeps a running buffer (the KV cache) of everything it’s generated. Every new line of text makes the buffer bigger. Memory climbs, generation slows, and eventually the system has to reset page by page just to keep going. That reset is why “read the whole document at once” has been hard.
The human copying trick
Baidu framed the fix around how a person copies a book by hand. You don’t re-read every word you’ve already written. You watch the source, glance at the last few characters you wrote, and move on. Older passages fade.
The model does the same thing through what the team calls Reference Sliding Window Attention, or R-SWA. Each token it generates can still see all the reference material (the image tokens and the prompt), but it only looks back at the last 128 tokens of its own output. That keeps the KV cache a fixed size instead of growing with every line. The cache runs like a queue: each new token pushes out the oldest one.
One smart detail: standard sliding-window attention would also degrade the visual image tokens over time, blurring the features and hurting recognition. R-SWA freezes those visual tokens. They’re encoded once and never change.
How they built it
Unlimited OCR sits on top of the open-source Deepseek OCR model. Baidu kept its DeepEncoder, which compresses a 1024×1024 PDF image down to just 256 tokens, and paired it with a mixture-of-experts decoder of three billion parameters, only about 500 million of which fire during inference.
- Training used roughly two million document samples, split 9-to-1 between single-page and multi-page data.
- Multi-page examples were made synthetically by stitching single pages into documents of 2 to 50 pages.
- Every standard attention layer in the decoder was swapped for R-SWA.
- Training ran 4,000 steps on 128 Nvidia A800 GPUs, with the DeepEncoder frozen.
The numbers
The payoff shows up on the benchmarks, according to the authors:
- 93 percent overall on OmniDocBench v1.5, six points above the Deepseek OCR baseline.
- 93.92 percent on the newer v1.6, topping the end-to-end rankings.
- Table structure recognition jumped nearly six points.
- In long-document tests, the error rate stayed below 0.11 even past 40 pages.
- Speed hit 5,580 tokens per second in Base mode versus 4,951 for Deepseek OCR, a 12.7 percent bump.
What stands out here is that limiting attention to 128 tokens didn’t cost accuracy. It helped slightly. The researchers suspect the tight window forces the model to focus on the dense OCR task, while full attention tends to drift as output grows.
What it means and where it falls short
The honest part: it’s not truly unlimited yet. The model’s 32,000-token context still caps how many pages fit, because visual tokens stack up with each page added. Baidu says it plans 128,000-token versions next, plus a system that lets the model fetch relevant memory blocks on its own, like flipping through a book. Any remaining errors, the team notes, come from the encoder’s resolution limit on tiny text, not from lost context.
The bigger picture is why practitioners should care. OCR has quietly become one of AI’s most active battlegrounds, with models competing on token efficiency. Because image-based text costs far less compute than digital text, this approach could stretch a language model’s memory for long chat histories and huge documents, not just scanned pages.
If you want to test it, the code and weights are already on GitHub and Hugging Face, and the model runs on vLLM and SGLang. You can find the full breakdown at The Decoder.