基于官方权重 openbmb/MiniCPM-V-4.6(SigLIP2 视觉编码器 + Qwen3.5 文本主干 + 24 层 hybrid
linear/full attention),在华为 Ascend 910 上做 Ascend NPU 推理验证的镜像。
MiniCPMV4_6ForConditionalGeneration(model_type=minicpmv4_6)full_attention +
19 个 linear_attention),hidden_size=1024,head_dim=256,num_attention_heads=8,
num_key_value_heads=2,vocab_size=248094hidden_size=1152,patch_size=14,image_size=980)model.safetensors ≈ 2.6 GBmkdir -p /data/MiniCPM-V-4.6 && cd /data/MiniCPM-V-4.6
HF_ENDPOINT=https://hf-mirror.com HF_HUB_DOWNLOAD_TIMEOUT=120 \
python3 -c "from huggingface_hub import snapshot_download; \
snapshot_download('openbmb/MiniCPM-V-4.6', local_dir='/data/MiniCPM-V-4.6/models')"
pip install -r requirements.txt依赖:torch 2.9.0 + torch_npu 2.9.0.post1 + CANN 8.5.1 + Ascend 910 驱动。
transformers_version 在 config 中标注为 5.7.0;本仓库按官方建议使用
AutoModel.from_pretrained(..., trust_remote_code=True) 在容器内置的 transformers 4.57.6
上加载(请参考 inference.py 的 _try_load 错误兜底)。
# Ascend NPU
python3 inference.py --device npu --prompt "Describe this image briefly."
# CPU(用于回归测试与精度对比基线)
python3 inference.py --device cpu --prompt "Describe this image briefly."
# 自定义输出
python3 inference.py --device npu --max_new_tokens 32 --outdir outputs脚本会在 outputs/ 下写入 metrics_npu.json 与 metrics_cpu.json:
load_time_s / warmup_time_s / inference_time_s / total_time_slogits_stats(mean / std / min / max)top5_tokens(teacher-forcing 后 logits top-5)sample_text(input_ids decode 样例)| 指标 | NPU | CPU | 差异 |
|---|---|---|---|
| load_time_s | (见 outputs/metrics_npu.json) | (见 outputs/metrics_cpu.json) | — |
| inference_time_s | 同上 | 同上 | — |
| cos_sim | — | — | 来自 compare_logits.py |
| max_abs_err | — | — | 同上 |
| mean_abs_err | — | — | 同上 |
对比脚本会在 NPU 与 CPU 都跑完后,用
outputs/logits_npu.npyvsoutputs/logits_cpu.npy计算余弦相似度与绝对误差,并写回outputs/compare.json。
.
├── inference.py # 双设备推理脚本
├── readme.md # 本文件
├── requirements.txt # 依赖清单
├── models/ # 权重(.gitignore 排除)
└── assets/ # 3 张 2x2 多面板适配信息图config.json 标 transformers_version=5.7.0;容器内为 4.57.6,需以 trust_remote_code
走自定义代码路径;若官方代码需要 transformers ≥ 5.x,会在 _try_load 中失败并把错误
落到 outputs/metrics_*.json,请按报错升级 transformers 后再跑。image_processor;当前 inference.py 默认走 text-only teacher-forcing,
足以产出可比的 logits 与耗时数据。assets/model_result.pngassets/model_result.pngoutputs/compare.json