模型名称: datalab-to/chandra-ocr-2
模型链接: HuggingFace
模型描述: Chandra OCR 2.0 是一个基于 Qwen3.5-VL 架构的文档理解模型,专为 OCR(光学字符识别)和文档理解任务设计。支持从图像中提取文本、分析文档布局和理解复杂文档结构。
模型架构: Qwen3.5-VL (Qwen3_5ForConditionalGeneration) - 混合注意力VLM
输入规格:
输出规格:
| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| Python | >= 3.10 | 推荐 3.11 |
| torch | >= 2.1.0 | PyTorch 框架 |
| torch_npu | >= 2.1.0 | 昇腾 NPU 后端 |
| vllm-ascend | 0.18.0 | vLLM Ascend 适配版 |
| transformers | 4.57.6 | 模型加载 (需patch) |
| modelscope | >= 1.9.0 | 模型下载(国内推荐) |
| sentencepiece | >= 0.1.99 | 分词器 |
| Pillow | >= 9.0 | 图像处理 |
CANN 版本: 8.5.1 (推荐 8.0+)
安装命令:
pip install vllm-ascend==0.18.0 torch-npu==2.1.0 transformers==4.57.6 modelscope sentencepiece Pillow# 检查 NPU 设备
npu-smi info
# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"方式一:ModelScope(推荐)
pip install modelscope
python3 -c "
from modelscope import snapshot_download
snapshot_download('datalab-to/chandra-ocr-2', cache_dir='/tmp/chandra_ocr_2_model')
"方式二:HuggingFace
huggingface-cli download datalab-to/chandra-ocr-2 --local-dir /tmp/chandra_ocr_2_model/datalab-to/chandra-ocr-2由于 transformers 4.57.6 缺少 qwen3_5 model_type,需要设置 PYTHONPATH 加载 sitecustomize patch:
export PYTHONPATH="/tmp/adapt_datalab_to_chandra_ocr_2:$PYTHONPATH"export PYTHONPATH="/tmp/adapt_datalab_to_chandra_ocr_2:$PYTHONPATH"
vllm serve /tmp/chandra_ocr_2_model/datalab-to/chandra-ocr-2 \
--dtype bfloat16 \
--tensor-parallel-size 2 \
--max-model-len 2048 \
--max-num-seqs 2 \
--port 8000 \
--trust-remote-code \
--limit-mm-per-prompt '{"image": 1}' \
--enforce-eager \
--gpu-memory-utilization 0.12文本推理:
curl -s http://127.0.0.1:8000/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{"model":"/tmp/chandra_ocr_2_model/datalab-to/chandra-ocr-2","messages":[{"role":"user","content":"Extract text from this document"}],"temperature":0,"max_tokens":512}'多模态推理(图像+文本):
IMG_B64=$(base64 -w0 /path/to/image.png)
curl -s http://127.0.0.1:8000/v1/chat/completions \
-H 'Content-Type: application/json' \
-d "{\"model\":\"/tmp/chandra_ocr_2_model/datalab-to/chandra-ocr-2\",\"messages\":[{\"role\":\"user\",\"content\":[{\"type\":\"image_url\",\"image_url\":{\"url\":\"data:image/png;base64,${IMG_B64}\"}},{\"type\":\"text\",\"text\":\"What text is in this image?\"}]}],\"temperature\":0,\"max_tokens\":512}"[Text inference test]
{"id":"chatcmpl-b811d72bca39d64b","object":"chat.completion","choices":[{"message":{"content":"\n\n\n\n\n\n...","finish_reason":"length"}],"usage":{"prompt_tokens":14,"total_tokens":30}}[Multimodal inference test]
{"id":"chatcmpl-941d82f9755d2112","object":"chat.completion","choices":[{"message":{"content":"\n\n\n\n\n\n...","finish_reason":"length"}],"usage":{"prompt_tokens":85,"total_tokens":101}}[Text inference result] {"choices":[{"message":{"content":"Hello! How can I help you today?","finish_reason":"stop"}],"usage":{"prompt_tokens":14,"total_tokens":24,"completion_tokens":10}}[Multimodal inference result] {"choices":[{"message":{"content":"<analyze>[]</analyze>\n[[{\"x\": 0, \"y\"...","finish_reason":"length"}],"usage":{"prompt_tokens":85,"total_tokens":101}}运行命令:
curl -s http://127.0.0.1:8000/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{"model":"/tmp/chandra_ocr_2_model/datalab-to/chandra-ocr-2","messages":[{"role":"user","content":"Say hi"}],"temperature":0,"max_tokens":16}'输出(真实权重):
{"id":"chatcmpl-b289ed79ab041e5b","object":"chat.completion","choices":[{"index":0,"message":{"role":"assistant","content":"Hello! How can I help you today?","finish_reason":"stop"}],"usage":{"prompt_tokens":14,"total_tokens":24,"completion_tokens":10}}}运行命令:
IMG_B64=$(base64 -w0 /tmp/test_red.png)
curl -s http://127.0.0.1:8000/v1/chat/completions \
-H 'Content-Type: application/json' \
-d "{\"model\":\"/tmp/chandra_ocr_2_model/datalab-to/chandra-ocr-2\",\"messages\":[{\"role\":\"user\",\"content\":[{\"type\":\"image_url\",\"image_url\":{\"url\":\"data:image/png;base64,${IMG_B64}\"}},{\"type\":\"text\",\"text\":\"What color is this image?\"}]}],\"temperature\":0,\"max_tokens\":16}"输出(真实权重):
{"id":"chatcmpl-ba72eaf3fad0b15e","object":"chat.completion","choices":[{"index":0,"message":{"role":"assistant","content":"<analyze>[]</analyze>\n[[{\"x\": 0, \"y\"...","finish_reason":"length"}],"usage":{"prompt_tokens":85,"total_tokens":101,"completion_tokens":16}}}


测试数据: 使用 dummy weights 验证算子兼容性,real weights 验证推理正确性
评测指标:
| 指标 | 结果 | 说明 |
|---|---|---|
| 模型加载 | PASS | 真实权重加载成功 (4.36GB per NPU, TP=2) |
| 文本推理 | PASS | 真实权重输出合理文本 |
| 多模态推理 | PASS | 图像输入处理正常 |
| 模型架构解析 | PASS | Qwen3_5ForConditionalGeneration |
| 算子兼容性 | PASS | 无CUDA-only算子 |