Baidu released Unlimited-OCR-2 on October 27, 2026, alongside MarathonDocBench, a benchmark for parsing documents roughly 100 to 300 pages long. The release targets a practical problem in document AI: keeping a parser running across many pages without letting its attention workload grow with the full document history.
The main change is Sparse Reference Sliding Window Attention, or SR-SWA. Baidu says it reduces text-and-image attention interactions to a fixed-size working set, helping keep per-step decoding latency and memory use nearly constant as documents grow. The company also claims state-of-the-art performance on long-document benchmarks. Those are vendor-reported claims; the supplied sources contain no independent reproduction of the performance or scaling results. The dated announcement appears in the model card.
The release includes downloadable model weights, a native Transformers inference path, and a customized SGLang serving path. Its most consequential feature is the ability to submit multiple pages together and preserve cross-page context, which gives it a different role from an OCR pipeline that processes every page separately.
What Sparse-Reference Attention Changes
A document parser has more work to do than recognize characters. It may also need to preserve reading order, reconstruct tables, identify headings, and connect content that continues onto another page. A table split across pages is a useful example: recognizing both halves separately leaves another system responsible for deciding how they belong together.
Long-context vision-language models can address that problem by processing more of the document together. But retaining an ever-growing sequence creates a resource problem. In conventional dense attention, attention interactions across a sequence can grow quadratically with sequence length. During autoregressive generation, attending over an expanding history also increases the work associated with each new output token.
Baidu’s technical description says SR-SWA compresses those interactions into a fixed-size set of working references, giving 512 tokens as an example. The goal is to bound the attention work needed at each decoding step, even as the parser moves through a much longer document.
That distinction matters when interpreting the model’s name. A bounded attention working set is a scaling mechanism, not a promise that a thousand-page file takes the same time or total memory as a ten-page file. More pages still require image processing and more output. Loading images, storing results, scheduling requests, and holding model weights also consume resources.
My view is that stable per-step behavior is the useful engineering claim here. If it holds under realistic workloads, developers could plan long-running parsing jobs without attention state becoming progressively more expensive. “Unlimited” is a less useful deployment specification because it says little about throughput, output length, or accuracy late in a document.
A finite working set also should not be treated as perfect recall of every earlier page. The published design describes parsing within a finite context window. Whether the retained references preserve the details a particular workflow needs remains an accuracy question, especially for distant cross-references and complex table continuations.
Multi-Page Parsing Is a Distinct Inference Mode
Unlimited-OCR-2 exposes a multi-page method called infer_multi. According to the repository documentation, it accepts page images in document order and parses them in one request, allowing the model to use cross-page context.
The method builds its prompt automatically and returns one <PAGE> marker for each input page, in the same order. That provides a useful page boundary in the output, though applications still need to interpret the generated content.
The documented single-page and multi-page methods also use different image-processing modes:
| Inference method | Documented image handling | Practical consequence |
|---|---|---|
infer_multi | One global view per page, called base mode | Processes ordered pages together with cross-page context |
infer | Dynamic tiling by default, called gundam mode | Uses a different visual-input path for an individual page |
This difference deserves attention in an evaluation. Comparing one multi-page request against repeated single-page calls changes both the availability of cross-page context and the image representation. Any accuracy difference cannot automatically be attributed to context alone.
For a workflow with dense tables or small print, I’d compare the supported modes on representative pages before choosing a production path. That recommendation follows from the documented preprocessing difference; the release evidence does not quantify its effect on those particular document types.
Running Unlimited-OCR-2 Locally
The Hugging Face listing identifies the model as MIT-licensed and lists roughly 3.34 billion parameters. Its published safetensors files total about 6.69 GB, predominantly using BF16 weights.

That download size is not a GPU memory requirement. Inference also needs memory for activations, attention state, image processing, and runtime allocations. Baidu documents a Transformers test environment using an NVIDIA A800 with 80 GB of memory, but that is a reported setup, not a stated minimum.
Transformers for Direct Inference
Baidu describes Transformers as the native path for quick tests. Its documented environment uses:
- Python 3.10
- PyTorch
2.13.0 - Transformers
4.52.1 - Hugging Face Hub
0.36.0 - Tokenizers
0.21.4
The repository also lists dependencies including Pillow, Torchvision, Addict, Einops, and EasyDict. These version details matter because the model uses custom code, so developers should begin with the documented environment instead of assuming any current Transformers installation will work.
The following example follows the published loading and multi-page interface:
import torch
from transformers import AutoModel, AutoTokenizer
model_name = "baidu/Unlimited-OCR-2"
tokenizer = AutoTokenizer.from_pretrained(
model_name,
trust_remote_code=True,
)
model = AutoModel.from_pretrained(
model_name,
trust_remote_code=True,
use_safetensors=True,
torch_dtype=torch.bfloat16,
).eval().cuda()
pages = [
f"your_doc/page_{page_number}.jpg"
for page_number in range(1, 8)
]
text, num_tokens = model.infer_multi(
tokenizer,
image_files=pages,
output_path="output/multi",
save_results=True,
)
This example loads the model onto a CUDA GPU in BF16, supplies seven page images in order, and requests saved results. The method returns parsed text and a token count. It is a usage example, not a measured performance result.
The trust_remote_code=True setting allows repository-provided Python code to run during loading. For a production deployment, reviewing that code and pinning a reviewed repository revision are sensible safeguards. Downloadable weights do not remove the software-supply-chain considerations that come with custom model implementations.
The interface shown here accepts page images. Teams starting with PDFs therefore need a rendering step before this Transformers call, plus a way to preserve page order and map output back to the original document.
SGLang for Serving
Baidu recommends SGLang for serving, but its instructions use a customized wheel, sglang-0.5.20.dev10+g8d62f5fb9c-py3-none-any.whl, supplied with the repository. The documented setup uses Python 3.10 and adds PyMuPDF 1.27.2.2 for PDF-to-image conversion and Fastokens 0.3.2.
That is a meaningful compatibility detail. The documented path depends on a particular SGLang build, so a generic upstream installation is not the same setup.
The serving instructions expose page-window scheduling for very long documents:
export SGLANG_UOCR_EANABLE_DOC_LIMIT=1
export SGLANG_UOCR_DOC_GUNDAM_PAGE_WINDOW=10
export SGLANG_UOCR_DOC_BASE_PAGE_WINDOW=10
export SGLANG_UOCR_MAX_PAGE_TOKENS=20000
These are configuration excerpts, not a complete server launch command. The spelling EANABLE matches the repository’s documented variable.
With those settings, the server uses ten-page windows and a per-page output cap of 20,000 tokens. The documentation says the key-value cache tail from the previous window is reused. Setting the document-limit switch to 0 instead places the whole document in one window.
A single document request can therefore be scheduled internally in smaller windows. Cross-page context does not require every page to remain in one giant active attention block throughout processing.
The output cap also puts a concrete boundary on the “unlimited” label. A page that needs more output than its configured allowance could be truncated. Raising that allowance changes the deployment’s resource and runtime exposure.
Memory Tuning Still Matters
The SGLang instructions include several memory-management controls. One concerns the chunk size for a SAM attention-bias calculation: Baidu says the built-in value of 512 can permit a single allocation of roughly 462 MiB and cause an out-of-memory error. Its example lowers SGLANG_OPT_UOCR_SAM_REL_POS_BIAS_MB to 64, which it describes as equivalent in computation with a lower peak allocation.
That setting is separate from the example 512-token reference set in the SR-SWA description. The shared number does not make them the same control.
The instructions also enable passing large crop tensors through /dev/shm, disable the VLM cache, and configure expandable CUDA allocator segments to reduce fragmentation failures. Moving tensors through shared memory changes how data passes between processes; it does not make the data disappear from the machine’s memory budget.
Frequently Asked Questions
4 questions
1Is Unlimited-OCR-2 Openly Available?
Yes. Baidu publishes downloadable weights on Hugging Face, where the model is listed under the MIT license. The release also provides local inference instructions.





