Model reference · open weights
Unlimited-OCR-2 is an open-weight language model from Baidu. Unlimited-OCR-2 (BF16) weighs 6.7 GB; the smallest configuration that runs it is RTX 3060 12 GB.
For self-hosting, compare this build's requirements below with the GPU you plan to rent.
Summary of the baidu/Unlimited-OCR-2 model card, 2026-10-27
What it is
| Released by | Baidu |
|---|---|
| Released | 2026-10-26 |
| Parameters | 3.3B |
| VRAM | 6.7 GB for the weights |
What it runs on
| Card | Requests at once | Context max | Memory | |
|---|---|---|---|---|
| 8K each | 32K each | |||
| RTX 3060 12 GB | 5 | 1 | 42K | 11.6 GB |
| RTX 4060 Ti 16 GB | 12 | 3 | 102K | 15.4 GB |
| RTX 3090 24 GB | 28 | 7 | all 128K | 23.4 GB |
| RTX 4090 24 GB | 28 | 7 | all 128K | 23.4 GB |
| RTX 5090 32 GB | 43 | 10 | all 128K | 31.0 GB |
| L40S 48 GB | 69 | 17 | all 128K | 44.0 GB |
| A100 80 GB | 137 | 34 | all 128K | 78.2 GB |
| H100 80 GB | 127 | 31 | all 128K | 78.1 GB |
| RTX PRO 6000 Blackwell 96 GB | 159 | 39 | all 128K | 93.8 GB |
| DGX Spark (GB10) 128 GB unified | 186 | 46 | all 128K | 107 GB |
| H200 141 GB | 246 | 61 | all 128K | 138 GB |
| B200 180 GB | 319 | 79 | all 128K | 176 GB |
| 2× RTX 3060 12 GB tensor parallel | 23 | 5 | all 128K | 11.6 GB a card |
| Requests at once | 8K tokens each | 32K tokens each |
|---|---|---|
| 1 | 9.4 GB | 10.9 GB |
| 5 | 11.5 GB | 19.0 GB |
| 8 | 13.0 GB | 25.0 GB |
| 16 | 17.0 GB | 41.1 GB |
| 32 | 25.0 GB | 73.4 GB |
| 64 | 41.1 GB | 138 GB |
One card, with vLLM's small-card settings.
From the model card
Unlimited OCR 2 supports Transformers (native, for quick tests) and SGLang (recommended for serving).
Tested with Python 3.10, torch==2.13.0, transformers==4.52.1, huggingface-hub==0.36.0, tokenizers==0.21.4, on an NVIDIA A800-80GB:
pip install torch==2.13.0 torchvision pillow transformers==4.52.1 huggingface-hub==0.36.0 \
tokenizers==0.21.4 addict==2.4.0 einops==0.8.2 easydict==1.13
Load the model once:
import torch
from transformers import AutoModel, AutoTokenizer
model_name = "baidu/Unlimited-OCR-2"
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).eval().cuda()
Multi-page inference (infer_multi). All pages of a document are parsed in one request, so the model can use cross-page context. Pass the page images in page order:
pages = [f"your_doc/page_{i}.jpg" for i in range(1, 8)]
text, num_tokens = model.infer_multi(tokenizer, image_files=pages,
output_path="output/multi", save_results=True)
The prompt is built automatically as "" * num_pages + "Multi page parsing.", and each page is encoded as one global view (base mode). The output contains one `` per input page, in the same order as image_files.
Single-page inference (infer). A single page is encoded with dynamic tiling (gundam mode) by default:
text = model.infer(tokenizer, image_file="your_doc/page_1.jpg",
output_path="output/single", save_results=True)
Set up the environment (uv-managed virtualenv, Python 3.10) and install the customized SGLang wheel
sglang-0.5.20.dev10+g8d62f5fb9c-py3-none-any.whl, plus PyMuPDF for PDF-to-image conversion:
uv venv --python 3.10
source .venv/bin/activate
uv pip install wheel/sglang-0.5.20.dev10+g8d62f5fb9c-py3-none-any.whl
uv pip install pymupdf==1.27.2.2
uv pip install fastokens==0.3.2
Start the SGLang server:
# Page-window scheduling for very long documents (the KV tail of the previous window is reused).
export SGLANG_UOCR_EANABLE_DOC_LIMIT=1 # 1 = enable, 0 = whole document in one window
export SGLANG_UOCR_DOC_GUNDAM_PAGE_WINDOW=10 # pages per window (gundam mode)
export SGLANG_UOCR_DOC_BASE_PAGE_WINDOW=10 # pages per window (base mode)
export SGLANG_UOCR_MAX_PAGE_TOKENS=20000 # per-page output cap; must be > 0
# Chunk cap for the SAM attention bias. The built-in default (512) allows a single
# ~462 MiB allocation and can OOM; 64 is equivalent with a lower peak.
export SGLANG_OPT_UOCR_SAM_REL_POS_BIAS_MB=64
# Pass large crop tensors through /dev/shm instead of pickling them into the
# tokenizer -> scheduler frame.
export SGLANG_UOCR_SHM_WRAP_MODEL_DATA=1
export SGLANG_UOCR_SHM_WRAP_MIN_MB=1
export SGLANG_VLM_CACHE_SIZE_MB=0
# Reduces fragmentation failures on the large contiguous allocations.
export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True
python -m sglang.launch_server \
--model-path baidu/Unlimited-OCR-2 \
--served-model-name Unlimited-OCR-2 \
--chat-template unlimited-ocr \
--tokenizer-backend fastokens \
--tokenizer-worker-num 8 \
--mem-fraction-static 0.7 \
--max-running-requests 64 \
--max-prefill-tokens 2048 \
--enable-custom-logit-processor \
--enable-streaming-session \
--allow-auto-truncate \
--disable-radix-cache \
--mm-preprocess-cache-size-mb 0 \
--cuda-graph-backend-decode full --cuda-graph-max-bs-decode 64 \
--cuda-graph-backend-prefill full \
--cuda-graph-max-bs-prefill 16384 \
--cuda-graph-bs-prefill 1024 2048 \
--cuda-graph-config '{"prefill": {"backend":Quoted from the model card on Hugging Face. The full card is behind the Hugging Face link above.