z
zyzoe/MiniCPM-V-4.6
模型介绍
文件和版本
Pull Requests
讨论
分析

MiniCPM-V-4.6 昇腾 NPU 适配

模型简介

MiniCPM-V-4.6 是面壁智能开源的高效多模态视觉语言模型(VLM),采用 NaViT 风格视觉编码器(SigLIP 底座)+ Qwen3.5 线性/全注意力混合文本主干,支持中英文图像理解与对话。

  • 原始权重地址(HuggingFace):https://huggingface.co/openbmb/MiniCPM-V-4.6
  • 参数量:1.300B(fp16 权重约 2.6GB)
  • 官方 modeling:transformers 5.7.0 原生 transformers.models.minicpmv4_6(MiniCPMV4_6ForConditionalGeneration),无需 trust_remote_code

验证环境

项目版本
NPUAscend 910(64GB HBM)
CANN8.5.1
torch / torch_npu2.9.0 / 25.5.5 配套
transformers5.7.0
Python3.11.14

推理引擎:torch_npu(PyTorch 原生 npu:0 设备,fp16)。

环境依赖

见 requirements.txt。核心:torch、torch_npu、transformers==5.7.0、pillow。

推理操作流程

export PYTHONPATH=/tmp/tf5            # transformers 5.7.0(含 minicpmv4_6 原生实现)
source /usr/local/Ascend/cann-8.5.1/set_env.sh
export MINICPMV46_MODEL_DIR=/tmp/bigw/MiniCPM-V-4.6   # 已下载权重目录
python inference.py --device npu

inference.py 自动完成:权重加载(fp16 → npu:0)→ 严格加载审计 → 合成 PIL 图 + 中/英 prompt 生成 → 重复度检查 → 性能统计,结果写入 /tmp/minicpmv46_npu_results.json。

加载正确性门禁

  • 门禁 1(strict load):output_loading_info 实测 missing=0 / unexpected=0 / mismatched=0(0/0/0),618+ 全部张量逐一对齐。
  • 门禁 2(config 落地审计):config.json 顶层键全部生效(vision_config/text_config 以嵌套子 config 对象形式落地,为预期行为,其内部字段逐一核对一致)。
  • 门禁 3(功能性对照):合成图仅含 3 个几何图形(红矩形/绿三角/蓝圆 + 白色横线),模型输出逐一准确命中全部三个形状、颜色与位置——图像内容与文字输出强绑定,随机初始化或错载权重不可能产生,构成决定性功能证据。

昇腾 NPU 真实输出(测试用例)

输入:程序合成的 640×480 PIL 图(深蓝背景、红色矩形左下、绿色三角中部、蓝色圆右侧、白色水平线)。

用例 1(中文):详细描述这张图片中的所有形状、颜色和它们的位置。

这张图片呈现了一个深蓝色背景,上面分布着几个几何图形……1. 一个红色的矩形:位于图像左下角,有白色的边框,内部填充红色……2. 一个绿色的三角形:位于图像中央偏右,部分重叠在蓝色的圆体上……

用例 2(英文):Describe all shapes, colors and their positions in this image.

  1. Green Triangle — green triangular shape, positioned slightly to the right and centered horizontally, overlapping with a blue circle. 2. Blue Circle — a large blue circular shape, located to the right of the green triangle……

重复度检查:中文 4-gram diversity = 0.97,英文 = 0.73,输出非退化、无复读。

NPU 性能(fp16, npu:0)

指标数值
预热5 次
正式测次20 次
单次生成 16 tokenavg 0.578s / p50 0.578s / min 0.569s / max 0.594s
生成吞吐27.67 tok/s
峰值 HBM(torch.npu allocator)2.6 GB
96 token 首轮完整生成6.3s(zh)/ 4.8s(en),含算子编译后稳态

截图

  • assets/agent_workflow.png:模型上卡日志(权重解析 → fp16 加载 → npu:0)
  • assets/npu_device_call.png:npu-smi 实时占用 + torch_npu 设备断言
  • assets/model_result.png:真机 NPU 推理输出

#NPU