{"slug": "baidu-releases-unlimited-ocr-a-3b-model-that-keeps-the-kv-cache-flat-for-long", "title": "Baidu Releases Unlimited OCR, a 3B Model That Keeps the KV Cache Flat for Long-Document Parsing", "summary": "Baidu released Unlimited OCR, a 3B-parameter Mixture-of-Experts model that uses Reference Sliding Window Attention to keep KV cache constant, enabling efficient parsing of dozens of pages in one forward pass. The model scores 93.23 on OmniDocBench v1.5, beating the DeepSeek OCR baseline by 6.22 points, and achieves 12.7% higher throughput. This innovation addresses memory and latency bottlenecks in long-document OCR, making multi-page parsing practical.", "body_md": "Most end-to-end OCR models slow down as output grows. Each generated token adds to the KV cache. Memory rises and generation drags. Parsing dozens of pages becomes impractical. Baidu’s ** Unlimited OCR **addresses this directly. It swaps the decoder’s attention for a design that keeps memory constant.\n\n**TL;DR**\n\n- Unlimited OCR is a 3B-parameter Mixture-of-Experts model, with only 500M parameters active.\n- It replaces decoder attention with Reference Sliding Window Attention (R-SWA), keeping the KV cache constant.\n- The model parses dozens of pages in one forward pass under a 32K maximum length.\n- It scores 93.23 on OmniDocBench v1.5, beating the DeepSeek OCR baseline by 6.22 points.\n- It builds on DeepSeek OCR via continue-training, not a from-scratch run.\n\n**What is Unlimited OCR?**\n\nUnlimited OCR takes DeepSeek OCR as its baseline. It keeps the DeepEncoder and the Mixture-of-Experts decoder. The MoE design holds 3B total parameters but activates only 500M at inference.\n\nThe DeepEncoder is the compression engine. It cascades a SAM-ViT under window attention with a CLIP-ViT under global attention. At the bridge, it applies 16× token compression. A 1024×1024 PDF image becomes just 256 visual tokens. Fewer input tokens mean a smaller prefill.\n\nDeepEncoder natively supports five resolution modes, and Unlimited OCR keeps two. ‘Base’ mode runs at 1024×1024 for multi-page work. ‘Gundam’ mode uses dynamic resolution for single pages.\n\n**How R-SWA Keeps the Cache Constant**\n\nThe contribution is Reference Sliding Window Attention. Standard Multi-Head Attention stores a key and value for every token. As output length T grows, the cache grows with it. The size is CMHA(T) = Lm + T. Memory and latency climb without bound.\n\nR-SWA breaks that link. Each generated token attends to all reference tokens, meaning the visual tokens and the prompt. It also attends to the preceding n output tokens, where n defaults to 128. Everything older is evicted. The cache becomes a fixed queue of size m + n.\n\nThe size is CR-SWA(T) = Lm + min(n, T) ≤ Lm + n. It is bounded by a constant. As T grows far beyond n, the cache ratio trends toward zero. So memory stays flat and per-step latency stays flat.\n\nThe research team compare this to soft forgetting. A person copying a book glances at the source and the last few words. They do not re-read everything transcribed so far. Visual tokens never undergo state updates. That avoids the progressive blurring seen in linear attention. The interactive simulator below lets you vary T and watch both caches respond.\n\n**How It Was Trained**\n\nUnlimited OCR was not trained from scratch. The research team continue-trained from the DeepSeek OCR checkpoint for 4,000 steps. They froze the DeepEncoder and trained only the decoder. Training used about 2M document samples on 8×16 A800 GPUs. The 9:1 split favored single-page data, with multi-page samples built by concatenation.\n\n**Benchmark**\n\nThe research team evaluates on OmniDocBench v1.5 and v1.6. The main finding/stat is 93.23 overall on v1.5. That beats the DeepSeek OCR baseline by 6.22 points. The table below compares the three related models. All three share the same 3B-A0.5B size.\n\n| Metric (v1.5) | DeepSeek-OCR | DeepSeek-OCR 2 | Unlimited-OCR |\n|---|---|---|---|\n| Overall ↑ | 87.01 | 89.17 | 93.23 |\n| Text Edit ↓ | 0.073 | 0.049 | 0.038 |\n| Formula CDM ↑ | 83.37 | 86.85 | 92.61 |\n| Table TEDS ↑ | 84.97 | 85.60 | 90.93 |\n| Read-order Edit ↓ | 0.086 | 0.060 | 0.045 |\n\nOn OmniDocBench v1.6, Unlimited OCR reaches 93.92 overall. That is the top score in the research paper’s v1.6 comparison. Gains hold across text, formula, and table recognition.\n\nSpeed improves too. On OmniDocBench in Base mode, Unlimited OCR hits 5,580 TPS against DeepSeek OCR’s 4,951 TPS. That is a 12.7% increase. The gap widens with longer output. At a 6,000-token output ceiling, DeepSeek OCR lags Unlimited OCR by 35%.\n\n**Where It Fits: Use Cases**\n\nThe constant cache suits workloads that page-by-page systems handle poorly.\n\n**Whole-book transcription**: Feed 40+ pages and parse them in one continuous pass. The reported edit distance stays below 0.11 at 40+ pages, with 96.90% Distinct-35.**Document parsing pipelines**: Extract text, tables, formulas, and reading order in a single forward pass.** High-throughput batch parsing**: The included`infer.py`\n\nlaunches an SGLang server and sends concurrent requests over a folder or PDF.**Beyond OCR**: The research team call R-SWA a general parsing attention, applicable to ASR and translation.\n\n**Running It: Minimal Code**\n\nThe Transformers path needs `trust_remote_code=True`\n\nand a CUDA GPU. Single-image parsing uses Gundam mode.\n\n``` python\nimport torch\nfrom transformers import AutoModel, AutoTokenizer\n\nname = \"baidu/Unlimited-OCR\"\ntokenizer = AutoTokenizer.from_pretrained(name, trust_remote_code=True)\nmodel = AutoModel.from_pretrained(\n    name, trust_remote_code=True, use_safetensors=True,\n    torch_dtype=torch.bfloat16,\n).eval().cuda()\n\nmodel.infer(\n    tokenizer,\n    prompt=\"<image>document parsing.\",\n    image_file=\"your_image.jpg\",\n    output_path=\"your/output/dir\",\n    base_size=1024, image_size=640, crop_mode=True,   # gundam mode\n    max_length=32768,\n    no_repeat_ngram_size=35, ngram_window=128,\n    save_results=True,\n)\n```\n\nMulti-page and PDF parsing call `model.infer_multi`\n\nin Base mode at `image_size=1024`\n\n. For production throughput, SGLang serves an OpenAI-compatible API using the `fa3`\n\nattention backend.\n\n**Strengths and Weaknesses**\n\n**Strengths:**\n\n- Constant KV cache holds memory and latency flat across long outputs.\n- End-to-end SOTA scores on OmniDocBench v1.5 and v1.6.\n- Only 500M active parameters keep inference cheap.\n- MIT license, open weights, and dual Transformers plus SGLang support.\n- R-SWA gains arrive without a measured accuracy cost on single pages.\n\n**Weaknesses:**\n\n- Parsing is not truly unlimited; a 32K context still bounds the prefill.\n- Long prefills grow as page count accumulates, despite heavy compression.\n- Multi-page runs use Base mode only, so very small text can be missed.\n- ASR and translation transfer remains future work, not a shipped result.\n\nCheck out the ** Paper**,\n\n**and**\n\n[Repo](https://github.com/baidu/Unlimited-OCR)**.**\n\n[Model Weights](https://huggingface.co/baidu/Unlimited-OCR)**Also, feel free to follow us on**\n\n**and don’t forget to join our**[Twitter](https://x.com/intent/follow?screen_name=marktechpost)\n\n**and Subscribe to**\n\n[150k+ML SubReddit](https://www.reddit.com/r/machinelearningnews/)**. Wait! are you on telegram?**\n\n[our Newsletter](https://www.aidevsignals.com/)\n\n[now you can join us on telegram as well.](https://t.me/machinelearningresearchnews)Need to partner with us for promoting your GitHub Repo OR Hugging Face Page OR Product Release OR Webinar etc.? [Connect with us](https://forms.gle/wbash1wF6efRj8G58)", "url": "https://wpnews.pro/news/baidu-releases-unlimited-ocr-a-3b-model-that-keeps-the-kv-cache-flat-for-long", "canonical_source": "https://www.marktechpost.com/2026/06/24/baidu-releases-unlimited-ocr-a-3b-model-that-keeps-the-kv-cache-flat-for-long-document-parsing/", "published_at": "2026-06-25 05:39:53+00:00", "updated_at": "2026-06-25 17:18:56.464988+00:00", "lang": "en", "topics": ["artificial-intelligence", "machine-learning", "computer-vision", "ai-products", "ai-research"], "entities": ["Baidu", "DeepSeek", "Unlimited OCR", "DeepSeek OCR", "OmniDocBench", "SAM-ViT", "CLIP-ViT", "A800"], "alternates": {"html": "https://wpnews.pro/news/baidu-releases-unlimited-ocr-a-3b-model-that-keeps-the-kv-cache-flat-for-long", "markdown": "https://wpnews.pro/news/baidu-releases-unlimited-ocr-a-3b-model-that-keeps-the-kv-cache-flat-for-long.md", "text": "https://wpnews.pro/news/baidu-releases-unlimited-ocr-a-3b-model-that-keeps-the-kv-cache-flat-for-long.txt", "jsonld": "https://wpnews.pro/news/baidu-releases-unlimited-ocr-a-3b-model-that-keeps-the-kv-cache-flat-for-long.jsonld"}}