Unlimited-OCR: Parsing a 40-Page PDF in One Pass Without Your GPU Melting Baidu released Unlimited-OCR, an MIT-licensed model that can parse dozens of pages of a PDF in a single forward pass without the GPU memory growth typical of transformer-based OCR. The model uses a novel Reference Sliding Window Attention (R-SWA) mechanism that keeps the KV cache at a fixed size, enabling constant memory and latency regardless of output length. The architecture combines DeepSeek-OCR's DeepEncoder with an MoE decoder and requires an NVIDIA GPU with at least 12 GB of VRAM. If you have ever built a document-parsing pipeline, you know the ritual. Split the PDF into pages. Run each page through the OCR model. Stitch the outputs back together. Then write a pile of glue code to fix the tables that got cut in half at a page boundary, and the heading that lost its section, and the footnote that ended up orphaned three pages away from its reference. Baidu's Unlimited-OCR https://github.com/baidu/Unlimited-OCR is a bet that you should not have to do any of that. It parses dozens of pages in a single forward pass, and it is MIT licensed. This post covers what the model actually does differently, and then three concrete ways to get it running: a quick Transformers script, an SGLang server for real throughput, and a Docker image if you would rather not touch a Python environment at all. Standard transformer decoding has a cost that most OCR benchmarks quietly hide: the KV cache grows with every token you generate. The KV cache is the model's short-term memory. Every token the model produces gets appended to it so future tokens can attend backwards. For a chatbot writing three paragraphs, this is fine. For an OCR model transcribing a 40-page technical manual into 30,000 tokens of Markdown, it is not. Memory climbs, attention cost climbs with it, and generation gets slower the longer it runs. Somewhere around page eight your throughput graph stops looking like a line and starts looking like a cliff. The industry workaround has been chunking. Process one page, dump the cache, process the next page, and accept that the model has no idea what came before. Unlimited-OCR attacks the cache growth directly. The team replaced every attention layer in the decoder with something they call Reference Sliding Window Attention R-SWA . The intuition is close to how a human copy-typist works. You do not hold every word you have already typed in your head. You hold the last sentence or two, and you keep glancing back at the source document. R-SWA does the same thing: the decoder keeps a fixed-size window of recently generated tokens, but it retains permanent access to the original image tokens. The KV cache is implemented as a queue with a fixed capacity, so when a new token arrives, the oldest one in the window gets evicted. The result is a cache size that is constant rather than growing. Memory and per-token latency stay flat whether you are on token 500 or token 30,000. The architecture is DeepSeek-OCR's DeepEncoder SAM-ViT-B plus CLIP-L feeding an MoE decoder. The encoder's aggressive visual token compression is what keeps the image side of the cache small enough for the whole thing to work. One thing the paper flags that is easy to miss: R-SWA is not OCR-specific. It is a general-purpose attention mechanism for any long-horizon transcription-shaped task, ASR included. You need an NVIDIA GPU. There is no CPU or Apple Silicon path in the official repo. The weights are bfloat16, so roughly 6 GB just to load the model, before activations and image tokens. A 12 GB card is a sane floor for single-image work; for multi-page runs at 32K context you will want more headroom. The maintainers tested on Python 3.12.3 with CUDA 12.9. If you just want to see output before committing to any of this, there is a Hugging Face Space https://huggingface.co/spaces/baidu/Unlimited-OCR you can drop a file into. This is the fastest way to a working result. Set up the environment: python -m venv .venv source .venv/bin/activate pip install torch==2.10.0 torchvision==0.25.0 transformers==4.57.1 pip install Pillow==12.1.1 matplotlib==3.10.8 einops==0.8.2 pip install addict==2.4.0 easydict==1.13 pymupdf==1.27.2.2 psutil==7.2.2 Pin these versions. The model ships custom modeling code via trust remote code , and that code is written against these specific releases. Version drift here produces confusing import errors rather than clean failures. Now a single image: python 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, model = model.eval .cuda model.infer tokenizer, prompt='