DeepSeek-OCR 2: 视觉因果流

使用方法

基于Huggingface transformers库在NVIDIA GPU上进行推理。测试环境要求为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
python 复制代码
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)

vLLM

参考 🌟GitHub 获取模型推理加速和PDF处理等指南。

支持模式

  • 动态分辨率
    • 默认:(0-6)×768×768 + 1×1024×1024 --- (0-6)×144 + 256 视觉令牌 ✅

主要提示词

python 复制代码
# document: <image>\n<|grounding|>Convert the document to markdown.
# without layouts: <image>\nFree OCR.

致谢

我们感谢 DeepSeek-OCR、Vary、GOT-OCR2.0、MinerU、PaddleOCR 提供的宝贵模型和思路。

同时感谢基准测试集 OmniDocBench。

相关推荐
问天_观心2 小时前
大模型训练与推理优化(二)
人工智能·深度学习·学习·大模型·transformer
欣欣之王来了2 小时前
AI合规专项:AI算法透明度的合规要求
人工智能·算法
threerocks2 小时前
【FDE 实战课|第 01 讲】从 Palantir 到 OpenAI:FDE 的来历与全球版图
人工智能·aigc·ai编程
果霸大叔2 小时前
做了六年 K8s,我重新理解了 Agent Harness:都是把"工程化"抽离出来,让开发者专心写业务
人工智能
甲维斯2 小时前
不错不错!GPT6.1Sol的测试结果来了!
人工智能
threerocks2 小时前
【FDE 实战课|第 02 讲】为什么模型越强,越需要有人进现场
人工智能·aigc·ai编程
木头科技2 小时前
【AI 工程化第五篇】Spring AI Agent 生产治理实战:限流、熔断、降级、灰度、多模型路由和安全边界
人工智能·安全·spring
陆卿之2 小时前
Java对接DeepSeek
java·开发语言·人工智能
Leo.yuan3 小时前
企业可信Data Agent怎么建:可信分析智能体(Traceable Analytic Agent)的分析链路与验证机制
大数据·人工智能·机器学习
u1301303 小时前
AI 日报(2026年9月23日)
人工智能