Second generation of Baidu's long-document OCR parsing model: It processes page images from multi-page documents (or even entire books) sequentially in a single pass, outputting parsed results page by page while leveraging cross-page context. The first generation aimed to advance DeepSeek-OCR, while the second generation introduces SR-SWA attention, removing the constraint of document length being limited by the context window.
Rising Score 234 · Likes 245 · Downloads 513
Reasons
- SR-SWA (Sparse Reference Sliding Window Attention) compresses image-text attention in ultra-long sequences into a fixed number of working references (e.g., 512 tokens). Officially, per-step decoding latency and memory usage remain nearly constant regardless of document length.
- Officially claimed to achieve the best results on benchmarks for both tens of pages (MPDocBench) and hundreds of pages (MarathonDocBench), with the MarathonDocBench dataset also released publicly. Specific scores are only shown in leaderboard images and are not listed in the text.
- MIT License; released on 10 27, not included in previous issues. The model card includes a replay GIF of parsing an entire Harry Potter book in a single request. It is also available on ModelScope and Baidu Intelligent Cloud. The Rising Score 234 only reflects attention level.
Usage
- Quick test with Transformers (official environment: Python 3.10, torch 2.13.0, transformers 4.52.1, A800-80GB): AutoModel.from_pretrained("baidu/Unlimited-OCR-2", trust_remote_code=True, use_safetensors=True, torch_dtype=torch.bfloat16); for multi-page documents, pass a list of images in page order to model.infer_multi(tokenizer, image_files=...), use model.infer(...) for single pages, with the default chunking 'gundam' mode.
- For serving, the official recommendation is SGLang: Install the official custom SGLang wheel (0.5.20.dev10) and PyMuPDF, set environment variables as specified in the card (default: one window per 10 pages, output limit of 20000 tokens per page), start with --chat-template unlimited-ocr, and use the OpenAI-compatible interface; convert PDFs to images at 300 dpi first.
- Set temperature to 0 in requests, and attach an n-gram logit processor to prevent repetition as shown in the examples (ngram_size 35, window_size 1024 for multi-page, 128 for single page).
Risks
- Requires trust_remote_code, and SGLang requires installing a custom wheel; the model card does not specify parameter count or minimum memory requirements, and the Transformers path has only been tested on A800-80GB.
- Smaller page windows reduce memory usage, but officially, content crossing window boundaries loses context; the default settings for SAM attention bias may cause memory overflow, so they need to be changed to 64 as specified in the card.
- "Best results" are self-reported by the official team; the leaderboard only contains images, with no verifiable numbers.