Unlimited-OCR: Parse 100-Page PDFs as One Continuous Document
Unlimited-OCR
| What it is | A 3B-parameter OCR model that parses multi-page documents as one continuous whole |
| Platform | Linux, macOS, Windows (NVIDIA GPU required) |
| Price | Free, open source (MIT) |
| Link | github.com/baidu/Unlimited-OCR |
Traditional OCR has a blind spot: it chops documents page by page. Tables that span two pages get sliced in half. Reading order breaks between pages. Headers and footers leak into the content stream. You’ve either manually stitched pages back together or paid for OCR SaaS that handles it server-side.
Unlimited-OCR solves this at the model level. It uses a mechanism called R-SWA (Recurrent Sliding Window Attention) to parse dozens of pages as a single sequence, with a constant KV cache during decoding; no matter how thick the document, VRAM usage stays flat.
R-SWA is the key insight. Standard attention scales quadratically with sequence length, which is why every other OCR tool caps you at a page or two. R-SWA slides a fixed-size attention window across the document while maintaining a recurrent state, so a 100-page PDF costs the same VRAM as a 2-page one. The KV cache remains constant during autoregressive decoding.
The model is 3B parameters and runs on a single consumer GPU. You don’t need an A100 cluster. I ran it on a 24GB RTX 4090 and parsed a 47-page academic paper in one shot. It preserved tables, footnotes, multi-column layout, all in correct reading order. The output was a single clean markdown block instead of 47 separate chunks to reassemble.
It handles everything traditional OCR chokes on. Page-spanning tables, mixed columns, footnotes that reference content on different pages, documents where the reading order jumps across page boundaries. Because the model sees the whole document context, it understands that a table row that starts on page 3 and finishes on page 4 belongs together.
The honest caveat: you need an NVIDIA GPU with at least 8GB VRAM, and the first inference is slow because the model weights (roughly 6GB) need to load. Inference speed is about 1-2 seconds per page on a 4090. It also currently supports document OCR only; it’s not a general scene-text reader.
Worth your time if: you regularly OCR multi-page PDFs (papers, contracts, scans) and are tired of manually stitching page outputs or paying per-page SaaS fees.
Install & first run
pip install torch torchvision transformers Pillow pymupdf einopsRun inference on a single image:
from transformers import AutoModel, AutoTokenizer
model = AutoModel.from_pretrained(
'baidu/Unlimited-OCR', trust_remote_code=True,
torch_dtype=torch.bfloat16
).eval().cuda()
tokenizer = AutoTokenizer.from_pretrained('baidu/Unlimited-OCR', trust_remote_code=True)
model.infer(tokenizer, prompt='<image>document parsing.',
image_file='your_image.jpg', output_path='./output',
base_size=1024, image_size=640, crop_mode=True)For PDFs, convert pages to images with PyMuPDF and use infer_multi:
import fitz
doc = fitz.open('your_doc.pdf')
for i, page in enumerate(doc):
page.get_pixmap(matrix=fitz.Matrix(300/72, 300/72)).save(f'page_{i:04d}.png')
model.infer_multi(tokenizer, prompt='<image>Multi page parsing.',
image_files=[f'page_{i:04d}.png' for i in range(len(doc))],
output_path='./output', image_size=1024, max_length=32768)The model also supports vLLM and SGLang for production deployments. See the GitHub README for server setup, Docker images, and batch inference scripts.
Related TMFNK Content
- Document OCR & Parsing: Docling, dots.ocr, and Alternatives The previous generation of open-source OCR tools; Docling is useful for single-page work but none stitch multi-page documents the way Unlimited-OCR does.
- LiteParse: Fast Local PDF Parsing with OCR and Bounding Boxes Another local PDF parser with OCR, useful when you need bounding box coordinates alongside extracted text.
- ScribeOCR: Best Free Web App for OCR, Text Recognition & Document Digitization A free web OCR option that requires no local GPU; simpler setup, but no multi-page context.
Crepi il lupo!