基于 Qwen3.5 的多模态 OCR 模型,适配华为昇腾 NPU(Ascend 910B/910C)
原始模型: datalab-to/chandra-ocr-2
昇腾适配: liuhongwei-2026/chandra-ocr-2
chandra-ocr-2 是一个基于 Qwen3.5 架构的多模态 OCR 模型,能够从图像中识别并提取文字信息。模型特点:
| 组件 | 版本 |
|---|---|
| OS | Ubuntu 22.04 / EulerOS |
| 昇腾驱动 | CANN 8.5.1+ |
| Python | 3.10+ |
| PyTorch | 2.5.0+ |
| torch_npu | 2.5.0+ |
| vLLM | 0.18.0+ |
| vLLM-Ascend | 0.18.0+ |
# 方式一:从 HuggingFace 镜像下载
HF_ENDPOINT=https://hf-mirror.com huggingface-cli download datalab-to/chandra-ocr-2 --local-dir /path/to/chandra-ocr-2
# 方式二:从 ModelScope 下载
python -c "from modelscope import snapshot_download; snapshot_download('datalab-to/chandra-ocr-2', cache_dir='/data/.cache/models')"
# 方式三:从 GitCode 镜像(需 git-lfs)
git clone https://gitcode.com/hf_mirrors/datalab-to/chandra-ocr-2.git /path/to/chandra-ocr-2# 单卡部署(推荐)
vllm serve /path/to/chandra-ocr-2 \
--port 8000 \
--dtype bfloat16 \
--max-model-len 32768 \
--max-num-seqs 8 \
--enforce-eager \
--trust-remote-code \
--served-model-name chandra-ocr-2
# 如需指定 NPU 设备
CUDA_VISIBLE_DEVICES=0 vllm serve /path/to/chandra-ocr-2 \
--port 8000 \
--dtype bfloat16 \
--max-model-len 32768 \
--max-num-seqs 8 \
--enforce-eager \
--trust-remote-code \
--served-model-name chandra-ocr-2使用 inference.py 脚本:
# 检查服务健康状态
python inference.py --server http://127.0.0.1:8000 --health
# 图片 OCR 识别
python inference.py \
--server http://127.0.0.1:8000 \
--image /path/to/test.png \
--prompt "请识别图片中的文字内容"
# 自定义提示词
python inference.py \
--server http://127.0.0.1:8000 \
--image /path/to/document.jpg \
--prompt "请提取图片中的表格数据"直接调用 REST API:
# 图片 OCR
IMAGE_BASE64=$(base64 -w0 /path/to/image.jpg)
curl -s http://127.0.0.1:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "chandra-ocr-2",
"messages": [
{
"role": "user",
"content": [
{"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,'"$IMAGE_BASE64"'"}},
{"type": "text", "text": "请识别图片中的文字内容"}
]
}
],
"max_tokens": 1024,
"temperature": 0
}' | python3 -m json.toolvLLM-Ascend 0.18.0 已原生支持 Qwen3.5 系列模型,包括:
| 特性 | 状态 |
|---|---|
| 全注意力层 | ✅ 原生支持 |
| Gated Delta Net(线性注意力) | ✅ vllm-ascend 自定义算子 |
| 视觉编码器(ViT) | ✅ 原生支持 |
| 多模态输入(文本+图片) | ✅ 原生支持 |
| bfloat16 推理 | ✅ 支持 |
| 连续批处理 | ✅ 支持 |
| 张量并行 | ✅ 支持 |
--enforce-eager 模式 | ✅ 推荐 |
截图后续补充
vllm serve 成功加载模型| 参数 | 值 |
|---|---|
| 基础架构 | Qwen3_5ForConditionalGeneration |
| 参数量 | ~4B(含视觉编码器) |
| 文本层数 | 32 |
| 注意力头数 | 16 |
| KV 头数 | 4 (GQA) |
| 视觉层数 | 24 |
| 视觉 patch_size | 16 |
| 词表大小 | 248320 |
| 权重大小 | ~4.7 GB (bf16) |