Baidu Unlimited-OCR reads 40+ pages in one pass without blowing the KV cache

A 3B MoE model with Reference Sliding Window Attention parses long PDFs in a single forward pass. Here is when it beats page-by-page OCR pipelines for RAG and document automation.

SaifullahSaifullah
4 min read
Baidu Unlimited-OCR reads 40+ pages in one pass without blowing the KV cache

Every document RAG pipeline I inherit has the same hack: split the PDF into pages, OCR each one, stitch the text back together, and pray tables that cross page boundaries survive.

Baidu Unlimited-OCR attacks that loop directly. Released June 22, 2026 under MIT license, it is a 3B-parameter Mixture-of-Experts model (roughly 500M active at inference) that parses dozens of pages in one forward pass.

The trick is not a bigger context window. It is a decoder attention design that keeps the KV cache flat while generation runs.

Why page-by-page OCR breaks on real documents

Standard end-to-end OCR models slow down as output grows. Each generated token adds to the KV cache. Memory rises. Generation drags. Parsing a 40-page contract becomes impractical.

Teams respond with a for-loop: process page 1, forget context, process page 2, repeat. It works for simple scans. It fails when:

  • A table spans two pages
  • Footnotes reference content on the previous page
  • Reading order depends on multi-column layout
  • Headers and section numbers need continuity

Baidu's paper states plainly: no existing model could parse ten pages in a single forward pass before this work. Everyone used the loop.

Side-by-side: page-by-page OCR loop versus single-pass multi-page parsing with flat KV cache

Reference Sliding Window Attention (R-SWA)

Unlimited-OCR builds on DeepSeek OCR via continued training, not from scratch.

The core change: Reference Sliding Window Attention in the decoder. Instead of letting the KV cache grow with every token, R-SWA keeps memory constant during generation.

ApproachKV cache behaviorMulti-page in one pass
Standard decoder attentionGrows with output lengthImpractical past ~10 pages
Long-context extensionsGrows with input lengthMemory-heavy
R-SWA (Unlimited-OCR)Constant during decodeDozens of pages under 32K limit

The 32K token ceiling still applies. Visual tokens for all input pages must fit in the prefill, and the transcription must fit in the generation budget. "Unlimited" means the decode cache does not balloon, not that context is infinite.

Benchmark numbers worth knowing

On OmniDocBench v1.5, Unlimited-OCR scores 93.23%, beating the DeepSeek OCR baseline by 6.22 points.

Baidu's multi-page eval reports edit distance staying below 0.11 at 40+ pages, with 96.90% Distinct-35 (a metric for output diversity across long runs).

CapabilityReported result
OmniDocBench v1.593.23% overall
40+ page single passEdit distance < 0.11
Text, tables, formulasSingle forward pass
LicenseMIT (commercial OK)

Independent replication is still thin a month after release. Treat the 40+ page claim as a strong benchmark result, not a guarantee on your messy scanned archives.

Inference modes and setup

Two modes matter:

  • Gundam mode (base_size=1024, image_size=640, crop_mode=True): single images, higher detail on crops
  • Base mode (image_size=1024, no crop): multi-page and PDF workflows

PDFs convert to page images with PyMuPDF, then feed into infer_multi in Base mode.

model.infer( tokenizer, prompt="<image>document parsing.", image_file="scan.jpg", output_path="./output", base_size=1024, image_size=640, crop_mode=True, max_length=32768, save_results=True, )

For production throughput, SGLang serves an OpenAI-compatible API with the fa3 attention backend. Hugging Face Transformers works for single-GPU experiments.

Hardware reality: 8-bit quantized builds can run on 8GB VRAM for testing. Production parsing at 1024px pages typically wants 12-24GB VRAM.

Workflow diagram: PDF to PyMuPDF page images to Unlimited-OCR infer_multi to structured text output

When I would use this in a client pipeline

Good fits:

  • Contract and invoice ingestion where tables cross pages
  • Book-length scans for internal search (under the 32K window)
  • Batch document parsing with SGLang on a single GPU fleet
  • Replacing per-page OCR + merge scripts in existing RAG stacks

Skip or hybrid:

  • Documents pushing past ~40 pages (chunk strategically, overlap windows)
  • Tiny text on low-res scans (Base mode at 1024px can miss fine print)
  • When you already pay for Mistral OCR 4 and latency is fine

For teams building private-data RAG, Unlimited-OCR pairs well with the document-block patterns in my RAG for business guide. The win is continuity across pages, not raw OCR accuracy on a single screenshot.

Adoption curve (June to July 2026)

The release log moved fast:

  • June 22: weights + paper
  • June 24: Hugging Face Spaces demo
  • June 28: vLLM inference support
  • July 3: Baidu Cloud integration
  • July 21: ms-swift training framework support

Tens of thousands of GitHub stars and millions of Hugging Face downloads in the first month suggest teams are actually trying it, not just bookmarking the repo.

Baidu also offers a managed document parsing API on Baidu Cloud for teams that do not want to self-host. Async task POST + poll pattern, same as most cloud OCR services.

Practical takeaway

Unlimited-OCR does not kill the page-by-page pipeline overnight. It gives you a credible open-source path when cross-page continuity is the bottleneck.

If your RAG quality drops on long PDFs and you have been blaming the embedding model, check the OCR stage first. A flat KV cache and single-pass parsing might be the cheaper fix.

Building document automation or private-data RAG? Book a free call and we can map whether single-pass OCR fits your volume, hardware, and compliance constraints.

Share this post

Related posts