GitHub - baidu/Unlimited-OCR: Unlimited OCR Works: Welcome the Era of One-shot Long-horizon Parsing.

Open original

Unlimited-OCR is an open-source OCR framework from Baidu that extends Deepseek-OCR to handle single images, multi-page documents, and PDFs. It provides Hugging Face transformer models, PyMuPDF conversion, and an OpenAI-compatible SGLang server for streaming or batch inference. The repo includes setup instructions, example scripts, and configuration for GPU-accelerated parsing.

  • Extends Deepseek-OCR to handle not just single images but multi-page documents and PDFs, with a 32,768-token context window for long-horizon parsing
  • Includes an OpenAI-compatible SGLang server supporting streaming inference, plus a batch script that auto-launches the server and processes image/PDF folders concurrently
  • PDF handling pipeline renders pages at 300 DPI via PyMuPDF, then feeds them through model.infer_multi with a no-repeat-ngram constraint to avoid repetitive output
  • Offers two preset image configs ("gundam" with crop mode at 1024/640, "base" at fixed 1024x1024) for trading off resolution and processing mode

Unlimited-OCR builds on Deepseek-OCR to handle both single images and multi-page documents with a context window up to 32,768 tokens. The repo ships with a Hugging Face demo, an arXiv paper (2606.23050), and a ModelScope release. Out of the box it supports two image configs: “gundam” (base_size=1024, image_size=640, crop_mode=True) and “base” (1024×1024, no crop). You grab the model via transformers (torch==2.10.0, torchvision==0.25.0, transformers==4.57.1, Pillow, matplotlib, einops, addict, easydict, pymupdf, psutil) and run model.infer or model.infer_multi for images or PDF-converted pages. For PDF conversion, they use PyMuPDF to render pages at 300 DPI into PNGs, then feed those into model.infer_multi with image_size=1024 and a no_repeat_ngram constraint (35 ngrams, window up to 1,024). They also provide an SGLang-based server that wraps the model behind an OpenAI-style streaming chat API. After installing a local SGLang wheel, kernels==0.11.7, pymupdf, you launch with python -m sglang.launch_server specifying model name Unlimited-OCR, attention-backend fa3, page-size 1, static memory fraction 0.8, context-length 32768, custom logit processor enabled, and host/port. The client code builds requests by base64-encoding images and sending them alongside text prompts like “<image>document parsing.” You can specify image_mode (“gundam” or “base”) and ngram_window. The server streams token deltas until “[DONE]”. For batch jobs there’s infer.py: point it at an image directory or a PDF, set concurrency (e.g. 8), choose image_mode, and it spins up the SGLang server automatically, processes pages concurrently, and writes results to your output folder. They credit Deepseek-OCR, Deepseek-OCR-2, and PaddleOCR for inspiration and models.

Ask about this article