TensorRT engines of DeepSeek-OCR-2, made by Moonbox for NVIDIA RTX GPUs. Each precision is one folder holding the
engine, trt_runner.py (a small numpy runner: TensorRT plus Polygraphy, no PyTorch) and a script that does the rest
of the pipeline. What the engine takes and returns is under How to run.
Compatibility. The engines are built hardware compatible (Ampere and newer: RTX 30, 40 and 50 series) and
version compatible (any TensorRT 10.x from 10.13 on, through its lean runtime). That costs a little speed against an
engine built for one GPU, but no rebuild is needed. Install the runtime with
pip install "tensorrt-cu12>=10.13,<11" "tensorrt-lean-cu12>=10.13,<11" polygraphy numpy.
The last column is the benchmark (details under How to run).
| Precision | File | Size | sha256 | Benchmark |
|---|---|---|---|---|
| fp16 | fp16/decoder_0.engine |
584.3 MB | b385c5e248a2 |
CER 0.0 % / 0.0 % (ONNX fp16 0.0 / 0.0), text identical to the ONNX fp16 build's on 12 / 12 pages; 2.17 s per page (ONNX fp16 2.11: the dense MoE reads all its experts every token in both) |
| fp16 | fp16/decoder_1.engine |
515.6 MB | 95d0a90b284e |
(the same build: numbers in its first row) |
| fp16 | fp16/decoder_10.engine |
516.4 MB | bdb291675229 |
(the same build: numbers in its first row) |
| fp16 | fp16/decoder_11.engine |
375.3 MB | 52b3e60dcbd9 |
(the same build: numbers in its first row) |
| fp16 | fp16/decoder_2.engine |
515.6 MB | a34389d0db2f |
(the same build: numbers in its first row) |
| fp16 | fp16/decoder_3.engine |
515.6 MB | 7bdbfbf21f76 |
(the same build: numbers in its first row) |
| fp16 | fp16/decoder_4.engine |
515.6 MB | 78bf718392eb |
(the same build: numbers in its first row) |
| fp16 | fp16/decoder_5.engine |
515.6 MB | c129ee0fa084 |
(the same build: numbers in its first row) |
| fp16 | fp16/decoder_6.engine |
515.6 MB | dc93774329a2 |
(the same build: numbers in its first row) |
| fp16 | fp16/decoder_7.engine |
515.6 MB | 7691149bd05f |
(the same build: numbers in its first row) |
| fp16 | fp16/decoder_8.engine |
515.5 MB | 63770511bf91 |
(the same build: numbers in its first row) |
| fp16 | fp16/decoder_9.engine |
515.4 MB | e87b225b8576 |
(the same build: numbers in its first row) |
| fp16 | fp16/decoder_split.json |
3.1 kB | f0574248d0f9 |
(the same build: numbers in its first row) |
| fp16 | fp16/device_chain.py |
8.3 kB | e675d2e7e2d1 |
(the same build: numbers in its first row) |
| fp16 | fp16/embed.engine |
375.3 MB | a0e019ffc9c3 |
(the same build: numbers in its first row) |
| fp16 | fp16/flow.engine |
791.9 MB | 6a1d5b3944ea |
(the same build: numbers in its first row) |
| fp16 | fp16/pipeline.py |
7.3 kB | b4c6a12e41e1 |
(the same build: numbers in its first row) |
| fp16 | fp16/pipeline_trt.py |
4.7 kB | cbd2a2bfb527 |
(the same build: numbers in its first row) |
| fp16 | fp16/processor_config.json |
0.5 kB | 0fe7ba9aa6b9 |
(the same build: numbers in its first row) |
| fp16 | fp16/sam_1024.engine |
434.7 MB | 7551ee8f9505 |
(the same build: numbers in its first row) |
| fp16 | fp16/sam_768.engine |
430.0 MB | c60fa71c9579 |
(the same build: numbers in its first row) |
| fp16 | fp16/special_tokens_map.json |
0.8 kB | ab4bd57ce17d |
(the same build: numbers in its first row) |
| fp16 | fp16/tokenizer.json |
10.0 MB | a02f8fd5228c |
(the same build: numbers in its first row) |
| fp16 | fp16/tokenizer_config.json |
0.2 MB | a0cbe8464049 |
(the same build: numbers in its first row) |
| fp16 | fp16/trt_runner.py |
4.4 kB | cbc9abb1f59c |
(the same build: numbers in its first row) |
DeepSeek-OCR-2 (DeepSeek: OCR and document conversion; a SAM ViT-B image encoder and a Qwen2 "visual causal flow"
encoder feeding a DeepSeek-V2 MoE decoder) as TensorRT engines built from this model's fp16 ONNX graphs, plus
pipeline_trt.py. The pipeline is the ONNX build's pipeline.py (the repository's infer: crop mode, base size
1024, tile size 768, greedy decoding with no_repeat_ngram_size 35) with every graph run as engines.
import sys
from PIL import Image
sys.path.insert(0, "fp16")
from pipeline_trt import DeepSeekOCR2Trt
ocr = DeepSeekOCR2Trt("fp16")
print(ocr(Image.open("page.png"))) # "<image>\nFree OCR." by default
print(ocr(Image.open("page.png"), "<image>\n<|grounding|>Convert the document to markdown."))
Or python fp16/pipeline_trt.py page.png out.md. It needs numpy, tokenizers, Pillow, TensorRT 10.13
(tensorrt-cu12 or tensorrt-lean-cu12) and Polygraphy. No PyTorch and no ONNX Runtime. The engines are
version-compatible and built for Ampere or newer GPUs (RTX 30-series and up). They hold 8.1 GB, and the benchmark's
process peaked at 12.5 GB of memory, GPU memory included (the ONNX fp16 build: 12.9 GB).
Not faster than the ONNX build. The MoE decoder runs its 64 routed experts densely (the non-selected experts' gates are zero, the same sum as the sparse dispatch), so each generated token reads all 5.5 GB of its weights, in TensorRT as in ONNX Runtime: 2.17 s per page here against 2.11 s for the ONNX fp16 build. This build is for running without ONNX Runtime.
The engines.
sam_1024.engine / sam_768.engine: SAM ViT-B for the padded 1024 px global view and for one 768 px tile; the
pipeline runs a page's tiles (2-6 for pages over 768 px) one at a time, each its own image.flow.engine: the Qwen2 flow encoder and the projector -> image_embeds, view_separator.embed.engine: input_ids [1, S] -> inputs_embeds [1, S, 1280].decoder_0..11.engine: the MoE decoder (12 layers): inputs_embeds [1, S, 1280], past_key_values.{0..11}.key / .value [1, 10, P, 128] (fp16) -> logits of the last position [1, 129280] and present.*. decoder_split.json
gives the order of the pieces and the tensors passed between them. The decoder is cut into pieces of at most 0.7 GB
of weights, so that each engine builds within the build machine's memory.Limits. A prompt up to 1,280 positions (BOS, a 6-tile page's 1,121 image tokens and the prompt's text) and up to 4,096 in all: a page's text stops after about 2,900 tokens (the original allows 8,192 new tokens).
On the GPU. The pipeline (device_chain.py) keeps the decoder's KV cache on the GPU: each step reads one set of
buffers and writes the longer cache into the other, so a step allocates nothing. The activations between the
decoder's pieces never leave the GPU, and the pieces share one working-memory buffer.
Precisions. The decoder, the flow encoder and the embedding are strongly typed: every tensor keeps the precision
the ONNX graph gives it, with the flow encoder's fp16 RMSNorm statistics and softmax computed in fp32, as ONNX
Runtime's kernels compute them. The two SAM engines are built weakly typed, so they compute in fp32. Built strongly
typed from the fp16 graph, TensorRT 10.13's SAM output was unrelated to ONNX Runtime's (0.2 dB on a page): the error
enters between the window attention and its projection. In fp32 it is 26.8 dB from ONNX Runtime's fp16 result.
No int8: TensorRT's int8 needs calibrated activations, and the ONNX int8/ / int4/ builds are weight-only
MatMulNBits, which TensorRT doesn't take.
Benchmark.
| English CER | Chinese CER | text identical to the ONNX fp16 build's | seconds per page | |
|---|---|---|---|---|
ONNX fp16/ (ONNX Runtime CUDA) |
0.0 % | 0.0 % | 12 / 12 | 2.11 |
TensorRT fp16/ |
0.0 % | 0.0 % | 12 / 12 | 2.17 |
The seconds per page include the image encoders, the prompt and every decoding step. The engines load on first use, so the first page's time includes the loading.
From DeepSeek-OCR-2 at revision aaa02f3811: each engine was built with TensorRT's builder from Moonbox's published
ONNX graph of the same model and precision. The network is strongly typed: every tensor keeps the precision the
ONNX graph gives it, so an fp16 engine computes what the fp16 ONNX build computes. Built on an RTX 3080 Laptop GPU,
it was benchmarked against the original before upload, and the sha256 column above is what the files must hash to.
apache-2.0. These files are a derivative of the original model and carry its license: it is copied in this repository, and it governs your use of these files. The original model card follows unchanged.
🌟 Github | 📥 Model Download | 📄 Paper Link | 📄 Arxiv Paper Link |
DeepSeek-OCR 2: Visual Causal Flow
Explore more human-like visual encoding.
Inference using Huggingface transformers on NVIDIA GPUs. Requirements tested on python 3.12.9 + CUDA11.8:
torch==2.6.0
transformers==4.46.3
tokenizers==0.20.3
einops
addict
easydict
pip install flash-attn==2.7.3 --no-build-isolation
from transformers import AutoModel, AutoTokenizer
import torch
import os
os.environ["CUDA_VISIBLE_DEVICES"] = '0'
model_name = 'deepseek-ai/DeepSeek-OCR-2'
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
model = AutoModel.from_pretrained(model_name, _attn_implementation='flash_attention_2', trust_remote_code=True, use_safetensors=True)
model = model.eval().cuda().to(torch.bfloat16)
# prompt = "<image>\nFree OCR. "
prompt = "<image>\n<|grounding|>Convert the document to markdown. "
image_file = 'your_image.jpg'
output_path = 'your/output/dir'
res = model.infer(tokenizer, prompt=prompt, image_file=image_file, output_path = output_path, base_size = 1024, image_size = 768, crop_mode=True, save_results = True)
Refer to 🌟GitHub for guidance on model inference acceleration and PDF processing, etc.
# document: <image>\n<|grounding|>Convert the document to markdown.
# without layouts: <image>\nFree OCR.
We would like to thank DeepSeek-OCR, Vary, GOT-OCR2.0, MinerU, PaddleOCR for their valuable models and ideas.
We also appreciate the benchmark OmniDocBench.
@article{wei2025deepseek,
title={DeepSeek-OCR: Contexts Optical Compression},
author={Wei, Haoran and Sun, Yaofeng and Li, Yukun},
journal={arXiv preprint arXiv:2510.18234},
year={2025}
}
@article{wei2026deepseek,
title={DeepSeek-OCR 2: Visual Causal Flow},
author={Wei, Haoran and Sun, Yaofeng and Li, Yukun},
journal={arXiv preprint arXiv:2601.20552},
year={2026}
}
deepseek-ai/DeepSeek-OCR-2