Skip to main content

Deployment

Unlimited-OCR-2 support is not in a tagged SGLang release yet. Until it is, install SGLang from a source build that contains it. For all methods and hardware platforms, see the official SGLang installation guide.
Command
Then run the Python output of the command panel below in that environment.
Pick your hardware to generate the launch command. SGLang selects the unlimited_ocr_v2 attention backend, the page size the checkpoint requires and a disabled radix cache on its own, so the recipe only carries the serving options: the unlimited-ocr chat template, explicit page-window processing with --uocr-doc-split, a per-page output budget, and decode CUDA graphs, which are off by default for this model. The built-in page guard runs automatically; --enable-custom-logit-processor is only needed for an external custom processor.

Playground

Use the Playground to adjust tensor parallelism on top of the selected deployment cell.

1. Model Introduction

Unlimited-OCR-2 is Baidu’s document parsing model for long and very long documents: all pages of a document go into one request, and the answer carries one <PAGE> section per input page, in page order. It replaces the sliding window of Unlimited-OCR with DASH sparse attention, where a learned router picks the KV blocks each query reads and every page keeps its own 2D position frame, so decode cost stays nearly flat as the document grows. The checkpoint has about 3.3B parameters in BF16 (a DeepSeek-style MoE language backbone with SAM and CLIP vision encoders) and is released under the MIT license. Recommended generation: temperature=0, with skip_special_tokens=false so the <PAGE> markers stay in the output. Resources: Hugging Face · GitHub · MarathonDocBench

2. Configuration Tips

  • Prompt layout: list the page images first, then one text part holding <PAGE><image> once per page followed by the instruction, for example "<PAGE><image>" * num_pages + "Multi page parsing.".
  • Whole-document processing is the default. Omit --uocr-doc-split to process the document together, within the configured context length.
  • Page-window processing is opt-in. The deployment recipe enables --uocr-doc-split for long documents. --uocr-doc-page-window N sets the maximum pages each window transcribes in every image mode (default 1). Later windows reuse the preceding window’s KV tail. This changes the available context and is approximate; it is not a lossless replacement for whole-document inference. The client still sends one request and receives one response or stream, with metadata.doc_split_* describing the processing.
  • Per-page output budget: --uocr-max-page-tokens N limits how many tokens one output page may spend before the guard advances to the next page or ends the document. The default 0 leaves the page length uncapped. A nonzero cap also sizes the default context of a split server. It changes stopping behavior and needs no custom-processor flag. The page budget excludes page markers and termination tokens; overlap scheduling may leave one already-computed token beyond the budget. Set the request’s total max_tokens to cover the document.
  • Per-request options: doc_split_options.max_batch_pages may lower the server’s window size; max_page_tokens may lower a nonzero server page cap. lookahead_pages defaults to 1 and overlap_pages to 0. Set lookahead_pages: 0 to omit the following page from the window’s input. Lookahead and overlap change the input context and must fit the server’s context budget. Window options require --uocr-doc-split; a per-page output cap can also be used without splitting.
  • Data parallelism: page-window processing requires a single DP rank. Omit --uocr-doc-split with --dp-size or --attn-dp-size above 1.
  • Not supported: speculative decoding, pipeline parallelism and PD disaggregation are rejected at launch.

3. Advanced Usage

3.1 Multi-page document

The example renders a three-page document and prints each page’s section. It uses the page-window deployment recipe above.
Example
Check metadata.doc_split_complete before treating a non-streaming split response as a complete document. If a window exceeds the context limit while other windows succeed, the response contains those successful windows, reports finish_reason: "length", and lists the rejected window in metadata.doc_split_incomplete_batches.
Output

3.2 Choosing an image mode

Pass images_config.image_mode per request; when it is omitted SGLang uses gundam. vLLM’s mm_processor_kwargs={"crop_mode": true} selects gundam and false selects base. Lower modes reduce prefill cost per page, which also lets a window hold more pages.
ModeUseWindow policy
tiny, smallLowest prefill cost for simple pages.—uocr-doc-page-window
baseOne global view per page; the model card’s multi-page setting.—uocr-doc-page-window
largeHigher-resolution global view.—uocr-doc-page-window
gundamDefault. Global view plus dynamic tiles for dense pages.—uocr-doc-page-window