周红伟:企业大模型微调和部署, DeepSeek-OCR v2技术原理和架构,部署案例实操。RAG+Agent智能体构建

复制代码
DeepSeek-OCR 发布于25年10月,而这次DeepSeek-OCR 2发布仅隔了三个月。这会不会是DeepSeek V4发布前上的前菜呢?让我们一起尝尝鲜吧。


DeepSeek发布全新DeepSeek-OCR 2模型,采用创新的DeepEncoder V2方法,让AI能够根据图像的含义动态重排图像的各个部分,而不再只是机械地从左到右扫描。这种方式模拟了人类在观看场景时所遵循的逻辑流程。最终,该模型在处理布局复杂的图片时,表现优于传统的视觉-[语言模型](https://so.csdn.net/so/search?q=%E8%AF%AD%E8%A8%80%E6%A8%A1%E5%9E%8B&spm=1001.2101.3001.7020),实现了更智能、更具因果推理能力的视觉理解。

github地址:https://github.com/deepseek-ai/DeepSeek-OCR-2

DeepSeek-OCR 2: Visual Causal Flow

Explore more human-like visual encoding.

<>Contents

<>Install

Our environment is cuda11.8+torch2.6.0.

  • Clone this repository and navigate to the DeepSeek-OCR-2 folder

    git clone https://github.com/deepseek-ai/DeepSeek-OCR-2.git

  • Conda

    conda create -n deepseek-ocr2 python=3.12.9 -y
    conda activate deepseek-ocr2

  • Packages

  • download the vllm-0.8.5 whl

    pip install torch==2.6.0 torchvision==0.21.0 torchaudio==2.6.0 --index-url https://download.pytorch.org/whl/cu118
    pip install vllm-0.8.5+cu118-cp38-abi3-manylinux1_x86_64.whl
    pip install -r requirements.txt
    pip install flash-attn==2.7.3 --no-build-isolation

Note: if you want vLLM and transformers codes to run in the same environment, you don't need to worry about this installation error like: vllm 0.8.5+cu118 requires transformers>=4.51.1

<>vLLM-Inference

  • VLLM:

Note: change the INPUT_PATH/OUTPUT_PATH and other settings in the DeepSeek-OCR2-master/DeepSeek-OCR2-vllm/config.py

复制代码
cd DeepSeek-OCR2-master/DeepSeek-OCR2-vllm
  • image: streaming output

    python run_dpsk_ocr2_image.py

  • pdf: concurrency (on-par speed with DeepSeek-OCR)

    python run_dpsk_ocr2_pdf.py

  • batch eval for benchmarks (i.e., OmniDocBench v1.5)

    python run_dpsk_ocr2_eval_batch.py

<>Transformers-Inference

  • Transformers

    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 = "\nFree OCR. "

    prompt = "\nConvert 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)

or you can

复制代码
cd DeepSeek-OCR2-master/DeepSeek-OCR2-hf
python run_dpsk_ocr2.py

<>Support-Modes

  • Dynamic resolution
    Default: (0-6)×768×768 + 1×1024×1024 --- (0-6)×144 + 256 visual tokens ✅
相关推荐
飞奔的猫几秒前
锈了儿—游戏素材用的在线图形处理工具
图像处理·人工智能·游戏美术
ACP广源盛139246256732 分钟前
Qwen3.8‑2.4T 开源落地@ACP#国产 Serdes 长距离视频传输芯片 GSV5800 在私有化 AI 服务中的价值与应用场景
大数据·数据库·人工智能·嵌入式硬件·矩阵·开源·音视频
shxjnpl3 分钟前
AI会议助手选型的三个“容易被宣传页隐藏”的指标
人工智能·机器学习·语音识别·智能硬件
千桐科技6 分钟前
DataX组件扩展、任务日志优化与部署能力完善,qData开源版数据中台V1.6.1版本解析!
大数据·开源·数据治理·开源项目·数据中台·qdata
AIHR数智引擎7 分钟前
如何用WorkBuddy跑通HR自动化流程?
人工智能·经验分享·chatgpt·职场和发展·自动化·ai-native
ClouGence9 分钟前
不用编程,物理老师也能用AI一键生成交互式课件
人工智能·html·aigc
汽车仪器仪表相关领域9 分钟前
ZDT‑I伺服电机测试系统:四象限动态加载
大数据·数据库·分布式·功能测试·汽车·压力测试·可用性测试
九硕智慧建筑一体化厂家12 分钟前
大型建筑集群智慧管控升级!IBMS系统实现多系统一体化融合管理
运维·人工智能·笔记·智慧城市
名字还没想好☜15 分钟前
Java 21 switch 模式匹配实战:sealed 接口 + record 替代 if-instanceof 链
java·人工智能·后端·python·spring
梦想出海-Phoebe16 分钟前
GPT-5.6 Sol突然降价,AI API价格战开始了?
人工智能