{
  "hf_id": "baidu/Unlimited-OCR",
  "meta": {
    "title": "Unlimited-OCR",
    "slug": "unlimited-ocr",
    "provider": "Ernie (Baidu)",
    "description": "Baidu's state-of-the-art document-parsing model with Reference Sliding Window Attention (R-SWA), optimized for full-page OCR and markdown generation.",
    "date_added": "2026-06-28",
    "date_updated": "2026-06-28",
    "tasks": [
      "multimodal"
    ],
    "performance_headline": "One-shot long-horizon document parsing to markdown",
    "related_recipes": [
      "deepseek-ai/DeepSeek-OCR"
    ]
  },
  "recommended_command": {
    "hardware": "h200",
    "strategy": "single_node_tp",
    "variant": "default",
    "node_count": 1,
    "deploy_type": "single_node",
    "env": {},
    "docker_image": "vllm/vllm-openai:unlimited-ocr",
    "command": "vllm serve baidu/Unlimited-OCR \\\n  --trust-remote-code \\\n  --logits_processors vllm.model_executor.models.unlimited_ocr:NGramPerReqLogitsProcessor \\\n  --no-enable-prefix-caching \\\n  --mm-processor-cache-gb 0 \\\n  --tensor-parallel-size 1",
    "argv": [
      "vllm",
      "serve",
      "baidu/Unlimited-OCR",
      "--trust-remote-code",
      "--logits_processors",
      "vllm.model_executor.models.unlimited_ocr:NGramPerReqLogitsProcessor",
      "--no-enable-prefix-caching",
      "--mm-processor-cache-gb",
      "0",
      "--tensor-parallel-size",
      "1"
    ],
    "docker_command": "docker run --gpus all \\\n  --privileged --ipc=host -p 8000:8000 \\\n  -v ~/.cache/huggingface:/root/.cache/huggingface \\\n  vllm/vllm-openai:unlimited-ocr baidu/Unlimited-OCR \\\n  --trust-remote-code \\\n  --logits_processors vllm.model_executor.models.unlimited_ocr:NGramPerReqLogitsProcessor \\\n  --no-enable-prefix-caching \\\n  --mm-processor-cache-gb 0 \\\n  --tensor-parallel-size 1",
    "docker_argv": [
      "docker",
      "run",
      "--gpus",
      "all",
      "--privileged",
      "--ipc=host",
      "-p",
      "8000:8000",
      "-v",
      "~/.cache/huggingface:/root/.cache/huggingface",
      "vllm/vllm-openai:unlimited-ocr",
      "baidu/Unlimited-OCR",
      "--trust-remote-code",
      "--logits_processors",
      "vllm.model_executor.models.unlimited_ocr:NGramPerReqLogitsProcessor",
      "--no-enable-prefix-caching",
      "--mm-processor-cache-gb",
      "0",
      "--tensor-parallel-size",
      "1"
    ],
    "strategy_spec": {
      "name": "single_node_tp",
      "deploy_type": "single_node",
      "display_name": "Tensor Parallel",
      "short_label": "TP",
      "orientation": "latency",
      "description": "Single-node tensor parallel. Splits the model across all local GPUs. TP size is set to the GPU count at deploy time. The simplest multi-GPU strategy — works for all model architectures.\n",
      "hardware_match": {
        "min_gpus": 1,
        "max_gpus": 8,
        "multi_node": false
      },
      "vllm_args": [],
      "parallel_flag": "--tensor-parallel-size"
    },
    "hardware_profile": {
      "brand": "NVIDIA",
      "generation": "hopper",
      "compute_arch": "sm90",
      "display_name": "H200",
      "description": "NVIDIA H200 SXM 141 GB HBM3e · 8-GPU HGX node",
      "gpu_count": 8,
      "vram_gb": 1128,
      "multi_node": false
    },
    "alternatives": {
      "multi_node_tp": "/baidu/Unlimited-OCR/strategies/multi_node_tp.json",
      "kv_store_centralized_mooncake": "/baidu/Unlimited-OCR/strategies/kv_store_centralized_mooncake.json",
      "kv_store_distributed_mooncake": "/baidu/Unlimited-OCR/strategies/kv_store_distributed_mooncake.json"
    },
    "by_hardware": {
      "h200": "/baidu/Unlimited-OCR/hw/h200.json",
      "h100": "/baidu/Unlimited-OCR/hw/h100.json",
      "b200": "/baidu/Unlimited-OCR/hw/b200.json",
      "gb200": "/baidu/Unlimited-OCR/hw/gb200.json",
      "b300": "/baidu/Unlimited-OCR/hw/b300.json",
      "gb300": "/baidu/Unlimited-OCR/hw/gb300.json",
      "mi300x": "/baidu/Unlimited-OCR/hw/mi300x.json",
      "mi325x": "/baidu/Unlimited-OCR/hw/mi325x.json",
      "mi350x": "/baidu/Unlimited-OCR/hw/mi350x.json",
      "mi355x": "/baidu/Unlimited-OCR/hw/mi355x.json"
    }
  },
  "model": {
    "model_id": "baidu/Unlimited-OCR",
    "min_vllm_version": "0.25.0",
    "docker_image": "vllm/vllm-openai:unlimited-ocr",
    "architecture": "dense",
    "parameter_count": "3B",
    "active_parameters": "3B",
    "context_length": 32768,
    "base_args": [
      "--trust-remote-code",
      "--logits_processors",
      "vllm.model_executor.models.unlimited_ocr:NGramPerReqLogitsProcessor",
      "--no-enable-prefix-caching",
      "--mm-processor-cache-gb",
      "0"
    ],
    "base_env": {},
    "install": {
      "pip": {
        "command": "uv venv\nsource .venv/bin/activate\nuv pip install -U vllm --torch-backend auto",
        "note": "Unlimited-OCR (UnlimitedOCRForCausalLM) is supported since vLLM v0.25.0."
      },
      "docker": {
        "command": "docker pull vllm/vllm-openai:unlimited-ocr"
      }
    }
  },
  "features": {
    "encoder_parallel": {
      "description": "Run the vision encoder in data-parallel mode — avoids TP comm overhead on the small encoder.",
      "args": [
        "--mm-encoder-tp-mode",
        "data"
      ]
    }
  },
  "opt_in_features": [
    "encoder_parallel"
  ],
  "variants": {
    "default": {
      "precision": "bf16",
      "vram_minimum_gb": 8,
      "description": "Full precision BF16 (~3B params)"
    }
  },
  "hardware_overrides": {},
  "guide": "## Overview\n\n[Unlimited-OCR](https://huggingface.co/baidu/Unlimited-OCR) is Baidu's\nDeepSeek-OCR-lineage document-parsing model. It shares the DeepSeek-OCR\n*gundam* vision stack (SAM-ViT-B + CLIP-L DeepEncoder, `base_size=1024` /\n`image_size=640` / crop) and ships with the same n-gram logits processor for\nhigh-quality, repetition-free document → markdown generation.\n\n## Prerequisites\n\n- **Hardware**: a single GPU with >=8 GB VRAM is enough for BF16 inference.\n- **vLLM**: served from the dedicated release image (the architecture is not yet\n  in a stable pip wheel). Pull the image shown in the Install → Docker tab.\n\n## Serving recipe (required)\n\nThe model has **no chat template** and is trained for a specific prompt/decode\nrecipe — without it the model returns empty output. The required pieces:\n\n- register the no-repeat-ngram logits processor on the server:\n  `--logits_processors vllm.model_executor.models.unlimited_ocr:NGramPerReqLogitsProcessor`\n- prompt text must begin with a literal `<image>` (e.g. `<image>document parsing.`)\n- `skip_special_tokens=False`\n- pass the processor args per request: `ngram_size=35`, `window_size=128`\n  (use `window_size=1024` for multi-page / PDF input)\n\n## Client Usage\n\n### Online OCR serving\n\n```bash\ndocker run --rm --gpus all --network host --ipc host \\\n  vllm/vllm-openai:unlimited-ocr \\\n  baidu/Unlimited-OCR \\\n  --trust-remote-code \\\n  --logits_processors vllm.model_executor.models.unlimited_ocr:NGramPerReqLogitsProcessor \\\n  --no-enable-prefix-caching \\\n  --mm-processor-cache-gb 0\n```\n\n```python\nimport time\nfrom openai import OpenAI\n\nclient = OpenAI(api_key=\"EMPTY\", base_url=\"http://localhost:8000/v1\", timeout=3600)\n\nmessages = [\n    {\n        \"role\": \"user\",\n        \"content\": [\n            {\"type\": \"text\", \"text\": \"<image>document parsing.\"},\n            {\"type\": \"image_url\", \"image_url\": {\"url\": \"https://huggingface.co/baidu/Unlimited-OCR/resolve/main/assets/baidu.png\"}},\n        ],\n    }\n]\n\nstart = time.time()\nresponse = client.chat.completions.create(\n    model=\"baidu/Unlimited-OCR\",\n    messages=messages,\n    max_tokens=8192,\n    temperature=0.0,\n    extra_body={\n        \"skip_special_tokens\": False,\n        \"vllm_xargs\": {\"ngram_size\": 35, \"window_size\": 128},\n    },\n)\nprint(f\"Response costs: {time.time() - start:.2f}s\")\nprint(f\"Generated text: {response.choices[0].message.content}\")\n```\n\nThe raw output carries `<|ref|>…<|/ref|>` / `<|det|>…<|/det|>` grounding tokens;\nunwrap the `<|ref|>` text and drop the `<|det|>` coordinate boxes to get clean markdown.\n\n## Troubleshooting / Configuration Tips\n\n- **The custom logits processor is required** — without it long documents loop on\n  `<|det|>` coordinate tokens.\n- Empty output almost always means the prompt is missing the literal `<image>`\n  prefix or `skip_special_tokens` was left `True`.\n- OCR tasks don't benefit from prefix caching / image reuse, so prefix caching and\n  the mm-processor cache are disabled in the recipe.\n- Single-image input uses gundam (crop) mode; multi-image requests automatically\n  fall back to non-crop (base) mode — use `window_size=1024` for those.\n\n## References\n\n- [Unlimited-OCR on Hugging Face](https://huggingface.co/baidu/Unlimited-OCR)\n- [vLLM multimodal inputs guide](https://docs.vllm.ai/en/latest/features/multimodal_inputs.html#offline-inference)\n",
  "source": {
    "source": "vllm",
    "repo": "vllm-project/vllm",
    "ref": "main",
    "sha": "389ffebe555705c85337025d5df108d0384d365e",
    "path": "recipes/models/baidu/Unlimited-OCR.yaml",
    "edit_url": "https://github.com/vllm-project/vllm/edit/main/recipes/models/baidu/Unlimited-OCR.yaml",
    "overlays": []
  }
}