deepseek-ocr-2 on Tenstorrent p150

Derived from DeepSeek's DeepSeek-OCR-2 (paper: DeepSeek-OCR 2: Visual Causal Flow), with unmodified weights downloaded from the authors' repository. Official code: deepseek-ai/DeepSeek-OCR-2. This is a third-party port, not affiliated with or endorsed by DeepSeek. See the original model card for training details.

DeepSeek-OCR-2 reads documents: it converts a page to Markdown with the layout regions marked by boxes, or reads its text without boxes ("free OCR"), the two uses its model card documents. Its vision encoder, DeepEncoder V2, is SAM-ViT-B (window attention over 16 x 16-pixel patches, 16x token compression) followed by a 24-layer Qwen2-style language-model encoder ("visual causal flow"): learned queries, 256 for a 1024 x 1024 view and 144 for a 768 x 768 tile, read the compressed image tokens and each other in a learned causal order, and become the vision tokens. They enter the same decoder as DeepSeek-OCR, a DeepSeek-V2-style model of 12 layers with 64 routed + 2 shared experts per layer (3B parameters, about 570M active per token), which writes the answer token by token. Three resolution modes trade speed for detail: Gundam, the official default (a 1024 x 1024 global view plus 2 to 6 tiles of 768 x 768 for images larger than 768 x 768, 257 to 1121 image tokens), Base (1024 x 1024, 257) and Small (768 x 768, 145). The package includes the official image views and tiling, prompts, stop token and no-repeat n-gram rule, and the official Markdown post-processing. The vision encoder and the prefill run on the device as traced tt-nn graphs, one per view size and prompt-length bucket, and the decoder writes every token with a traced tt-nn decode step (the mixture of experts over the 6 experts the token is routed to). An experimental decoder megakernel (all 12 layers, the routing and the sampling in one device program per token, about 3.5x faster) can be enabled; it can hang the card (see Limitations). Image decoding and tiling run on the host CPU.

Runs on Tenstorrent p150 β€” see the serving profiles below.

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

Document OCR on one Tenstorrent p150, one request at a time: Markdown conversion of pages, slides and tables with layout boxes, and plain-text OCR of lines, paragraphs and formulas; 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.8 GB of free disk for the checkpoint (fetched once into the Hugging Face cache), plus the container image and about 2.3 GB for the compiled kernels in the container's persistent cache (3.2 GB more with the experimental megakernel, for its packed weights)
  • Time for the first start: about 18 minutes on the test host (it compiles the device kernels); later starts reuse the kernel cache and take a few minutes
  • Images as PNG, JPEG, WebP, BMP, TIFF or GIF (the first frame); PDF pages must be rendered to images first

Quickstart

tt serve changh95/DeepSeek-OCR-2

tt serve downloads the Docker image and the deepseek-ai/DeepSeek-OCR-2 at aaa02f3811945a91062062994c5c4a3f4c0af2b0 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/DeepSeek-OCR-2.

On the port tt serve reported:

curl -sLO https://huggingface.co/changh95/DeepSeek-OCR-2/resolve/main/code/tt_dsocr/samples/line_en/sample.png
curl -s localhost:20000/ocr -F file=@sample.png -F task=free -F mode=base
# {"model": "deepseek-ocr-2", "text": "Invoice No. 2026-0417, due 15 December 2026.", "finish_reason": "stop", ...}
curl -s localhost:20000/ocr -F file=@sample.png                       # Markdown with layout boxes (the default task)
curl -s localhost:20000/ocr -F file=@sample.png -F format=json        # the boxes in pixels (JSON)
curl -sN localhost:20000/ocr -F file=@sample.png -F task=free -F stream=true        # SSE text deltas

Serving profiles

Select a different serving profile using --profile.

profile hardware mesh description
ttnn (default) p150 P150 the tt-nn decoder (the default)
megakernel p150 P150 EXPERIMENTAL: the decoder megakernel, about 4x faster decode; it can hang the card, which then needs a reset

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 image goes in an image_url part as a data URL (base64), the prompt in a text part (<image> is placed in front when the text has none; empty = the Markdown task); 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, grounding tags included:

import base64
from openai import OpenAI
client = OpenAI(base_url="http://localhost:20000/v1", api_key="unused")
image = "data:image/png;base64," + base64.b64encode(open("sample.png", "rb").read()).decode()
r = client.chat.completions.create(model="deepseek-ocr-2", messages=[{"role": "user", "content": [
    {"type": "image_url", "image_url": {"url": image}}, {"type": "text", "text": "Free OCR."}]}],
    extra_body={"mode": "base"})
print(r.choices[0].message.content)

POST /ocr is the native route: multipart (file + fields), JSON ({"image": base64 or data URL, ...}) or the raw image as the body (Content-Type: image/png, fields as query parameters):

request field default meaning
file / image required the image (one per request)
task markdown markdown (`<
prompt the task's a free prompt instead of the task's (<image> is added in front when absent; up to DSOCR_MAX_PROMPT_TOKENS; untested by the authors)
mode gundam gundam, base, small (those enabled by DSOCR_MODES)
min_crops, max_crops 2, 6 Gundam tile grid limits (1 <= min <= max <= DSOCR_MAX_CROPS); images up to 768 x 768 get no tiles
format markdown for markdown, else raw raw (the model's output), markdown (the official post-processing: layout tags removed, image regions as ![](images/<i>.jpg) placeholders), json ({"text", "refs": [{"label", "boxes" (pixels), "boxes_norm" (0-999)}], "image"})
max_new_tokens 8192 1 .. DSOCR_MAX_NEW_TOKENS; clipped to the KV capacity left after the prompt
no_repeat_ngram_size, ngram_window, ngram_whitelist, ngram_preset hf: 20, whole sequence, none the official infer's no-repeat n-gram rule; ngram_preset=vllm is DeepSeek-OCR's vLLM recipe (30, window 90, <td> / </td> allowed); off or size 0 disables it
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", ...}
  • The answer: text (in format), raw_text, refs (every <|ref|>label<|/ref|><|det|>boxes<|/det|> group, boxes in pixels of the original image), json, finish_reason (stop | length), usage (prompt_tokens, image_tokens, completion_tokens), image (size, mode, tile grid, 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 and the timings of the last request; GET /v1/models lists the model.
  • The chat route reads the last user message only (one image, its 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, 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,small (one vision trace per view size) all, gundam
Gundam tiles DSOCR_MAX_CROPS 2 .. 6 6
KV capacity (prompt + output) DSOCR_MAX_CONTEXT 1024 .. 16384 positions 8192
largest / default max_new_tokens DSOCR_MAX_NEW_TOKENS, DSOCR_DEFAULT_MAX_NEW_TOKENS 16 .. 16384 8192, 8192
longest prompt text DSOCR_MAX_PROMPT_TOKENS 16 .. 4096 512
prefill buckets (one trace each) DSOCR_PREFILL_BUCKETS comma-separated multiples of 32 rows derived from the modes
device engines DSOCR_ENGINE (the serve profiles ttnn and megakernel set it) vis=ttnn,pre=ttnn,dec=ttnn (the tt-nn decoder) or dec=mk (the decoder megakernel: EXPERIMENTAL, about 3.5x faster decode, it can hang the card: see Limitations) vis=ttnn,pre=ttnn,dec=ttnn (profile ttnn)
weight formats DSOCR_PRECISION vis = bf16 / bfp8; pre_mlp, pre_experts = bf16 / bfp8 / bfp4; vis_fid, pre_fid = HiFi4 / HiFi2 / LoFi; mk (the decoder megakernel) = bfp8 / bfp8h8 / bf16 "" = vision bf16 HiFi4, prefill bfp8 HiFi2, mk=bfp8 (bf16 head)
megakernel attention slots DSOCR_MK_ATTK 1 .. 6 (context <= 8192 x slots) 4
largest top_k DSOCR_K_MAX 1 .. 64 64
megakernel launches per poll DSOCR_LOOP_STEPS 1 only (more back-to-back launches are refused: never validated) 1
queue DSOCR_QUEUE_DEPTH, DSOCR_QUEUE_TIMEOUT_S waiting requests, seconds 8, 300
uploads DSOCR_MAX_BODY_MB, DSOCR_MAX_INPUT_MEGAPIXELS, DSOCR_ALLOW_URLS MB, megapixels, 0 / 1 64, 50, 0

Example output

DeepSeek-OCR-2 on a Tenstorrent p150: an A4 technical note (left, with the returned layout boxes) and the returned
blocks (right)

An A4 page of an invented technical note (two text columns, a formula, a table; written and rendered for this package's tests), converted by this package's container on one p150 with the default request settings (task=markdown, format=json, Gundam, greedy, the tt-nn decoder): left, the page with the layout boxes as returned (pixels, from json.refs) and their labels; right, each group's returned content 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 DeepSeek's own float32 model on the CPU (transformers 4.46.3, the official infer input building, same weights and prompts, greedy, no_repeat_ngram_size 20) on synthetic test images (a paragraph, a table, a formula, a chart, Chinese) and a public-domain manuscript scan in Gundam mode, with the default configuration (the tt-nn decoder), and by an independent verifier on 16 held-out requests (new images in Small, Base and Gundam modes).

eval this package images
Prompt ids and image views vs the official infer identical 6 + 16 held out
Image embeddings PCC vs float32 0.9993 - 0.9998 (official bfloat16: 0.9996 - 0.9997); held out 0.9971 - 0.9999 6 + 16
Outputs identical to the float32 outputs (greedy) 5 of 6 pages (23 - 177 tokens). The 1863 handwritten manuscript first differs at its 9th token, where float32 itself is near a tie (probability 0.50 for its line break, 0.39 for this package's): the rest of the reading then differs (character error rate 0.137; both readings misread the handwriting). Teacher-forced along float32's tokens, the next-token top-1 agreement on that page is 0.981 6
Held out: outputs identical to float32 (greedy) 6 of 16. Each other output first differs where float32 itself is near a tie (its token has probability 0.11-0.56 and this package picks float32's second choice): layout-box coordinates, a block label or a line break (character error rate 0.001-0.031), and two formulas (0.041; 0.31 on a Small-mode formula) 16
speed (batch 1, warm) input measured
Vision encoder (traced) 1024 view / Gundam with 1 - 6 tiles 98 ms / 0.21 - 0.47 s
Time to first token Gundam pages 154-607 ms (119-830 ms held out)
Decoder (tt-nn; host-bound: the host CPU drives every step) quiet host / loaded host 80-82 / 44-60 tokens/s
Whole page (a 161-token table, Gundam) image in, text out 2.3 s
Server start (tt serve until ready, in the container) first start with empty caches / restart about 18 min (18 min 20 s with the megakernel configuration, which also packs its weights; DeepSeek-OCR's tt-nn first start: 17 min 12 s) / about 2-4 min (2 min 1 s - 2 min 19 s with a full kernel cache; longer on a busy host)

The decode speed depends on the host: the tt-nn decoder issues every step from the host CPU, so a busy host slows it. The experimental decoder megakernel (serve profile megakernel) decodes at 267-325 tokens/s (the 161-token table page in 0.89 s), with all 6 of these outputs identical to float32 (8 of the 16 held-out ones); see Limitations before using it.

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.
  • Two task presets only, the two prompts of the model card (markdown, free); DeepSeek-OCR's other presets (grounded OCR, figures, descriptions, locate) are not offered because the DeepSeek-OCR-2 card does not document them. Other prompts are accepted through prompt but untested.
  • One image per request, single-turn prompts, batch 1: requests are served one at a time in arrival order (DSOCR_QUEUE_DEPTH may wait). No PDF input; multi-page documents are read page by page.
  • Small stretches the image to a square (the official behaviour); Base pads it; very small print on a large page needs Gundam (tiles).
  • The markdown format follows the official post-processing: image regions become images/<i>.jpg placeholders but no crops are written (the boxes are in refs, in pixels). Transparent images are flattened as the official code does (convert("RGB")).
  • Sampling (temperature > 0) draws from at most the 64 most likely tokens (DSOCR_K_MAX); greedy decoding, the official default, is the reference behaviour.
  • The decoder megakernel (the serve profile megakernel: tt serve changh95/DeepSeek-OCR-2 --profile megakernel; decode at 267-325 instead of 44-82 tokens/s) is EXPERIMENTAL and off by default: it stopped responding three times in testing, all while decoding DeepSeek-OCR-2 pages (twice in development, about once per 2,200 decode steps, and once in an independent soak after 245,538 clean decode steps, with bounded reads and an abort-and-retry path in place); the root cause is not established. A stall leaves the card unusable until it is reset (tt-smi -r). Use it only where a stalled card can be reset; every other number on this card is measured with the default tt-nn decoder.
  • Formulas are the weakest case: two held-out formulas differ from float32 after a near-tie (character error rate 0.041 in Base mode, 0.31 in Small mode). On one held-out page of a repeated sentence in Base mode the vision encoder agreed less with float32 than DeepSeek's bfloat16 model does (image-embedding PCC 0.9981 against 0.9998; the text was identical to float32).
  • 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): deepseek-ai/DeepSeek-OCR-2 aaa02f38, Apache License 2.0 (the model card's license: apache-2.0 and the repository's LICENSE.txt, "Copyright (c) 2023 DeepSeek"; copied unchanged to code/tt_dsocr/licenses/LICENSE-Apache-2.0-DeepSeek-OCR-2.txt). Notices: code/tt_dsocr/licenses/NOTICE.md.
  • This package is a derivative work of DeepSeek-OCR-2: the inference code is written anew (image views, tiling, prompts and post-processing follow the official infer), the networks run on the device in tt-nn operations (and an optional, experimental decoder megakernel), and the weights are loaded unmodified. The official Python files are never downloaded or executed. The HTTP server, the Python API and the decode megakernel (with its on-device sampler) 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/DeepSeek-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 f3125bfd8f2022f3 (sha256, first 16 hex digits)
built 2026-12-02T10:25:35+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/DeepSeek-OCR-2

Finetuned
(39)
this model

Collection including changh95/DeepSeek-OCR-2

Paper for changh95/DeepSeek-OCR-2