# AI use cases for Unlimited OCR (baidu/Unlimited-OCR)

Repo: [baidu/Unlimited-OCR](https://github.com/baidu/Unlimited-OCR) | Use cases: 3 | Page: https://dedupedai.com/use-cases/baidu-unlimited-ocr/

Unlimited OCR 2 is Baidu's open OCR model for ultra-long document parsing. Sparse Reference Sliding Window Attention lets it parse documents of any length within a finite context window, with multi-page inference that uses cross-page context. It runs with Hugging Face Transformers for quick tests and a customized SGLang server for serving, and has a Hugging Face Spaces demo.

This file holds every use case of this repo. Each one starts with a "## " heading and ends with its URL.

- Parse a long multi-page scan with cross-page context: https://dedupedai.com/use-cases/baidu-unlimited-ocr/parse-a-long-multi-page-document-with-unlimited-ocr-2/
- Serve Unlimited OCR 2 with SGLang for hundred-page PDFs: https://dedupedai.com/use-cases/baidu-unlimited-ocr/serve-unlimited-ocr-2-with-sglang-for-batch-pdf-parsing/
- Compare your OCR pipeline on the MarathonDocBench ultra-long benchmark: https://dedupedai.com/use-cases/baidu-unlimited-ocr/benchmark-ocr-on-marathondocbench/

## How to parse a long multi-page scan with cross-page context with Unlimited OCR

Repo: [baidu/Unlimited-OCR](https://github.com/baidu/Unlimited-OCR) | Difficulty: Advanced | Time: 1 hour | Basis: From the README

Load Unlimited OCR 2 in Transformers and parse all pages of a document in one request.

**Who it is for:** A data engineer turning long scanned reports into text where tables and sections cross page breaks.

**The problem:** Page-by-page OCR loses context across pages and breaks tables and paragraphs that span them.

**The outcome:** Text for the whole document from one multi-page call, saved to an output folder.

### Steps

1. Install the tested versions with `pip install torch==2.13.0 torchvision pillow transformers==4.52.1 huggingface-hub==0.36.0` plus the other pinned packages in the README
2. Load baidu/Unlimited-OCR-2 with AutoModel and AutoTokenizer using trust_remote_code=True and bfloat16 on CUDA
3. Convert your document to page images in page order
4. Call model.infer_multi with image_files set to the pages and save_results=True
5. For a single page, call model.infer, which uses dynamic tiling (gundam mode)

### Prompt to paste into your agent

```text
Using baidu/Unlimited-OCR-2 in Transformers as the README shows, convert <document.pdf> to page images, run infer_multi over all pages, and save the text to output/multi. Report token count and any pages that look wrong.
```

### Caveat



Risk, remote-code: Loading the model uses trust_remote_code=True, which runs code from the model repository; review it first.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/baidu-unlimited-ocr/parse-a-long-multi-page-document-with-unlimited-ocr-2/

## How to serve Unlimited OCR 2 with SGLang for hundred-page PDFs with Unlimited OCR

Repo: [baidu/Unlimited-OCR](https://github.com/baidu/Unlimited-OCR) | Difficulty: Advanced | Time: 2 hours | Basis: From the README

Set up the customized SGLang build and run a server tuned for very long documents.

**Who it is for:** A platform team that needs a document parsing service for long PDFs.

**The problem:** Serving OCR for hundred-page documents runs out of memory or context with standard settings.

**The outcome:** An SGLang server for Unlimited-OCR-2 with page-window scheduling for very long documents.

### Steps

1. Run `uv venv --python 3.10` and `source .venv/bin/activate`
2. Install the customized SGLang wheel from the repo, then `uv pip install pymupdf==1.27.2.2` and `uv pip install fastokens==0.3.2`
3. Set the page-window variables, for example SGLANG_UOCR_EANABLE_DOC_LIMIT=1 and SGLANG_UOCR_DOC_GUNDAM_PAGE_WINDOW=10
4. Start it with `python -m sglang.launch_server` and `--model-path baidu/Unlimited-OCR-2` plus the README flags
5. Send PDFs converted with PyMuPDF and check memory on the first long document

### Prompt to paste into your agent

```text
Set up baidu/Unlimited-OCR's SGLang server following the README exactly, with page windows of 10, then parse <long.pdf> through it and tell me peak GPU memory and time per page.
```

### Caveat



Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/baidu-unlimited-ocr/serve-unlimited-ocr-2-with-sglang-for-batch-pdf-parsing/

## How to compare your OCR pipeline on the MarathonDocBench ultra-long benchmark with Unlimited OCR

Repo: [baidu/Unlimited-OCR](https://github.com/baidu/Unlimited-OCR) | Difficulty: Advanced | Time: half a day | Basis: From the README

Use Baidu's new MarathonDocBench dataset to test how your current OCR handles very long documents.

**Who it is for:** A team choosing an OCR model for long reports, contracts or books.

**The problem:** Most OCR benchmarks use single pages, so they hide how models fail on long documents.

**The outcome:** A side by side comparison of your current OCR and Unlimited OCR 2 on long documents.

### Steps

1. Get MarathonDocBench from Hugging Face (baidu/MarathonDocBench)
2. Run your current OCR on a sample of its documents
3. Run Unlimited OCR 2 with infer_multi on the same documents
4. Compare outputs, and try the Hugging Face Spaces demo for quick checks

### Prompt to paste into your agent

```text
Download baidu/MarathonDocBench, pick 5 long documents, run both <my OCR tool> and baidu/Unlimited-OCR-2 (infer_multi) on them, and write a comparison of where each fails.
```

### Caveat



Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/baidu-unlimited-ocr/benchmark-ocr-on-marathondocbench/
