Listen to this Post

Introduction:
For years, organizations have been held hostage by proprietary OCR APIs that charge per page—Amazon Textract, Google Cloud Vision, and Azure Document Intelligence all operate on a pay-per-page model that scales painfully with volume. But on June 22, 2026, Baidu shattered this paradigm by open-sourcing Unlimited-OCR, a 3-billion-parameter vision-language model that reads entire 40-page documents in a single forward pass—completely free, running 100% locally on your own machine. With 14,600 GitHub stars, 2.12 million Hugging Face downloads in a single month, and benchmark scores that crush the competition, this MIT-licensed model represents a fundamental shift in how enterprises approach document processing at scale.
Learning Objectives:
- Understand the architectural innovations—Reference Sliding Window Attention (R-SWA) and constant KV cache—that enable one-shot long-horizon document parsing
- Deploy Unlimited-OCR locally using Transformers, vLLM, SGLang, or GGUF-quantized versions for resource-constrained environments
- Compare cost and performance against proprietary cloud OCR services like Amazon Textract and Google Document AI
- Implement production-ready OCR pipelines with multi-page PDF support, multilingual recognition, and structured Markdown output
- Optimize inference speed and memory usage across NVIDIA, AMD, and Apple Silicon hardware
- The R-SWA Breakthrough: How Unlimited-OCR Solves the “Long-Document Amnesia” Problem
Traditional end-to-end OCR models suffer from a fatal flaw: the decoder’s KV cache grows linearly with every generated token. By page 10, decoding slows noticeably; by page 20, you’re either out of memory or quality degrades because attention is spread too thin. The industry’s workaround—chunking documents page by page in a for-loop—breaks cross-page context and loses reading order.
Unlimited-OCR solves this through Reference Sliding Window Attention (R-SWA). The mechanism keeps visual tokens as fixed reference information that remains fully preserved, while maintaining a sliding attention window over only the most recent 128 output tokens. This compresses the decoder’s KV cache from linear growth to a constant size, enabling single-forward transcription of dozens of pages.
The architecture builds directly on DeepSeek-OCR’s DeepEncoder—a SAM-ViT cascaded with CLIP-ViT that compresses a 1024×1024 page down to roughly 256 visual tokens. But while DeepSeek-OCR solved the input compression problem, Unlimited-OCR solves the output bottleneck: preventing the decoder from being dragged down by an ever-growing KV cache. The result is a 3B-parameter model with only ~570M parameters activated during inference.
2. Benchmark Performance: 93.92% on OmniDocBench v1.6
The numbers speak for themselves. On OmniDocBench v1.6, Unlimited-OCR achieves 93.92% total score, establishing a new SOTA and outperforming DeepSeek-OCR’s 87.01% by over six percentage points. Breaking this down:
| Metric | Unlimited-OCR | DeepSeek-OCR | Improvement |
|–||–|-|
| Text Edit Distance | 0.038 | 0.073 | -48% |
| Formula CDM | 92.61 | 83.37 | +9.24 pts |
| Table TEDS | 90.93 | 84.97 | +5.96 pts |
| Reading Order Edit Distance | 0.045 | — | Stable |
On OmniDocBench v1.5, the model scores 93.23%. Even more impressive: when processing 40+ pages, the edit distance stays below 0.11, and the Distinct-35 metric remains around 97%. Real-world inference speed improves by 12.7% over DeepSeek-OCR, expanding to ~35% faster when output length reaches 6,000 tokens.
3. Deployment Guide: Running Unlimited-OCR Locally
3.1 Quick Start with Transformers (NVIDIA GPUs)
Requirements: Python 3.12.3+ CUDA 12.9 pip install torch==2.10.0 torchvision==0.25.0 transformers==4.57.1 Pillow==12.1.1 einops==0.8.2 addict==2.4.0 pymupdf==1.27.2.2
import torch from transformers import AutoModel, AutoTokenizer model_name = 'baidu/Unlimited-OCR' 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() Single image — two modes: 'gundam' (crop, 640px) or 'base' (full, 1024px) model.infer( tokenizer, prompt='<image>document parsing.', image_file='your_document.jpg', output_path='./output', base_size=1024, image_size=640, crop_mode=True, gundam mode max_length=32768, 32K context window no_repeat_ngram_size=35, ngram_window=128, save_results=True ) Multi-page PDF — automatically uses base mode (1024px) model.infer_multi( tokenizer, prompt='<image>Multi page parsing.', image_files=['page1.png', 'page2.png', 'page3.png'], output_path='./output', image_size=1024, max_length=32768, no_repeat_ngram_size=35, ngram_window=1024, save_results=True )
3.2 Production Deployment with vLLM (OpenAI-Compatible API)
pip install vllm vllm serve "baidu/Unlimited-OCR"
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "baidu/Unlimited-OCR",
"prompt": "<image>document parsing.",
"max_tokens": 4096,
"temperature": 0.1
}'
3.3 SGLang Deployment with Prefill-Aware Sliding Window
Install from PR branch (required for R-SWA support) git clone https://github.com/sgl-project/sglang.git cd sglang git fetch origin pull/29186/head && git checkout FETCH_HEAD uv pip install -e python Launch server with prefill-aware SWA python3 -m sglang.launch_server \ --model-path "baidu/Unlimited-OCR" \ --attention-backend fa3 \ --page-size 1 \ --disable-radix-cache \ --enable-custom-logit-processor \ --host 0.0.0.0 --port 30000
from openai import OpenAI
client = OpenAI(base_url="http://localhost:30000/v1", api_key="EMPTY")
response = client.chat.completions.create(
model="baidu/Unlimited-OCR",
messages=[{
"role": "user",
"content": [
{"type": "text", "text": "document parsing."},
{"type": "image_url", "image_url": {"url": "data:image/png;base64,..."}}
]
}],
max_tokens=4096
)
3.4 Lightweight Deployment with GGUF Quantizations (llama.cpp)
For resource-constrained environments, GGUF quantizations are available:
| Quantization | Bits | Size | Use Case |
|–|||-|
| Q4_K_M | 4 | 1.82 GB | Recommended default — best size/quality trade-off |
| Q5_K_M | 5 | 2.07 GB | Higher quality with modest memory increase |
| Q8_0 | 8 | 2.91 GB | Near-lossless, best quality |
| IQ3_M | 3 | 1.35 GB | Compact, usable when memory is tight |
| IQ2_M | 2 | ~1 GB | Minimum viable, noticeable quality loss |
Note: Requires a DeepSeek-OCR-aware llama.cpp build (PR 17400) — stock llama.cpp will not load these files.
3.5 Apple Silicon Deployment with MLX
pip install mlx-vlm
from mlx_vlm import load, generate
model, processor = load("sahilchachra/unlimited-ocr-mxfp8-mlx")
response = generate(
model, processor,
prompt="<image>document parsing.",
image="path/to/document.jpg",
max_tokens=4096,
verbose=True
)
Benchmarks on Apple M4 Pro (24GB): MXFP8 quantization achieves 205.6 tokens/sec with 4.98GB memory—41% faster and 35% less memory than FP16 baseline.
4. Cost Comparison: Free vs. Pay-Per-Page
| Service | Pricing | Cost for 10,000 Pages |
|||-|
| Unlimited-OCR | $0 (MIT license, runs locally) | $0 |
| Amazon Textract (DetectDocumentText) | ~$0.0015/page | $15 |
| Amazon Textract (AnalyzeDocument) | ~$0.004/page | $40 |
| Google Document AI | ~$0.001/page | $10 |
| AWS Textract AnalyzeExpense | $0.01/page | $100 |
For organizations processing millions of documents annually, the savings are seven figures. But the cost advantage is just the beginning—Unlimited-OCR’s one-shot processing eliminates the engineering overhead of building and maintaining page-splitting pipelines, retry logic, and result stitching.
5. Prompting Guide and Advanced Features
Unlimited-OCR uses the DeepSeek-OCR prompt vocabulary. The base prompt is simply "document parsing."—prefix with `<|grounding|>` to also obtain bounding boxes for recognized text.
Supported image modes (passed via `images_config.image_mode` in SGLang):
tiny,small,base,large, `gundam` (default — crop mode with 640px)- Multiple images supported only for
tiny,small, and `base`Multilingual support: Out-of-the-box support for Chinese and English, handling mixed-language documents seamlessly.
Output format: Clean, structured Markdown—not raw text dumps.
6. Security and Data Privacy Considerations
Running Unlimited-OCR locally means document data never leaves your infrastructure. This is a critical advantage for:
– Healthcare organizations processing PHI (HIPAA compliance)
– Financial institutions handling sensitive client data
– Government agencies with data sovereignty requirements
– Legal firms managing privileged client documents
Unlike cloud APIs where data may be logged, stored, or used for model improvement, local inference gives you complete control over data retention and security posture.
7. Future Roadmap and Limitations
Current limitations:
- Prefill length is still constrained by the 32K context window—as page count increases, visual tokens accumulate
- Not truly “unlimited” in the strictest sense, though 40+ pages is achievable
Planned improvements:
- Extending training context window to 128K
- Exploring prefill pool mechanisms for even longer document handling
What Undercode Say:
- The $0 TCO is the real story. Cloud OCR vendors charge per page because they can. Unlimited-OCR breaks that pricing model permanently—and with MIT licensing, there’s no vendor lock-in or surprise bill at the end of the month.
-
R-SWA is a general-purpose breakthrough. The paper explicitly notes that Reference Sliding Window Attention applies beyond OCR—to ASR, translation, and any long-sequence generation task. This isn’t just an OCR model; it’s a fundamentally new attention mechanism that could reshape how we approach long-context AI.
-
The DeepSeek lineage is telling. Unlimited-OCR builds directly on DeepSeek-OCR, with the technical report referencing DeepSeek over 40 times. This suggests a continuity of talent and thinking—some speculate the core author previously worked at DeepSeek. Either way, it demonstrates that open-source AI innovation is accelerating faster than proprietary alternatives.
-
Enterprise adoption will be rapid. With 14,600 GitHub stars in days, vLLM and SGLang integrations already merged, and Baidu Cloud hosting available, the ecosystem is maturing faster than any open-source OCR project before it. The ms-swift training support means fine-tuning for domain-specific documents is now accessible.
Prediction:
+1 Unlimited-OCR will trigger a wave of commoditization in document processing, forcing AWS, Google, and Azure to either drastically cut prices or release their own open-weight models within 12-18 months.
+1 The R-SWA mechanism will be adopted across multiple modalities—ASR, video understanding, and long-form text generation—becoming a standard attention variant in foundation model architectures.
-1 Organizations currently locked into cloud OCR pipelines face a migration cost that may delay adoption despite the clear TCO advantages, creating a temporary “two-tier” market where large enterprises continue paying while startups and SMBs leapfrog to open-source.
▶️ Related Video (80% Match):
🎯Let’s Practice For Free:
🎓 Live Courses & Certifications:
Join Undercode Academy for Verified Certifications
🚀 Request a Custom Project:
Secure, high-velocity infrastructure and disruptive technological engineering. Contact our engineering team for high-tier development and proprietary systems:
[email protected]
💎 Smart Architecture | 🛡️ Secure by Design | ⭐ Trusted by Thousands
IT/Security Reporter URL:
Reported By: Naresh Joshi – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅


