Baidu Open-Sources Unlimited OCR 2 to Parse Hundreds of Pages Without Breaking

Baidu's open-source Unlimited OCR 2 parses hundred-page documents in a single pass using a new sparse attention trick that caps memory growth.

·
·
·
Baidu Open-Sources Unlimited OCR 2 to Parse Hundreds of Pages Without Breaking
Read5 min
TypeNews
SubtopicOcr
  • Baidu open-sources Unlimited OCR 2, a 3B VLM for parsing hundred-page documents in one request.
  • New SR-SWA attention compresses history into a fixed-size reference pool, keeping memory nearly constant.
  • Claims SOTA on MPDocBench and MarathonDocBench long-document benchmarks.
  • MIT-licensed, with Transformers, SGLang, and vLLM inference paths.
  • Multi-page mode preserves cross-page context for tables, references, and reading order.
  • Builds on DeepSeek-OCR and PaddleOCR, targeting the quadratic-attention bottleneck in long docs.

Baidu has released Unlimited OCR 2, a 3-billion-parameter vision-language model that parses ordered page images from short files through documents hundreds of pages long. It targets a persistent OCR problem: splitting large documents into isolated chunks can break reading order, cross-page tables, references, and other layout relationships.

The MIT-licensed release includes model weights, a Transformers interface, code in a GitHub repository, and serving recipes for SGLang and vLLM. Baidu’s main technical contribution is Sparse Reference Sliding Window Attention, or SR-SWA, which limits the attention state retained while the model moves through a document.

Component Details
Input Ordered page images; PDF pipelines must rasterize pages before using the shown Transformers API
Output Document text with headings, tables, formulas, figures, and reading order
Interfaces Transformers for testing; SGLang and vLLM recipes for serving
License MIT

A fixed reference pool caps attention growth

Conventional full attention performs pairwise work across the input, giving a sequence of length L an attention cost of O(L2). Optimized kernels can reduce temporary memory use, but the number of interactions remains quadratic. During KV-cached autoregressive decoding, stored keys and values grow linearly, while every new token scans a longer history.

SR-SWA compresses text and visual interactions into a fixed-size pool of reference tokens, with 512 tokens given as an example in the release. The model updates this rolling pool as it processes pages, allowing later output to use a compressed representation of earlier content without scanning the full token history at every decoding step.

Baidu describes the result as “unbounded” document parsing within a finite context window. The term refers to bounded attention state: per-token decoding latency and memory can remain nearly stable as the document grows. Image encoding, output generation, and total runtime still increase with the number of pages.

Strong reported scores need workload checks

Baidu reports state-of-the-art results on MPDocBench, which covers documents spanning dozens of pages, and MarathonDocBench, which extends to hundreds. Its published leaderboard compares Unlimited OCR 2 with Qwen, Gemini, GLM, DeepSeek, MiniMax, and Kimi model families across text extraction, tables, formulas, figures, and reading order.

Baidu leaderboard comparing Unlimited OCR 2 with other document-parsing models
Baidu’s reported results on long-document parsing benchmarks.

These results are author-reported. Cross-model comparisons can shift with page resolution, prompts, decoding settings, model versions, and task-specific post-processing. A production evaluation should preserve original page order and include representative scans, languages, layouts, multi-page tables, and documents near the intended length limit.

The quick path starts with page images

The Transformers integration exposes infer for individual pages and infer_multi for ordered page sets. Single-page inference uses dynamic tiling, called “gundam mode” in the project, to divide a page into image regions. Multi-page inference encodes each page as one global view and parses the sequence in one call so compressed context can flow across page boundaries.

python
from transformers import AutoModel, AutoTokenizer
import torch

tokenizer = AutoTokenizer.from_pretrained(
    "baidu/Unlimited-OCR-2",
    trust_remote_code=True,
)

model = AutoModel.from_pretrained(
    "baidu/Unlimited-OCR-2",
    trust_remote_code=True,
    torch_dtype=torch.bfloat16,
).eval().cuda()

pages = [f"doc/page_{i}.jpg" for i in range(1, 50)]

text, n_tokens = model.infer_multi(
    tokenizer,
    image_files=pages,
    output_path="out",
)

The example assumes a CUDA-capable GPU with bfloat16 support. Three billion bfloat16 parameters require about 6 GB for weights alone, with additional memory needed for image tensors, activations, caches, runtime kernels, and concurrent requests. The trust_remote_code=True option executes Python supplied by the model repository, so deployments should inspect the code and pin a reviewed revision.

SGLang makes the trade-offs explicit

Baidu’s production recipe emphasizes SGLang and uses a customized wheel supplied through the repository. Its controls expose how page windows, output limits, and static memory allocation affect long-document serving. The KV cache mentioned below stores attention keys and values from previously processed tokens.

Setting Purpose and trade-off
SGLANG_UOCR_DOC_GUNDAM_PAGE_WINDOW Sets the number of pages scheduled per window. The next window reuses the previous window’s KV-cache tail. Smaller values reduce peak memory while weakening context across window boundaries.
SGLANG_UOCR_MAX_PAGE_TOKENS Caps output tokens per page, preventing one malformed or difficult page from consuming the document’s generation budget.
SGLANG_OPT_UOCR_SAM_REL_POS_BIAS_MB Limits chunks used for SAM relative-position bias. Baidu says the 512 MB default can exhaust GPU memory and recommends 64 MB as an equivalent lower-memory setting.
--mem-fraction-static 0.7 Reserves less memory for static allocation than the 0.75 default, leaving more headroom when serving 32 or more concurrent requests.

Cross-page context comes with limits

Unlimited OCR 2 fits books, legal filings, scientific papers, financial reports, and scanned archives where independent page processing loses document structure. Cross-page state may help with tables that continue onto another page, repeated headers, section hierarchy, and references whose targets appear elsewhere in the file.

SR-SWA stores a lossy summary of earlier content. A fixed reference pool can discard details needed much later, such as a footnote on page 3 that changes the interpretation of text on page 190. SGLang page windows introduce another boundary: blocks that continue across windows receive only the retained cache tail, and Baidu warns that smaller windows can reduce cross-page merging quality.

Unlimited OCR 2 builds on DeepSeek-OCR, DeepSeek-OCR-2, PaddleOCR, and Baidu’s first Unlimited OCR release. Its evidence currently covers document parsing. Applying sparse-reference attention to long video, repository-scale code, or other extended sequences remains a research direction. Architecture, training, and benchmark details are available in the paper.

Trending
  • No trending articles

Comments

avatar

Next Reads