Unlimited-OCR: Baidu's Free Open-Source Model Parses Entire PDFs in One Shot
If you’re still uploading massive PDF files to GPT-4 or Claude and watching your token bill climb, Baidu just handed you a way out.
Unlimited-OCR landed this week — a fully open-source OCR model that can transcribe dozens of pages in a single forward pass. No chunking. No API costs. No accumulated memory explosion.
The Problem It Solves
Traditional LLM-based OCR has a fundamental scaling problem. As output sequences grow longer, the KV cache balloons, memory consumption spikes, and generation slows to a crawl. This is why most document processing pipelines chunk PDFs into individual pages and process them separately.
Baidu’s insight: humans don’t get slower when copying long documents. Why should models?
Reference Sliding Window Attention (R-SWA)
The core innovation is Reference Sliding Window Attention — a new attention mechanism that maintains a constant KV cache throughout the entire decoding process, regardless of output length.
By combining DeepSeek OCR’s high-compression encoder with this constant-memory decoder, Unlimited-OCR can process entire multi-page documents in a single 32K context window.
From the paper:
Taking DeepSeek OCR as the baseline, we replace all attention layers in the decoder with our proposed Reference Sliding Window Attention (R-SWA), which reduces attention computation costs while maintaining a constant KV cache throughout the entire decoding process.
Quick Start
The model runs on HuggingFace Transformers with a standard NVIDIA GPU setup:
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,
torch_dtype=torch.bfloat16,
).eval().cuda()
# Single image
model.infer(
tokenizer,
prompt='<image>document parsing.',
image_file='contract.jpg',
output_path='./output',
max_length=32768,
)
# Multi-page PDF
model.infer_multi(
tokenizer,
prompt='<image>Multi page parsing.',
image_files=['page1.png', 'page2.png', 'page3.png'],
output_path='./output',
max_length=32768,
)
For PDFs, convert pages to images first using PyMuPDF:
import fitz # PyMuPDF
def pdf_to_images(pdf_path, dpi=300):
doc = fitz.open(pdf_path)
mat = fitz.Matrix(dpi / 72, dpi / 72)
paths = []
for i, page in enumerate(doc):
out = f'page_{i+1:04d}.png'
page.get_pixmap(matrix=mat).save(out)
paths.append(out)
return paths
model.infer_multi(
tokenizer,
prompt='<image>Multi page parsing.',
image_files=pdf_to_images('annual_report.pdf'),
output_path='./output',
)
SGLang Server for Production
For production workloads, run it as an OpenAI-compatible API server:
python -m sglang.launch_server \
--model baidu/Unlimited-OCR \
--served-model-name Unlimited-OCR \
--context-length 32768 \
--host 0.0.0.0 \
--port 10000
Then hit it with standard OpenAI SDK calls.
Why This Matters
The implications for document processing pipelines are significant:
- No more chunking logic — Process entire documents without splitting and reassembling
- Constant memory — Memory usage doesn’t explode with document length
- Zero API costs — Run it locally on your own hardware
- MIT license — Use it commercially, modify it, redistribute it
For anyone building RAG systems, document extraction pipelines, or enterprise search — this removes a major pain point.
The Lineage
Unlimited-OCR builds on DeepSeek-OCR’s architecture and explicitly credits both DeepSeek-OCR and PaddleOCR in its acknowledgments. It’s part of Baidu’s broader PaddlePaddle ecosystem, which has been pushing open-source document AI for years.
Links
- GitHub: github.com/baidu/Unlimited-OCR
- HuggingFace: huggingface.co/baidu/Unlimited-OCR
- Live Demo: HuggingFace Spaces
- Paper: arXiv:2606.23050
The “one-shot long-horizon parsing” era is here. Your PDF processing pipeline just got a lot simpler.