How Baidu Unlimited-OCR Solves Long-Document Transcription
In this article
Baidu released Unlimited-OCR approximately one month ago, positioning it as a direct architectural advance over DeepSeek OCR for multi-page document transcription. The core problem it targets is not recognition accuracy on individual pages — it is the memory and latency collapse that occurs when autoregressive decoders generate tens of thousands of output tokens across hundred-page documents. For engineers building document-processing pipelines, that distinction matters: the input-side compression problem was already largely addressed by DeepSeek OCR, and Unlimited-OCR is specifically an output-side fix.
The Two-Sided Token Problem DeepSeek OCR Partially Solved
Vision-language OCR models convert every document page into a grid of patch embeddings before the transformer sees anything. Higher patch counts preserve fine-grained detail — small fonts, dense tables, handwriting — but also multiply input token counts and GPU memory proportionally. DeepSeek OCR addressed this with optical compression, reducing a page that would otherwise produce 1,000 visual tokens down to 128 tokens at a 16× compression ratio. At 10× compression, the DeepSeek paper reports approximately 97% accuracy retention; accuracy drops sharply beyond that threshold. DeepSeek OCR shipped with five resolution modes, letting practitioners trade token count against detail preservation depending on document complexity.
That compression strategy controls a fixed up-front cost. Once encoding is complete, the decoder takes over — and on a 100-page document the transcription can run to tens of thousands of output tokens. Under standard transformer attention, every newly generated token extends the Key-Value (KV) cache, causing GPU memory consumption and per-step attention cost to grow without a ceiling. This output-side bottleneck is independent of how efficiently the input was encoded, and it is what DeepSeek OCR left unsolved.
Unlimited-OCR builds directly on DeepSeek OCR's visual encoder (specifically its Base and Gundam variants) and adds a decoding mechanism — Reference Sliding Window Attention (R-SWA) — to cap the KV cache at a constant size regardless of output length. For context on how open-source benchmarks are stress-testing OCR systems across these dimensions, the Chandra OCR 2 open-source benchmark provides a useful reference frame.
Reference Sliding Window Attention: How the KV Cache Stays Flat
Standard sliding window attention keeps only a fixed window of recent tokens in the cache, discarding earlier context. Applied naively to OCR, that would cause the model to lose access to the document image itself once the window slides past the initial visual tokens. R-SWA avoids this by dividing the attention context into two structurally distinct segments.
The static reference prefix holds the compressed visual tokens from the DeepSeek encoder plus the system prompt. These tokens are pinned permanently and remain visible to every generated token throughout decoding. The causal sliding window holds only the most recently generated output tokens, with the source specifying a window of approximately 128 tokens. As decoding continues, this window advances and older output tokens are discarded.
The total KV cache size equals m + n, where m is the fixed visual token count and n is the fixed sliding window length. Neither component grows with output length, so whether the decoder produces 500 tokens or 30,000 tokens, memory footprint remains approximately constant. This is the architectural claim behind the "Unlimited" label — not that documents have no practical limit, but that the decoder's memory cost is decoupled from transcription length.
Architecture vs. DeepSeek OCR: What Changed and What Didn't
| Dimension | DeepSeek OCR | Baidu Unlimited-OCR |
|---|---|---|
| Visual encoder | Original DeepSeek visual encoder | DeepSeek visual encoder (Base and Gundam variants, reused) |
| Input compression | Optical compression, up to 16× (e.g. 1,000 → 128 tokens) | Inherited from DeepSeek OCR unchanged |
| Accuracy at 10× compression | ~97% retained (per DeepSeek paper) | Same baseline; encoder not modified |
| Resolution modes | 5 discrete modes | Inherited; not redesigned |
| Decoder attention | Standard full causal attention; KV cache grows linearly with output length | R-SWA: static visual prefix + ~128-token sliding window; KV cache fixed at m + n |
| Long-document memory behaviour | GPU memory grows without bound as output tokens accumulate | Constant memory footprint regardless of output length |
| Model availability | Separate release | Open-sourced; weights on Hugging Face at baidu/Unlimited-OCR |
| Inference frameworks supported | Transformers | Transformers, vLLM, SGLang |
Running Unlimited-OCR in Practice
Baidu open-sourced both weights and inference code. The model loads via Hugging Face Transformers with AutoModel.from_pretrained("baidu/Unlimited-OCR", trust_remote_code=True, use_safetensors=True, device_map="auto"), and the repository also exposes a pipeline("image-text-to-text") interface for simpler use cases. Required dependencies include torch, torchvision, transformers, Pillow, matplotlib, einops, addict, easydict, pymupdf, and psutil.
For production serving, Baidu's repository includes vLLM support. Running vllm serve "baidu/Unlimited-OCR" spins up an OpenAI-compatible API endpoint, making it straightforward to slot Unlimited-OCR into an existing RAG or document-processing pipeline without writing custom serving code. SGLang is listed as a third option for teams already invested in that runtime. This deployment flexibility is increasingly relevant as document-processing workloads move toward the agentic architectures discussed in what the agentic era means for data science.
What This Demonstrates
Unlimited-OCR reframes long-document OCR as an information-management problem rather than a model-scaling problem. Optical compression reduces the cost of reading high-resolution pages; R-SWA keeps decoding memory flat by preserving access to the document image while retaining only a short recent history of generated text. The broader principle — that long-context vision-language inference can be made memory-stable by being precise about which tokens need to persist during decoding — is likely to propagate into other multimodal tasks well beyond OCR.