赛事: 昇腾 Model Agent 模型适配大赛(第二季) 引擎: torch_npu 硬件: Ascend 910B4 标签:
npuascendpytorchtransformers
| 属性 | 值 |
|---|---|
| 原始模型 | HuggingFaceTB/SmolVLM-256M-Instruct |
| 参数量 | 256 M |
| 任务类型 | 多模态视觉语言(图像 + 文本 -> 文本) |
| 输入格式 | RGB 图像 + 文本提示 |
| 输出格式 | 生成文本 |
SmolVLM 是轻量级开源视觉语言模型(Idefics3 架构),融合了强大的视觉编码器与 SmolLM2 语言主干,支持图像理解与对话式多模态推理。本适配在昇腾 NPU (Ascend 910B4)上完成图像描述推理,31 token 约 7.9 s。
⚠️ 本仓库不包含模型权重(交付件仅
inference.py/readme.md/requirements.txt/assets/), 推理前必须先从原始模型仓单独下载权重。
# 1. 下载模型权重(仓库不含权重,必须单独下载)
huggingface-cli download HuggingFaceTB/SmolVLM-256M-Instruct --local-dir ./ --local-dir-use-symlinks False
# 2. 安装依赖
pip install -r requirements.txt -i https://repo.huaweicloud.com/repository/pypi/simple/# 运行 NPU 推理(图像 + 提示 -> 生成文本)
python3 inference.py --model_path . --image test_input.jpg \
--prompt "Describe this image in one sentence." --device npu:0python3 inference.py --model_path . --image test_input.jpg \
--prompt "Describe this image in one sentence." --device npu:0 --max_new_tokens 80预期输出:
[Model Agent] NPU 设备就绪: Ascend910B4 (count=1)
[Model Agent] 模型加载完成 -> npu:0 (Idefics3ForConditionalGeneration)
[Model Agent] 生成文本 (31 tokens):
In this image I can see two giraffes and a zebra standing on the ground. In the background I can see the trees, plants and the sky.
[Model Agent] 推理时延: 7870.8 ms.
├── inference.py # NPU 推理脚本
├── readme.md # 本文件
├── requirements.txt # 依赖清单
└── assets/ # 截图素材本模型由 昇腾 Model Agent 自动完成 NPU 适配:
AutoModelForImageTextToText(Idefics3)+ AutoProcessor,
model.to('npu:0') + torch.no_grad() 自回归生成,attn_implementation="eager"
规避 flash-attn,无 CUDA 依赖。