MiniCPM-V-4.6 是 openbmb 推出的多模态视觉语言模型(VLM),基于 Qwen3.5 文本架构 + 自研视觉塔,约 1.3B 参数,支持中英双语图文理解与推理。
本仓库提供在 昇腾 Ascend910 NPU 上的完整推理适配方案,基于 torch_npu 引擎,无需额外 CUDA 依赖。
| 属性 | 值 |
|---|---|
| 模型名称 | openbmb/MiniCPM-V-4.6 |
| 模型类型 | 视觉语言模型(VLM) |
| 参数量 | 1.3B |
| 架构 | MiniCPMV4_6ForConditionalGeneration |
| 文本骨干 | Qwen3.5 (Transformer) |
| 视觉塔 | MiniCPMV4_6Vision (27 层 ViT) |
| 支持语言 | 中文、英文 |
| 上下文长度 | 262144 tokens |
| 输入 | 图片 + 文本 |
| 输出 | 文本描述/回答 |
| 组件 | 版本 |
|---|---|
| Python | 3.11 |
| torch | 2.9.0 |
| torch_npu | 2.9.0.post1 |
| CANN | 8.5.1 |
| transformers | 5.15.1 |
| Pillow | ≥10.0 |
| numpy | ≥1.26 |
# 从 hf-mirror.com 镜像下载
HF_ENDPOINT=https://hf-mirror.com python3 -c "
from huggingface_hub import snapshot_download
snapshot_download('openbmb/MiniCPM-V-4.6',
ignore_patterns=['onnx/', 'openvino/', '*.h5', 'pytorch_model.bin'],
local_dir='./model')
"pip install torch torch_npu transformers pillow numpy# 测试 1:随机图片 + 英文提示
python3 inference.py
# 测试 2:指定图片 + 自定义提示
python3 inference.py --image demo.jpg --prompt "What is in this image?"
# 测试 3:fp16 精度推理
python3 inference.py --dtype fp16 --max_new_tokens 100输入: 224x224 灰色图片 + "Describe this image"
输出:
The image provided is entirely gray and lacks visible content or detail. It appears to be a blank or empty gray background with no distinct objects.
输入: 224x224 随机彩色图 + "Describe this image in detail"
输出:
The image appears to be a random, textured pattern composed of small, scattered dots in various colors, including shades of purple, blue, and green.
NPU 设备数: 2
NPU 设备: Ascend910_9362
峰值显存: 2.74 GB
推理精度: bfloat16MiniCPM-V-4.6-NPU/
├── inference.py # 推理脚本(调用 torch_npu)
├── readme.md # 部署说明文档(本文件)
├── requirements.txt # 环境依赖清单
└── assets/ # 截图素材
├── agent_workflow.png
├── npu_device_call.png
├── model_result.png
├── agent_usage_1.png
├── agent_usage_2.png
└── agent_usage_3.png| # | 问题 | 原因 | 解决方案 |
|---|---|---|---|
| 1 | transformers 报 model_type minicpmv4_6 not recognized | transformers 4.57.6 不支持该架构 | 升级 transformers 到 5.15.1+ |
| 2 | MiniCPMV4_6Model 无 generate 方法 | 需用 MiniCPMV4_6ForConditionalGeneration 类 | 直接用该类加载 |
| 3 | 处理器 TypeError: got multiple values for argument 'images' | 传参格式错误 | 先 apply_chat_template 再 processor(images=[], text=...) |
| 4 | 推理 Mulitmodal features and tokens do not match | 输入中未包含 <|image_pad|> token | 确保用 apply_chat_template 生成含 image token 的文本 |
| 5 | NPU 上 TypeError: only integer tensors of a single element | pixel_values 被错误转为 bf16 | 保持 float 输入原生精度,不转 model.dtype |
| 6 | 首次下载大文件 Disk quota exceeded | /opt/atomgit 配额不足 | 下载到 /tmp 后复制 |
| 7 | 下载 ChunkedEncodingError 连接中断 | 网络不稳定,大文件下载中断 | 用 curl -C - 续传或二次重试 |
Apache 2.0