#NPU Ascend910 MiniCPM-V Vision-Language Model
MiniCPMV4_6ForConditionalGeneration (3B params, vision 27 layers, text 24 layers, Mamba linear attention + full attention)model.safetensors 2.5 GB (2600957528 bytes), config.json model_type minicpmv4_6, processor MiniCPMV4_6Processornpu:036f34a661a4bd35d0dc2294cb044d2584646c7d3 (2026-08-17)npu:0, 64GB HBM, 驱动 25.5.5, CANN 8.5.1torch_npu 2.9.0.post1+gitee7ba04huggingface_hub 1.28.0, tokenizers 0.22requirements.txt (pip install -r requirements.txt)working/openbmb-MiniCPM-V-4.6 或 /tmp/minicpm_download (2.5G), 自动检测pip install -r requirements.txt默认在 npu:0 执行, 自动查找本地模型:
python inference.py
# 或显式指定
python inference.py --device npu:0
# CPU 基线
python inference.py --device cpu
# 一致性验证
python inference.py --mode validate
# 性能基准 (warmup 3, 10 iters, synchronized)
python inference.py --mode benchmark模型首次加载会编译, 计时前后调用 torch.npu.synchronize().
输入 (固定可复现):
<|im_start|>user\n<|image_pad|>\nDescribe this image briefly.<|im_end|>\n<|im_start|>assistant\n<think>\n\n</think>\n\ninput_ids [1,87], pixel_values [1,3,14,14336], attention_mask [1,87]NPU 输出 (npu:0, float16, synchronized 1594 ms 首轮, 1044 ms 稳定均值, 需编译):
output_ids shape [1,107], device npu:0decoded: user\n0\nDescribe this image briefly.\nassistant\n<think>\n\n</think>\n\nThe image shows a large yellow square centered within a blue border. Inside the yellow square, the wordCPU 基线 (相同权重/输入/seed, float16, 768 ms):
decoded 完全相同: The image shows a large yellow square centered within a blue border. Inside the yellow square, the wordmodel.safetensors), 同输入 (448图, 同prompt), 同dtype float16, 同随机种子, model.eval() + torch.no_grad() + do_sample=False (deterministic)[248045,846,198,...,760,2099,4774,264,3349,13358,9057,29203,2785,264,6105,3755,13] (87+20)PASS (smoke consistency, 单样本固定输入, 非完整数据集评测)python inference.py --mode validate (内部同时验证视觉塔在 NPU, 语言模型在 NPU, 无 CPU fallback)[COMPARE] CPU ids len 107, NPU ids len 107, exact match: True
[PASS] CPU-NPU token exact match
[PASS] Validation passednpu:0, float16, batch 1, 图片 448x448, 输入 87 tokens, 输出 20 tokens, torch.npu.synchronize() 前后计时latencies ms: [992.28, 1049.07, 1051.78, 1046.37, 1035.79, 1059.25, 1040.96, 1057.46, 1062.28, 1053.92]
avg 1044.92 min 992.28 max 1062.28 p50 1050.42 p90 1059.55 p95 1060.92
tokens/s 19.14, images/s 0.96
首轮编译延迟: 1594 ms (含模型加载后首次 generate, 含编译缓存), 稳定延迟 1044 msmodel.generate, 不含 processor (processor ~5 ms)ArgSort AiCpu 提示但为可接受 (非静默降级)截图由 scripts/render_xterm_evidence.mjs --style raw 根据本次真实日志渲染, 非手工绘制。

agent_workflow.png: 下载、侦察、CPU/NPU 加载、一致性、benchmark 全流程日志npu_device_call.png: npu-smi info + torch.npu.is_available() + 模型参数 npu:0 设备验证model_result.png: python inference.py 默认 NPU 推理真实输出transformers>=5.7.0 才能识别 minicpmv4_6; 旧版本无法加载max_new_tokens 限制, 长文本可能分叉但首20 tokens 已验证一致ArgSort 在 AiCpu 执行为预期 (int32 排序), 非错误, 不影响结果正确性flash-linear-attention 加速, 使用 torch 原生实现#NPU #Ascend #Ascend910 #VLM #MiniCPM #vision-language