g
gcw_C8PI9e90/MiniCPM-V-4.6-npu
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

MiniCPM-V-4.6-npu 昇腾 NPU 适配

1. 模型介绍

  • Hugging Face 原始模型:https://huggingface.co/openbmb/MiniCPM-V-4.6
  • GitCode HF 镜像:https://ai.gitcode.com/hf_mirrors/openbmb/MiniCPM-V-4.6
  • GitCode 权重文件:https://ai.gitcode.com/hf_mirrors/openbmb/MiniCPM-V-4.6/blob/main/model.safetensors
  • 任务类型:多模态视觉语言问答
  • 模型框架:PyTorch + torch-npu (Ascend)
  • 模型架构:MiniCPMV4_6ForConditionalGeneration (SigLIP2-400M + Qwen3.5-0.8B, 4x/16x 视觉 token 压缩)
  • 输入格式:见 readme.md 第 3 节
  • 输出格式:见 readme.md 第 3 节
  • 验证环境:Ascend 910, CANN 8.5.1, torch 2.9.0, torch-npu 2.9.0.post1

MiniCPM-V 4.6 端侧多模态模型

2. NPU 适配说明

本仓库提供独立 CPU/NPU 推理脚本与精度对比脚本。测试严格先运行 CPU、释放资源,再运行昇腾 NPU;NPU 计时前后执行同步,结束后释放缓存。

3. 环境准备

python -m pip install -r requirements.txt --index-url "${PIP_INDEX_URL:-https://pypi.tuna.tsinghua.edu.cn/simple}"

4. 推理命令

python inference.py --device cpu --model-dir /path/to/model --output cpu_inference.json
python inference.py --device npu --model-dir /path/to/model --output npu_inference.json

5. CPU/NPU 精度测试

python compare_cpu_npu.py --model-dir /path/to/model --output comparison.json
指标CPUNPU
推理耗时29933.1087 ms1097.5760 ms
精度指标实测值
主指标mean_relative_error_pct
CPU/NPU 主误差0.06906685%
最大相对误差592807.0573%
最大绝对误差0.1839513779
余弦相似度0.9999993726
语义输出一致True

结论:NPU 与 CPU 推理结果误差小于 1%。

6. 性能说明

性能数据与输入大小、批量、预热、模型规模和首次算子编译有关。上表为本次真实运行结果,不作为跨模型性能排名。

7. 执行记录

7.1 Agent 完整适配工作流

Agent 完整适配工作流

7.2 NPU 硬件设备调用日志

NPU 硬件设备调用日志

7.3 模型最终适配验收结果

模型最终适配验收结果