Derived from DeepSeek's DeepSeek-OCR (paper: DeepSeek-OCR: Contexts Optical Compression), with unmodified weights downloaded from the authors' repository. Official code: deepseek-ai/DeepSeek-OCR. This is a third-party port, not affiliated with or endorsed by DeepSeek. See the original model card for training details.
DeepSeek-OCR reads documents and images: it converts a page to Markdown with the layout regions marked by boxes, reads text with or without boxes, parses figures, describes images and finds a referred object or text in the image ("locate"). Its vision encoder, DeepEncoder, is SAM-ViT-B (window attention over 16 x 16-pixel patches) followed by CLIP-L, which compresses each 1024 x 1024 view to 256 vision tokens (16x fewer tokens than patches); the tokens enter a DeepSeek-V2-style decoder of 12 layers with 64 routed + 2 shared experts per layer (3B parameters, about 570M active per token) that writes the answer token by token. Five resolution modes trade speed for detail: Tiny (512 x 512, 73 image tokens), Small (640, 111), Base (1024, 273, aspect ratio kept), Large (1280, 421) and Gundam, the official default (a 1024 x 1024 global view plus 2 to 9 tiles of 640 x 640, 273 to 1263 image tokens). 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 4x 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).
| Hardware | p150 |
| License | apache-2.0 |
Document OCR on one Tenstorrent p150, one request at a time: Markdown conversion of pages, slides and tables with layout boxes, plain-text OCR of lines, paragraphs and formulas, figure parsing and image descriptions, and locating a referred element; for research, prototyping and offline processing.
tt: uv tool install tenstorrent (or use tt-model alone, see the Quickstart)tt serve changh95/DeepSeek-OCR
tt serve downloads the Docker image and the deepseek-ai/DeepSeek-OCR at 9f30c71f441d010e5429c532364a86705536c53a 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.
On the port tt serve reported:
curl -sLO https://huggingface.co/changh95/DeepSeek-OCR/resolve/main/code/tt_dsocr/samples/line_en/sample.png
curl -s localhost:20000/ocr -F file=@sample.png -F task=free
# {"model": "deepseek-ocr", "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 task=locate -F 'ref=the date' # boxes in pixels (JSON)
curl -sN localhost:20000/ocr -F file=@sample.png -F task=free -F stream=true # SSE text deltas
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 |
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", 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 (`< |
ref |
- | locate: the object or text to find |
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) |
mode |
gundam |
tiny, small, base, large, gundam (those enabled by DSOCR_MODES) |
min_crops, max_crops |
2, 9 | Gundam tile grid limits (1 <= min <= max <= DSOCR_MAX_CROPS); images up to 640 x 640 get no tiles |
format |
markdown for markdown / ocr, json for locate, else raw |
raw (the model's output), markdown (the official post-processing: layout tags removed, image regions as  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 no-repeat n-gram rule; ngram_preset=vllm is the official 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", ...} |
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.temperature defaults to 0, not
OpenAI's 1; it also takes task, ref, 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.Retry-After), 503 while starting or after DSOCR_QUEUE_TIMEOUT_S, 500 on a device failure.tt_dsocr.api.DeepSeekOcr) is described in
code/PYTHON.md; it needs a tt-metal build with the patches in patches/.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 tiny,small,base,large,gundam (one vision trace per view size) |
all, gundam |
| Gundam tiles | DSOCR_MAX_CROPS |
2 .. 9 | 9 |
| 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 4x 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 |
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.
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 text line, a paragraph, an A4 page, a table, formulas, a chart, Chinese, a handwritten
note; all five modes) with the default configuration (the tt-nn decoder), and by an independent verifier on 20 held-out requests
(new images in every mode and with every task preset).
| eval | this package | images |
|---|---|---|
Prompt ids and image views vs the official infer |
identical | 12 + 20 held out |
| Image embeddings PCC vs float32 | Tiny, Small, Base, Gundam: 0.9955 - 0.9999 (official bfloat16: 0.9983 - 0.9998; held out 0.9970 - 0.9999). Large: 0.984 on a chart (bfloat16 0.9995) and 0.988 on a held-out text image | 12 + 15 |
| Teacher-forced next-token top-1 agreement vs float32 | 1.000 on a table and a chart (Gundam); 0.960 on the Tiny formula (its float32 near-tie, below) | 3 |
| Outputs identical to the float32 outputs (greedy) | 10 of 12 (all five modes, incl. the Large chart); the A4 page (481 tokens) has a character error rate of 0.0026, and the Tiny formula (23 tokens) 0.032 (its second token is a float32 near-tie: logits 23.29 vs 23.00) | 12 |
| Held out: outputs identical to float32 (greedy) | 3 of 15 checked (two formulas, a repetitive page). Each other output first differs where float32 itself is near a tie (its token has probability 0.06-0.43 and this package picks float32's second choice): box coordinates and table numbers (character error rate 0.001-0.015), a chart's numbers (0.072), Greek / Cyrillic lines (0.006-0.052), and two answers float32 gets wrong too (Korean lines the model cannot read, 0.45; a free-form description, 0.39) | 15 |
| speed (batch 1, warm) | input | measured |
|---|---|---|
| Vision encoder (traced) | Tiny 512 / Base 1024 / Gundam 1024 + 9 tiles | 38 ms / 94 ms / 0.46 s |
| Time to first token | Tiny / Small / Base / Gundam pages | 133 / 160 / 183 / 360-880 ms (100-800 ms held out) |
| Decoder (tt-nn; host-bound: the host CPU drives every step) | quiet host / loaded host | 65-83 / 34-49 tokens/s |
| Whole page (a 161-token table, Gundam) | image in, text out | 2.4 s |
| Long output (1,655 tokens, held out, loaded host) | image in, text out | 39.9 s |
Server start (tt serve until ready, in the container) |
first start with empty caches / restart | 17 min 12 s / about 2-4 min (1 min 47 s on a quiet host, 3 min 47 s - 4 min 27 s under load) |
The decode speed depends on the host: the tt-nn decoder issues every step from the host CPU, so a busy host slows it
(34-49 tokens/s at a load average of about 22; 66-74 tokens/s for most of a 62-request soak). The experimental
decoder megakernel (serve profile megakernel) decodes at 230-320 tokens/s (the 161-token table page in 0.86 s)
with 9 of these 11 outputs identical to float32; see Limitations before using it.
DSOCR_QUEUE_DEPTH may wait). No PDF input; multi-page documents are read page by page.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). For the ocr task the recognized text of each
box is kept. Transparent images are flattened as the official code does (convert("RGB")).temperature > 0) draws from at most the 64 most likely tokens (DSOCR_K_MAX); greedy decoding, the
official default, is the reference behaviour.megakernel: tt serve changh95/DeepSeek-OCR --profile megakernel;
decode at 230-320 instead of 65-83 tokens/s) is EXPERIMENTAL and off by default: it stopped responding three times in testing, all while decoding
DeepSeek-OCR-2 pages with the same program (twice in development, about once per 2,200 decode steps, and once
in an independent soak after bounded reads and an abort-and-retry path had been added); 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.tt serve downloads them from the authors' repository at this commit):
deepseek-ai/DeepSeek-OCR 9f30c71f, MIT License
(Copyright (c) 2023 DeepSeek; the model card and the repository's LICENSE). Notices:
code/tt_dsocr/licenses/NOTICE.md.infer; MIT), 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.code/) and the tt-metal patches in patches/: Apache-2.0.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.Questions or problems with this package: open a discussion at https://huggingface.co/changh95/DeepSeek-OCR/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.
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 |
facb97435cb0e31e (sha256, first 16 hex digits) |
| built | 2026-12-02T11:14:16+00:00 by tt-model 0.1.0 |
deepseek-ai/DeepSeek-OCR