baidu/Unlimited-OCR

Unlimited OCR Works: Welcome the Era of One-shot Long-horizon Parsing.

What it solves

Traditional OCR systems struggle with very long documents: as the number of pages grows, the attention mechanism that connects text to images scales quadratically, causing memory use and latency to balloon. Unlimited OCR 2 removes that barrier, letting you parse an entire book or a hundred-page PDF in a single request without losing cross-page context or running out of memory.

How it works

Unlimited OCR 2 builds on the earlier Unlimited OCR model and introduces a technique called Sparse Reference Sliding Window Attention (SR-SWA). Instead of letting every text token attend to every image patch across the whole document, SR-SWA compresses those interactions into a fixed-size set of "working references" (for example, 512 tokens). This keeps computation and memory nearly constant no matter how long the document is, so the model can handle arbitrarily long inputs within a finite context window. The model reads all pages in page order, uses cross-page context to improve accuracy, and outputs one text block per page.

For inference, you can use the native Transformers interface for quick tests or the recommended SGLang serving setup for production. The SGLang configuration includes knobs for page-window scheduling, memory limits, and CUDA graph settings, plus an OpenAI-compatible API for sending requests. There is also a batch client (infer.py) for standard benchmarks like MPDocBench and MarathonDocBench, with post-processing scripts to format the raw output.

Who it's for

Developers, researchers, and engineers who need to convert long multi-page documents—books, contracts, reports, academic papers—into structured text. It is especially useful when you need to parse an entire document at once, preserving context across pages, and when you want to deploy OCR at scale with predictable memory and latency.

Highlights

  • Sparse Reference Sliding Window Attention (SR-SWA) keeps decoding speed and memory usage nearly constant regardless of document length.
  • Achieves state-of-the-art results on dozen-page benchmarks (MPDocBench) and hundred-page benchmarks (MarathonDocBench).
  • Supports both Transformers (for quick tests) and SGLang (recommended for serving), with an OpenAI-compatible API.
  • Can parse full documents—even a full book—in a single request, using cross-page context.
  • Available on Baidu AI Cloud, Hugging Face, and ModelScope; training is supported via the ms-swift community.

Related

  • Dispatch
  • Project
  • Project
  • Project
  • Project