Baidu’s Open Source OCR Model Parses Hundred-Page Books In One Request: Here Is How SR-SWA Works

OCR

![OCR model SR-SWA: Baidu Unlimited OCR 2 parses hundred-page documents with constant-memory attention](HERO_IMAGE_URL)

Optical character recognition has quietly become one of the most practical applications of vision-language models, and it just hit a wall that everyone in the field knew about but few had addressed: documents are long. An end-to-end OCR model that reads one page beautifully falls apart on a hundred-page filing, because the attention mechanism at the heart of every modern language model scales quadratically, and a KV cache that grows with every page eventually makes generation slow, memory-hungry, or both.

Baidu's Unlimited OCR 2, released open source under the MIT license on October 27, 2026, attacks that wall directly. The 3.34B-parameter model parses books, filings and reports of hundreds of pages in a single request, and the trick that makes it possible is called SR-SWA, Sparse Reference Sliding Window Attention, which keeps the per-step decoding cost nearly flat no matter how long the document is. On Baidu's own hundred-page benchmark, it scores 77.1 while the next best model scores 33.7. This article works from the model card on Hugging Face, the GitHub repository and the underlying technical report, and it covers the architecture, the attention mechanism, the benchmark numbers with their caveats, and what the deployment story looks like in practice.

What Unlimited OCR 2 is

Unlimited OCR 2 is a vision-language model that takes ordered page images as input and emits structured text: body text, tables, formulas, figure descriptions, headings and reading order. It is a successor to Unlimited-OCR, which Baidu released in June 2026 to build on DeepSeek-OCR, the model that helped reignite interest in end-to-end document parsing.

The architecture follows the DeepSeek-OCR template: a SAM ViT-B plus CLIP-L encoder feeds a 12-layer mixture-of-experts decoder, with each token routed to 6 of 64 experts plus 2 shared experts. The model has 3.34B total parameters. In multi-page mode, each page costs 273 image tokens, which means a 100-page document presents 27,300 input tokens before a single output token is generated, and a 500-page document presents over 136,000. That arithmetic is what makes the attention problem unavoidable.

The use cases are the everyday ones that make OCR a serious business: digitizing book archives, parsing financial filings, converting legal documents into searchable structured text, and extracting tables from scanned reports. Output quality on tables and formulas is where modern OCR models differentiate themselves, and it is where this release posts its strongest numbers.

The attention problem, stated plainly

Standard attention compares every token with every other token, which means cost grows with the square of sequence length. During decoding, the problem compounds differently: each new output token must attend to the entire KV cache accumulated so far, and that cache only grows as generation continues. A model reading a long book does not just take longer to start; it gets slower and more memory-hungry with every page it reads.

The original Unlimited OCR paper describes this as the central limitation of using an LLM decoder for OCR. The upside of an LLM decoder is real, it leverages the prior distribution of language and produces better-formatted output than classical pipelines, but the downside is that long documents progressively slow generation. The paper's motivation is worth quoting in substance: this stands in contrast to humans, who show no such decline during long-horizon copying tasks, because human working memory does not re-read everything on every step.

How SR-SWA works

SR-SWA, Sparse Reference Sliding Window Attention, is the release's core contribution. Rather than letting every new token attend to the full, ever-growing sequence, it compresses text-visual attention interactions into a fixed set of working references, 512 tokens in the model card's example, paired with a small local window.

The configuration combines a 128-token local sliding window with top-16 selection over 32-token blocks, which produces 16 blocks of 32 tokens and matches the 512-token reference budget. At each decoding step, the model attends to the local window plus the fixed reference set instead of the entire history. Per-step latency and memory therefore stay nearly constant as the document grows, regardless of whether the input is 10 pages or 500.

Baidu calls the result unlimited-horizon parsing within a finite context window, and the phrasing is precise rather than marketing: the context window is still finite, and image encoding time still rises with page count, but the decoding bottleneck, the thing that made long-document OCR degrade as it progressed, is bounded. The original R-SWA mechanism from the June paper reduced attention computation while keeping the KV cache constant throughout decoding; version 2 adds the sparsity and reference selection that let the mechanism handle hundred-page documents.

There is a general lesson in the design worth naming for anyone following agent and long-context research: the technique is not OCR-specific. The June paper notes that R-SWA applies equally to speech recognition, translation and other long-horizon sequence tasks, which places it in the same family of constant-memory attention approaches that other labs have pursued from different directions this year.

The benchmarks, with their caveats

Baidu evaluated the model on MPDocBench, a public benchmark of 433 documents and 3,246 pages with dozens of pages per document, and on MarathonDocBench, a new benchmark for ultra-long documents with hundreds of pages, released by the team on October 27.

On MPDocBench, Unlimited OCR 2 scores 84.6, ahead of Qwen3.8-Max at 78.3 and Qwen3.8-Flash-Next at 77.4. On MarathonDocBench, the hundred-page benchmark, it scores 77.1 against 33.7 for Kimi-K3 and 28.6 for Gemini-3.8-Flash. The decisive comparison is not the absolute score but the degradation curve: Qwen3.8-Max falls from 78.3 on dozens of pages to 22.9 on hundreds of pages, a collapse of more than 55 points, while Unlimited OCR 2 drops only 7.5 points. The predecessor, Unlimited-OCR, scores 0.0 on MarathonDocBench, which quantifies what the attention mechanism fixed.

Sub-scores show the shape of the capability. On MPDocBench versus MarathonDocBench: text at 94.8 versus 89.6, formulas at 89.4 versus 87.9, reading order at 92.3 versus 85.3, tables at 87.8 versus 74.8, and heading hierarchy at 60.1 versus 48.2. Text and formulas survive the length increase nearly intact; table structure degrades more; heading hierarchy is the clear weak spot, and it is the weakest sub-score on both benchmarks.

The caveats belong next to the OCR numbers, and they are substantial. Every benchmark figure is Baidu's own, and the leaderboards appear only as chart images rather than as published tables, which makes precise verification difficult. MarathonDocBench is the team's own new benchmark, released the same day as the model, so no independent third party has run it. Single-metric margins on MPDocBench are thin, with Qwen3.8-Max scoring 94.3 on text against 94.8, so the headline lead rests on the long-document regime rather than on universal superiority. A contamination check is not published. Treat the long-document gap as credible but unverified, and the short-document lead as narrow.

How it compares with the open OCR field

The open-source OCR landscape now has several purpose-built models, and the differences are instructive. DeepSeek-OCR-2, the architectural ancestor, ships under Apache 2.0 with 3.39B parameters and does not disclose a long-document mechanism. PaddleOCR-VL-1.6, from Baidu's own PaddlePaddle team, is much smaller at 0.96B parameters and Apache 2.0. The predecessor Unlimited-OCR shares the 3.34B size and MIT license but lacks SR-SWA, and its MarathonDocBench score of 0.0 makes the version-2 upgrade a precision instrument rather than a refresh.

Licensing differences matter for anyone embedding OCR commercially. MIT and Apache 2.0 are both permissive, but MIT is the looser of the two, which makes Unlimited OCR 2 attractive for commercial embedding where attribution terms are the only constraint. Serving support is the practical differentiator: the new model supports Transformers and a customized SGLang wheel, while the predecessor also supports vLLM. Teams standardizing on vLLM will need to wait for that integration or use the Transformers path.

Running it, and the footguns

The model card supports Transformers for quick tests and SGLang for serving, tested on an NVIDIA A800-80GB in BF16, with BF16 weights totaling about 6.7 GB, comfortably within a single CUDA GPU.

The Transformers path is deliberately simple. A single-page call uses dynamic tiling, which the team calls gundam mode, and a multi-page call, infer_multi, parses every page of a document in one request so the model keeps cross-page context. The prompt is constructed automatically as a repeated page marker followed by an instruction, and the output contains one page section per input page in order.

Two deployment warnings are worth surfacing, because both are the kind of thing that costs an afternoon. First, loading requires trust_remote_code=True, which executes Python code shipped in the model repository. That is the same mechanism this site covered in the Unsloth Studio research: it is a legitimate requirement for models with custom architectures, and it should still be a conscious, audited decision on a machine whose credentials you care about. Second, the customized SGLang wheel is not upstream SGLang, and the model card documents a default setting that can trigger a 462 MiB allocation and out-of-memory failures, with a documented environment variable to reduce the peak. The memory tuning notes, from static memory fractions to prefill token caps, read like field notes from a real deployment, and they are worth reading before a first run regardless of your hardware.

What it means for document-heavy work

For teams building on OCR, this release shifts what is possible in one request, and it lands in a document-parsing market that this site has watched accelerate, from the agent platforms reading their own context to the model releases that DeepSeek-OCR helped inspire. Digitizing a book archive, extracting structured data from a thousand-page filing, or batch-parsing a document corpus no longer requires chunking pipelines that split documents into page groups and stitch results, losing cross-page context like table headers and running section structure along the way. A single-request model that maintains cross-page context removes an entire class of stitching bugs.

For the research community, the release is a concrete demonstration that constant-memory attention can carry a real production workload, not just a benchmark, and the publication of MarathonDocBench gives the field a shared yardstick for the hundred-page regime. The comparison with the Nemotron architecture analysis is instructive: Nemotron added Mamba-2 layers for linear-cost long context, DSpark attacked decoding speed, and SR-SWA attacks decoding memory, three independent attacks on the same underlying constraint from three different labs. The constraint is quadratic attention, and 2026 is the year the field stopped accepting it.

Choosing an OCR model in 2026: a practical comparison

With DeepSeek-OCR, its successor, two Baidu entries and PaddleOCR-VL all open and capable, picking one is a workload question rather than a leaderboard question, and the decision factors are concrete.

Document length is the first filter. For single pages and short files, every model in the field performs well, and factors such as table fidelity on your specific document types, formula support if you process scientific material, and license terms dominate. The moment documents run past a few dozen pages, the attention mechanism becomes the deciding factor, and SR-SWA is currently the only published design among the open models that explicitly bounds decoding cost at that scale. A team parsing contracts or books should verify the long-document claim on its own samples; a team parsing invoices should not pay for it.

Deployment footprint is the second filter. All three architectures are around 3B parameters, small enough for a single GPU, but the serving story differs: the predecessor supports vLLM, the new model ships a customized SGLang wheel, and PaddleOCR-VL integrates with its own mature pipeline. If your infrastructure is standardized on one serving stack, the integration cost may outweigh the benchmark deltas, which are thin on short documents regardless.

Output structure is the third. All of these models emit markdown-flavored structure, but table fidelity and heading hierarchy vary by document type, and the only reliable evaluation is running your own fifty documents through each candidate and scoring the output against ground truth. That afternoon of work is worth more than any published leaderboard, because OCR errors compound downstream, in retrieval systems that index wrong text and in analytics that inherits wrong numbers.

The final factor is trajectory. OCR models are shipping quarterly, benchmarks are being published for the long-document regime for the first time, and the constant-memory attention techniques landing in OCR will migrate to transcription and translation within the year. Choosing a model with an active release cadence and a permissive license, which describes all four open entries, keeps the switching cost low.

Where the numbers stop

  • All benchmark scores are Baidu's own, published as leaderboard chart images rather than reproducible tables. No independent evaluation was available at release.
  • MarathonDocBench is Baidu's own benchmark, released on October 27, 2026, the same day as the model. No third-party results exist yet, and the benchmark's composition and grader are described in Baidu's materials only.
  • Active parameter count is not disclosed; the 3.34B figure is total parameters, and the MoE routing means the compute per token is lower than the total suggests.
  • MPDocBench margins are thin on individual sub-scores, with Qwen3.8-Max within 0.5 points on text. The long-document regime is where the differentiation is claimed, and that is the regime where independent verification is thinnest.
  • Heading hierarchy is the weakest sub-score on both benchmarks, 48.2 on long documents, which means structural outlines of very long documents may need post-processing.
  • The A800-80GB hardware reference and memory figures come from Baidu's testing; other GPUs and quantizations will produce different footprints, and the model card's OOM warning shows the serving configuration is sensitive.
  • I have not run the model. Every capability and figure here is cited from Baidu's published materials.

FAQ

What is Unlimited OCR 2?

It is a 3.34B-parameter open-source vision-language OCR model from Baidu, released October 27, 2026 under the MIT license, built to parse very long documents. It converts ordered page images into structured output covering text, tables, formulas, figures, headings and reading order, and it can parse hundreds of pages in a single request. It runs on one CUDA GPU in BF16, with weights around 6.7 GB.

What is SR-SWA and why does it matter?

SR-SWA stands for Sparse Reference Sliding Window Attention. Instead of letting every decoding step attend to the entire growing sequence, it compresses text-visual attention into a fixed 512-token set of working references plus a 128-token local window. That keeps per-step decoding latency and memory nearly constant as documents grow, eliminating the quadratic slowdown that makes conventional LLM-based OCR degrade on long documents. The mechanism is general-purpose and applicable beyond OCR to tasks such as translation and speech recognition.

How accurate is it?

By Baidu's own published benchmarks, it scores 84.6 on MPDocBench, a public dozens-of-pages benchmark, and 77.1 on MarathonDocBench, the team's new hundred-page benchmark, where the next best model scores 33.7. Its weakest area is heading hierarchy on long documents, at 48.2. All figures are self-reported through chart images, MarathonDocBench is Baidu's own new benchmark with no independent results yet, and MPDocBench margins over Qwen3.8-Max are thin on individual sub-scores, so the long-document claim is the credible one and the universal-superiority claim is not.

The short version

Unlimited OCR 2 is Baidu's MIT-licensed 3.34B OCR model that parses hundred-page documents in one request, powered by SR-SWA, a sparse attention scheme that bounds decoding cost to a fixed 512-token reference set plus a small local window. On Baidu's benchmarks it holds 77.1 on hundred-page documents where competitors collapse into the 20s and 30s, with its predecessor scoring zero. The mechanism is the story: constant-memory attention carried to a real workload, with a general-purpose design that applies beyond OCR. The caveats are equally clear: self-reported benchmarks, a homegrown hundred-page benchmark, undisclosed active parameters, and a heading-hierarchy weak spot. For document-heavy teams, the model changes the chunking calculus; for the field, it is another confirmation that quadratic attention is the constraint 2026's best work is dismantling.

Sources

Subscription Form