unlimited-ocr-2 on Tenstorrent p150

Derived from Baidu's Unlimited-OCR-2 (paper: Unlimited OCR Works 2), with unmodified weights downloaded from the authors' repository. Official code: baidu/Unlimited-OCR. The model builds on DeepSeek's DeepSeek-OCR. This is a third-party port, not affiliated with or endorsed by Baidu or DeepSeek. See the original model card for training details.

Unlimited-OCR-2 parses whole documents: it reads one or more page images in one request and writes every page in order, each page as layout blocks with a label (title, text, table, equation, image, ...), a box and the content (Markdown, HTML tables, LaTeX). Each page is encoded by DeepSeek-OCR's vision encoder, DeepEncoder (SAM-ViT-B followed by CLIP-L, 16x token compression), into 273 image tokens for a 1024 x 1024 view, plus about 100 per 640 x 640 tile; the tokens of all pages enter a DeepSeek-V2-style decoder of 12 layers with 64 routed + 2 shared experts per layer (3B parameters, about 570M active per token) whose attention is block-sparse (SR-SWA, "DASH"): in every layer a learned router picks, for each token, 12 earlier blocks of 32 tokens (while a page is written: blocks of that page's image) and adds them to a 128-token local window, with a page-aware 2-D rotary position, so each token reads at most 512 earlier positions however long the document is. The output starts every page with <PAGE>, as many as there are input pages (the official page-count guard). Two resolution modes: Gundam, the official choice for a single page (a 1024 x 1024 global view plus 2 to 16 tiles of 640 x 640, 273 to 2033 image tokens), and Base, the official choice for several pages (one 1024 x 1024 view per page). The package includes the official input building (views, tiling, the <PAGE><image> prompt layout), greedy decoding with the page-count guard, and a Markdown / JSON reading of the page and block tags. The vision encoder runs on the device as traced tt-nn graphs (one per view size), the decoder as tt-nn operations with the block router's choice made on the host per layer; image decoding and tiling run on the host CPU.

Runs on Tenstorrent p150 (mesh P150).

Packaged and published with tt-model-manager 0.1.0 (manifest schema 5.1).

At a glance

Hardware p150
License apache-2.0

Intended use

Multi-page document parsing on one Tenstorrent p150, one request at a time: articles, reports, papers and books rendered as page images, converted to Markdown with layout blocks and boxes per page, keeping the context across pages; for research, prototyping and offline processing.

Prerequisites

  • The Tenstorrent CLI, tt: uv tool install tenstorrent (or use tt-model alone, see the Quickstart)
  • Docker
  • Tenstorrent hardware: p150
  • About 6.7 GB of free disk for the checkpoint (fetched once into the Hugging Face cache), plus the container image and about 2.6 GB for the compiled kernels in the container's persistent cache
  • Time for the first start: about 24 minutes on the test host (it compiles the device kernels); later starts reuse the kernel cache and take a few minutes
  • Page images as PNG, JPEG, WebP, BMP, TIFF or GIF (the first frame); PDF pages must be rendered to images first

Quickstart

tt serve changh95/Unlimited-OCR-2

tt serve downloads the Docker image and the baidu/Unlimited-OCR-2 at cb16b920ec2249c4b280f3aa67942e00b5099122 weights (into your HF cache; they are not in the image), then starts the model's own HTTP server on port 20000 (or the next free port, if that one is busy). The first start compiles kernels for your device, which takes several minutes; the server is ready when it logs Application startup complete.

Without tt-cli: tt-model serve changh95/Unlimited-OCR-2.

On the port tt serve reported:

base=https://huggingface.co/changh95/Unlimited-OCR-2/resolve/main/code/tt_dsocr/samples
curl -sL -o page1.png $base/table_sales/sample.png
curl -sL -o page2.png $base/formula_quad/sample.png
curl -s localhost:20000/ocr -F file=@page2.png -F format=raw          # one page (Gundam tiles)
# {"model": "unlimited-ocr-2", "text": "<PAGE><BLOCK>equation[184, 243, 812, 760]<FORK>$$\nx = \\frac {- b ...", ...}
curl -s localhost:20000/ocr -F file=@page1.png -F file=@page2.png    # a two-page document: Markdown per page
curl -s localhost:20000/ocr -F file=@page1.png -F file=@page2.png -F format=json    # pages -> blocks + boxes
curl -sN localhost:20000/ocr -F file=@page1.png -F file=@page2.png -F stream=true   # SSE text deltas

Capabilities

This package exposes the model's own HTTP server on port 20000, not an OpenAI-compatible chat API β€” its request and response shapes are the model's own. See the author's notes for the payload it expects.

POST /v1/chat/completions is OpenAI-compatible: the pages go in image_url parts as data URLs (base64), one per page in order; the text part is the instruction (empty = Multi page parsing., the official default; the server writes <PAGE><image> per page in front of it, or takes a text that already has one <PAGE><image> per page, as the official SGLang client sends it); stream, max_tokens, temperature, top_p, seed and stream_options.include_usage work as in the OpenAI API, and the OpenAI Python client works against it. The answer is the model's raw output, page and block tags included:

import base64
from openai import OpenAI
client = OpenAI(base_url="http://localhost:20000/v1", api_key="unused")
url = lambda p: "data:image/png;base64," + base64.b64encode(open(p, "rb").read()).decode()
r = client.chat.completions.create(model="unlimited-ocr-2", messages=[{"role": "user", "content": [
    {"type": "image_url", "image_url": {"url": url("page1.png")}},
    {"type": "image_url", "image_url": {"url": url("page2.png")}}]}])
print(r.choices[0].message.content)        # <PAGE><BLOCK>table[...]<FORK><table>...<PAGE><BLOCK>equation[...]...

POST /ocr is the native route: multipart (one file part per page, in order, + fields), JSON ({"images": [base64 or data URL, ...], ...} or {"image": ...} for one page) or one raw image as the body (Content-Type: image/png, fields as query parameters):

request field default meaning
file (repeated) / images / image required the page images, in order: 1 .. DSOCR_MAX_PAGES (8)
task parse parse: the official instruction Multi page parsing. after the pages' <PAGE><image> runs (the only prompt the model card documents)
prompt the task's another instruction (<PAGE><image> per page is added in front when it has no <image>; a single <image> is expanded per page; every page needs its <PAGE><image>); untested by the authors
mode gundam for one page, base for several gundam (1024 global view + 2 .. 16 tiles of 640), base (one 1024 view per page: 273 image tokens + 1 <PAGE>); those enabled by DSOCR_MODES
min_crops, max_crops 2, 16 Gundam tile grid limits per page (1 <= min <= max <= DSOCR_MAX_CROPS); pages up to 640 x 640 get no tiles
format markdown for parse, else raw raw (the model's output with its tags), markdown (per page the block contents without the tags; image blocks as ![](images/page_<p>_<i>.jpg) placeholders; pages separated by <!-- page <k> --> lines), json ({"text", "pages": [{"page", "width", "height", "text", "blocks": [{"label", "kind", "level" (titles), "box" (pixels of that page), "box_norm" (0-999), "text"}]}], "refs"})
max_new_tokens 16384 1 .. DSOCR_MAX_NEW_TOKENS; clipped to the KV capacity left after the prompt (the official default: until the context is full)
no_repeat_ngram_size, ngram_window, ngram_whitelist, ngram_preset off no n-gram rule (the official infer); ngram_preset=sglang is the official SGLang client's rule (35, window 128 for one page, 1024 for several); explicit fields set any rule
temperature, top_k, top_p, repetition_penalty, seed 0, 0, 1, 1.0, random 0 = greedy, the official decoding; top_k <= 64
stream false Server-Sent Events: {"type": "delta", "text"} as tokens are decoded, then {"type": "done", ...}
  • Fixed (the official infer defaults): the page-count guard is always on (the end of the output is held back until it has one <PAGE> per input page; a page longer than 20000 tokens is closed).
  • The answer: text (in format), raw_text, refs (every block with a box: label, boxes in pixels of its page, 0..999 values, page number), json, finish_reason (stop | length), usage (prompt_tokens, image_tokens, completion_tokens), image (the first page's size and mode, n_pages, and per page its size, tile grid and image tokens) and timings (preprocessing, vision, prefill, first token, decode tokens per second).
  • GET /health reports readiness, GET /info the weights and their commit, the device, the engines, the configuration, the modes and their image-token counts, the limits (max_pages) and the timings of the last request; GET /v1/models lists the model.
  • The chat route reads the last user message only (its image parts and text parts); temperature defaults to 0, not OpenAI's 1; it also takes task, mode, min_crops, max_crops, top_k, repetition_penalty and the n-gram fields. n other than 1, stop, logprobs, tools, presence / frequency penalties and JSON response formats are refused with 400. Image URLs (http / https) are fetched only when DSOCR_ALLOW_URLS=1.
  • Errors: 400 with the reason (also: more pages than DSOCR_MAX_PAGES, or a document that does not fit the largest prefill bucket: send several pages in base mode), 413 body or image too large, 415 content type, 422 malformed body, 429 queue full (Retry-After), 503 while starting or after DSOCR_QUEUE_TIMEOUT_S, 500 on a device failure.
  • A Python API with the same parameters (tt_dsocr.api.DeepSeekOcr) is described in code/PYTHON.md; it needs a tt-metal build with the patches in patches/.

Configuration

The server builds its device programs for one configuration when it starts; change it with environment variables and start it again. GET /info reports it.

item environment variable values default
resolution modes a request may use DSOCR_MODES, DSOCR_DEFAULT_MODE any of gundam,base (one vision trace per view size) both, gundam (one page; several pages use base)
Gundam tiles per page DSOCR_MAX_CROPS 2 .. 16 16
pages per request DSOCR_MAX_PAGES 1 .. 32 (the prefill buckets and the KV capacity must hold them) 8
KV capacity (all pages + the whole output) DSOCR_MAX_CONTEXT 1024 .. 16384 positions 16384
largest / default max_new_tokens DSOCR_MAX_NEW_TOKENS, DSOCR_DEFAULT_MAX_NEW_TOKENS 16 .. 16384 16384, 16384
longest instruction text DSOCR_MAX_PROMPT_TOKENS 16 .. 4096 512
prefill buckets DSOCR_PREFILL_BUCKETS comma-separated multiples of 32 rows (multiples of 128 always work; a few others above 4096 rows are refused at start) derived from the modes and pages (384 .. 2816)
device engines DSOCR_ENGINE vis=ttnn,pre=ttnn,dec=ttnn (the only decoder engine of the DASH attention) vis=ttnn,pre=ttnn,dec=ttnn
weight formats DSOCR_PRECISION vis = bf16 / bfp8; pre_mlp, pre_experts = bf16 / bfp8 / bfp4; vis_fid, pre_fid = HiFi4 / HiFi2 / LoFi "" = vision bf16 HiFi4, decoder MLP / experts bfp8 HiFi2
largest top_k DSOCR_K_MAX 1 .. 64 64
queue DSOCR_QUEUE_DEPTH, DSOCR_QUEUE_TIMEOUT_S waiting requests, seconds 8, 600
uploads DSOCR_MAX_BODY_MB, DSOCR_MAX_INPUT_MEGAPIXELS, DSOCR_ALLOW_URLS MB per request, megapixels per page, 0 / 1 128, 50, 0

Example output

Unlimited-OCR-2 on a Tenstorrent p150: a two-page request (an invented maintenance report page and an
invented technical note page), each page with the returned layout boxes (left) and its returned blocks
(right)

Two A4 pages (an invented quarterly maintenance report and an invented technical note; written and rendered for this package's tests) sent as ONE request to this package's container on one p150 with the default settings (task=parse, format=json, greedy, page-count guard on): a row per page; left, the page with the boxes of the returned blocks (pixels, from json.pages[].blocks) and their labels; right, the returned blocks in reading order, the HTML table drawn as a grid and the formula as the returned LaTeX. The timings are in the image's footer; the exact request and the whole answer are in media/demos.json. Attributions for every file in media/: media/ATTRIBUTION.md.

Expected performance

Measured on the p150 (ETH dispatch, 120 cores) against Baidu's own float32 model on the CPU (transformers 4.52.1, the official infer input building, same weights and prompts, greedy, page-count guard on, no n-gram rule) on synthetic test pages (a text line, a paragraph, a table, a formula, Chinese: one page in Gundam mode, two-page documents in Base mode), and by an independent verifier on 16 held-out runs (new pages, 1 to 8 pages).

eval this package pages
Prompt ids and image views vs the official infer identical all
Image embeddings PCC vs float32 0.9975 - 0.9998 (held out: 0.9980 - 0.9998) 6 (+ held out)
Teacher-forced next-token top-1 agreement vs float32 0.960 - 1.000 (the two-page documents 0.960 / 0.995) 6
Greedy outputs identical to the float32 outputs 4 of 4 test pages; held out: 4 of 16 runs. The other runs differ in 1-10 layout-box coordinates by 1-27 units (0-999 scale, steps where float32 itself is near a tie) and once in a block label; the text is identical where checked 6 + 16
This port's accuracy gates relative to DeepSeek-style bfloat16 drift (image-row PCC >= min(0.999, bf16 - 0.001); teacher-forced top-1 >= bf16 - 0.01; distribution distance <= max(2 x bf16, 0.020)) met on 2 of the 6 test inputs (the formula page; the paragraph page with 14 tiles); missed on 4: the Chinese page (image rows 0.9989 against 0.999), the table page with 2 tiles (image rows 0.9982 against 0.9986; distribution distance 0.031 against 0.020), the two-page table + formula document (distribution distance 0.024 against 0.020) and the two-page line + paragraph document (image rows 0.9975 against 0.999; top-1 0.960 against 0.990; distribution distance 0.032 against 0.020). The misses are numerical: the greedy text stayed identical 6
speed (batch 1, warm) input measured
Time to first token one Gundam page with 0 / 2 / 14 tiles 0.23-0.53 / 0.31-0.96 / 1.2-2.0 s
Time to first token two / eight Base pages 0.35-0.37 / 1.3-2.0 s
Decoder, prompt + output below ~2,300 positions (one or two pages) quiet / loaded host 40-50 / 25-39 tokens/s, or lower on a busier host
Decoder beyond ~2,300 positions (every 8-page document) loaded / quieter host 13-20 (or lower on a busier host) / up to 31 tokens/s
Whole page (a 159-token table, Gundam) image in, text out 3.5 s (quiet host) - 7.5 s (loaded)
8-page dense document (8 Base pages, 4,933 output tokens) image in, text out 250 s (loaded host)
Server start (tt serve until ready, in the container) first start with empty caches / restart 23 min 43 s / 2 min 9 s

Limitations

  • Not for decisions that need exact text without a human check (legal, medical, financial or identity documents): OCR output can miss, misread or invent characters, on the CPU and the p150 alike.
  • At most DSOCR_MAX_PAGES (8 by default, up to 32) pages per request, all in one KV cache of DSOCR_MAX_CONTEXT (16384) positions: the prompt of 8 Base pages takes 2197 of them, the rest is the room for the whole output, after which the answer stops with finish_reason length. The paper's unlimited-horizon decoding (the SGLang deployment's page windows that reuse the KV of the previous window) is not implemented: longer documents are sent in several requests.
  • The decoder's block router runs on the host for every layer of every token (a host round trip per layer), and the decode attention spans the KV capacity: a larger DSOCR_MAX_CONTEXT costs decode time.
  • Several pages in Gundam mode are accepted only when they fit the largest prefill bucket (they rarely do with tiles); Base, one 1024 x 1024 view per page, is the official mode for documents.
  • Prompts must keep the trained layout, one <PAGE><image> per page (the server writes it); the official fallback for prompts without <PAGE> markers (a different rotary position) is not implemented and such prompts are refused with 400. The model is trained on the default instruction; other prompts are untested.
  • The page-count guard and its per-page cap (20000 tokens) are fixed. The markdown and json formats are this package's reading of the <PAGE> / <BLOCK> / <FORK> / <CHILD> tags (the official save_results keeps the block tags in its Markdown); raw is the model's output unchanged. Image blocks become placeholders; no crops are written.
  • Sampling (temperature > 0) draws from at most the 64 most likely tokens (DSOCR_K_MAX); greedy decoding, the official default, is the reference behaviour.
  • Decoding is slow and depends on the host: the block-sparse attention picks its blocks on the host CPU for every layer of every token (12 host round trips per token), and the prefill runs without traces. One or two pages decode at 25-50 tokens per second, depending on the host's load; beyond about 2,300 positions of prompt + output (every 8-page document from its first token) the speed drops to 13-20 tokens per second on a loaded host (up to 31 on a quieter one); the cause of that step is not established. An 8-page document with about 600 output tokens per page took about 4 minutes; about 1,000 tokens per page would take about 7 minutes.
  • One p150 only: device dispatch runs on the chip's Ethernet cores, so multi-chip meshes are not supported.

Licensing

  • Weights (not redistributed here; tt serve downloads them from the authors' repository at this commit): baidu/Unlimited-OCR-2 cb16b920, declared license: mit in its model card; the Hugging Face repository has no LICENSE file, and the model's official code repository (baidu/Unlimited-OCR, commit 5951217f) carries the MIT License, "Copyright (c) 2026 Baidu", shipped unchanged as code/tt_dsocr/licenses/LICENSE-MIT-Unlimited-OCR.txt (provenance: code/tt_dsocr/licenses/NOTICE-Unlimited-OCR-2.txt). Notices: code/tt_dsocr/licenses/NOTICE.md.
  • This package is a derivative work of Unlimited-OCR-2: the inference code is written anew (image views, tiling, the multi-page prompt layout and the page-count guard follow the official infer; the block-sparse attention follows the official modelling code, read but never run in the package), the networks run on the device in tt-nn operations, and the weights are loaded unmodified. The official Python files, the repository's wheel/ and its PDF are never downloaded, and the authors' code is never executed. The HTTP server and the Python API are adapted from the same author's changh95/GLM-OCR port (Apache-2.0), whose server worker comes from the same author's Qwen3-ASR / Qwen3-TTS ports. Related packages by the same author: changh95/GLM-OCR, changh95/PaddleOCR-VL, changh95/DepthPro2, changh95/all-MiniLM-L6-v2.
  • Port, server and scripts (code/) and the tt-metal patches in patches/: Apache-2.0.
  • Samples: code/tt_dsocr/samples/*/sample.png, synthetic images made for this package (Apache-2.0); provenance in their PROVENANCE.md. The demo files in media/: see media/ATTRIBUTION.md.

Feedback

Questions or problems with this package: open a discussion at https://huggingface.co/changh95/Unlimited-OCR-2/discussions β€” that is what reaches its author. A problem with the tt tooling itself: tt report issue (collects your environment and opens a prefilled issue against tenstorrent/tt-cli). Product feedback: support@tenstorrent.com.

Provenance

The exact sources the image was built from β€” code/ in this repo is byte-identical to the model code inside the image:

component built from
tt-metal 44d66500520fda9f2c7060c0f6b41ec48f7ab37e (dirty tree β€” the image includes uncommitted changes)
code/ digest 0068bf588cb3414e (sha256, first 16 hex digits)
built 2026-12-02T12:03:53+00:00 by tt-model 0.1.0
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for changh95/Unlimited-OCR-2

Finetuned
(7)
this model

Collection including changh95/Unlimited-OCR-2

Paper for changh95/Unlimited-OCR-2