J
gcw_9PElOpHK/MiniCPM-V-4.6-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

MiniCPM-V-4.6 NPU

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
输入图片 + 文本
输出文本描述/回答

环境依赖

组件版本
Python3.11
torch2.9.0
torch_npu2.9.0.post1
CANN8.5.1
transformers5.15.1
Pillow≥10.0
numpy≥1.26

快速开始

1. 下载模型权重

# 从 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')
"

2. 安装依赖

pip install torch torch_npu transformers pillow numpy

3. 运行推理

# 测试 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

推理结果示例

测试 1:灰色纯色图片

输入: 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.

测试 2:随机彩色噪点图

输入: 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.

测试 3:NPU 设备信息

NPU 设备数: 2
NPU 设备: Ascend910_9362
峰值显存: 2.74 GB
推理精度: bfloat16

目录结构

MiniCPM-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

踩坑记录

#问题原因解决方案
1transformers 报 model_type minicpmv4_6 not recognizedtransformers 4.57.6 不支持该架构升级 transformers 到 5.15.1+
2MiniCPMV4_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 的文本
5NPU 上 TypeError: only integer tensors of a single elementpixel_values 被错误转为 bf16保持 float 输入原生精度,不转 model.dtype
6首次下载大文件 Disk quota exceeded/opt/atomgit 配额不足下载到 /tmp 后复制
7下载 ChunkedEncodingError 连接中断网络不稳定,大文件下载中断用 curl -C - 续传或二次重试

许可证

Apache 2.0