Baidu researchers have presented an OCR model designed for a problem that current end-to-end systems struggle to solve: reading long documents without slowing down as the generated text grows. The model, called Unlimited OCR, can handle dozens of document pages in a single inference pass while keeping memory use and speed constant regardless of text length.
The key change is not a larger decoder or a bigger cache. It is a redesigned attention mechanism that limits what the model remembers from its own output while keeping the document image and prompt available throughout generation.
Why long OCR documents strain current models
Modern OCR systems increasingly use a language model as the decoder. That setup helps turn visual document information into structured text, but it also creates a memory problem during generation.
The bottleneck is the KV cache. This buffer stores previously processed tokens so the model can refer back to them while producing new output. As a model reads more lines, the cache grows. More stored tokens mean more memory use and slower generation.
According to the Baidu researchers' technical report, no current OCR model handles more than about ten pages in one pass. Existing systems typically avoid the cache problem by processing documents page by page and resetting the cache after each step.
That workaround is practical, but it breaks the idea of treating a longer document as one continuous job. Unlimited OCR is built to keep the process moving without repeatedly clearing state between pages.
The attention trick behind Unlimited OCR
Baidu frames the design with a simple human analogy. A person copying a book does not constantly re-read everything already written. The person focuses on the source material, the most recent characters, and the next character to copy. Older output fades into the background.
Unlimited OCR applies that idea through Reference Sliding Window Attention, or R-SWA. Each generated token can still attend to all reference tokens, including the visual image tokens and the prompt. But for previously generated output, it only looks back at the last 128 tokens.
That fixed look-back window keeps the KV cache from expanding with every new output token. Instead of growing linearly with text length, the cache is capped at the fixed sum of prefix length and window size.
This differs from standard sliding window attention in an important way. If visual tokens were also pushed through the same shifting state, image features could gradually blur and recognition quality could decline. R-SWA avoids that by encoding visual tokens once and keeping them unchanged.
What Baidu built on top of Deepseek OCR
Unlimited OCR builds on the open-source Deepseek OCR model. Baidu keeps the DeepEncoder and combines it with a mixture-of-experts architecture with three billion parameters. During inference, only about 500 million parameters are active.
The DeepEncoder compresses a 1024-by-1024-pixel PDF image into 256 tokens. Two resolution modes also carry over from the base system. Base mode is used for multi-page documents, while Gundam mode uses dynamic resolution for single pages.
The decoder is where the main architectural change happens. Baidu replaced every standard attention layer in the decoder with R-SWA.
Training used about two million document samples, split 9-to-1 between single-page and multi-page data. Paddle OCR handled annotation for single pages. For multi-page data, the team synthetically stitched single pages into documents ranging from two to 50 pages.
All data was packed into sequences of 32,000 tokens. Training ran for 4,000 steps on 8 times 16 Nvidia A800 GPUs. The DeepEncoder stayed frozen, and only the language model parameters were updated.
Accuracy and speed results
The researchers report that Unlimited OCR reaches 93 percent overall on OmniDocBench v1.5, six percentage points above the Deepseek OCR baseline. On OmniDocBench v1.6, it reaches 93.92 percent, placing it at the top of the end-to-end system rankings.
The benchmark covers several document understanding tasks. Pure text recognition improves slightly by edit distance, while table structure recognition rises more sharply, by nearly six percentage points.
The long-horizon results are central to the claim. When processing many pages in one pass, the model keeps its error rate below 0.11 even past 40 pages. Baidu says the remaining errors mainly appear when text is tiny, and attributes them to the DeepEncoder's resolution limit in Base mode rather than to lost context.
Limiting the generated-output window to 128 tokens also does not hurt single-page accuracy. The researchers say it slightly helps, and suggest that R-SWA may keep the model focused on the dense OCR task while full attention can drift as output grows longer.
The fixed cache also improves throughput. In Base mode, Unlimited OCR reaches 5,580 tokens per second, compared with 4,951 for Deepseek OCR. That is a 12.7 percent increase. In a theoretical upper-bound comparison with ideal parallelism, Unlimited OCR leads the baseline by 35 percent at around 6,000 output tokens.
Why it is not truly unlimited yet
The name Unlimited OCR points to the goal, but the current model still has a fixed context length of 32,000 tokens. Visual tokens accumulate with each added page, so the number of pages is still bounded.
Baidu plans to train 128,000-token models soon. The researchers also describe a future prefill pool that would let the model retrieve relevant KV blocks on its own, similar to flipping through a book.
The team sees R-SWA as useful beyond document OCR. Because it is designed for tasks where a model uses a stable reference while generating output, the authors point to speech recognition and translation as possible applications.
Code and model weights are available on GitHub and Hugging Face. The model runs on ModelScope and the inference engines vLLM and SGLang, and it can be tried in a demo on Hugging Face Spaces.
The broader significance is clear from the direction of OCR research. Models are competing on token efficiency, not just recognition quality. If documents can be read from images with less compute than their digital text equivalents, OCR-style representations could matter for long chat histories, large documents, and other memory-heavy AI workflows.