gcw_mXoV1I2Z/MiniCPM-V-4.6
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

MiniCPM-V-4.6 昇腾 NPU 适配

MiniCPM-V 4.6 是 openbmb 推出的面向端侧部署的多模态大模型(基于 SigLIP2-400M 视觉编码器与 Qwen3.5-0.8B LLM),支持单图 / 多图 / 视频理解,并引入混合 4x/16x 视觉 token 压缩。

本仓库提供 昇腾 NPU(Ascend910 / torch_npu) 环境下的推理适配。

适配要点

  • 设备迁移:模型与输入 Tensor 全部迁移至 npu:0,入口 import torch_npu + torch.npu.set_device(0),异常时抛出 RuntimeError 提示 CANN/torch-npu 环境问题。
  • 依赖升级:MiniCPM-V-4.6 需要 transformers>=5.7.0(内置 minicpmv4_6 架构,config 中 auto_map 为空,不能依赖 trust_remote_code)。
  • 推理路径:采用 README 推荐的 AutoModelForImageTextToText + AutoProcessor + model.generate(downsample_mode="16x",max_slice_nums=36)。
  • CUDA 清理:全工程不包含任何 .cuda() / torch.cuda.* / CUDA_VISIBLE_DEVICES 等 CUDA 调用。

推理

# 命令行单图推理
python inference.py --img /path/to/image.png

# FastAPI 服务
uvicorn inference:app --host 0.0.0.0 --port 8000
curl -F "file=@/path/to/image.png" http://127.0.0.1:8000/predict

依赖声明见 requirements.txt(含 torch_npu、transformers>=5.7.0、fastapi、uvicorn、pillow 等)。

验证结果

  • CLI 推理:python inference.py --img test_input.png 输出结构化 JSON(设备 npu:0)。
  • FastAPI:POST /predict 返回 200 OK 与推理 JSON。
  • 证据截图见 assets/(agent_workflow.png / npu_device_call.png / model_result.png)。