SmolVLM-256M-Instruct 是 HuggingFaceTB 发布的一系列轻量级视觉-语言模型(VLM)中的最小可部署成员。它以 Idefics3 架构为基础:视觉侧采用 SigLIP 风格的视觉塔(输入 512×512、patch 16×16,12 层 Transformer,hidden 768),文本侧采用 SmolLM2 风格的稠密自回归解码器(30 层、hidden 576、9 个注意力头、vocab 49280),通过一个 modality projection 连接器把图像 patch 特征映射进文本语义空间。scale_factor=4 表示每个图像 patch 展开为 4 个图像 token,image_token_id=49190 用于在输入序列中标记图像位置。
本仓库将官方权重(HuggingFaceTB/SmolVLM-256M-Instruct,单文件 safetensors,513,028,808 字节)在 昇腾 Ascend NPU 上完成部署适配,采用 vLLM-Ascend 服务化推理 形态,对外暴露 OpenAI 兼容的 /v1/chat/completions 接口,支持单图多轮图文对话。
| 属性 | 值 |
|---|---|
| 模型名 | SmolVLM-256M-Instruct |
| 架构 | Idefics3ForConditionalGeneration(model_type=idefics3) |
| 文本骨干 | hidden=576 / layers=30 / heads=9 / kv_heads=3 / max_len=8192 |
| 视觉骨干 | hidden=768 / layers=12 / patch=16 / image_size=512 |
| 连接器 | modality_projection(proj.weight) |
| 图像 token | image_token_id=49190,scale_factor=4,单图≈4096 token |
| 权重文件 | model.safetensors(513,028,808 字节,单文件) |
| 加载后权重 | 0.48 GB(bf16) |
| 部署形态 | vLLM-Ascend 0.18.0 · chat/completions · OpenAI 兼容接口 |
SmolVLM-256M-Instruct 的 config.json 声明 architectures=["Idefics3ForConditionalGeneration"]、model_type=idefics3。在 vLLM 0.18.0 的模型注册表中,Idefics3ForConditionalGeneration 已映射到 idefics3 模型实现(vllm/model_executor/models/idefics3.py),架构原生受支持,无需新增或改写模型代码,本次工作属于「权重拉取 + 服务化 + 验证」的完整适配链路:
nn.Linear、nn.LayerNorm、nn.Embedding、视觉塔的 nn.Conv2d(patch embedding)以及标准 attention 算子,均为昇腾原生算子,无 CUDA/Triton 专属内核,算子门禁通过。ai.gitcode.com/hf_mirrors/HuggingFaceTB/SmolVLM-256M-Instruct)→ ModelScope → HuggingFace 的顺序尝试;本次实测 GitCode 镜像对连续请求触发 429 限流,遂按既定回退顺序从 ModelScope(HuggingFaceTB/SmolVLM-256M-Instruct)完成拉取,本地单文件 safetensors 校验通过。npu-smi 物理设备 Phy-ID 为 12/13,torch_npu 通过 ASCEND_RT_VISIBLE_DEVICES(逻辑索引)做映射;本次指定逻辑索引 1 即物理 davinci13,避开同机其他任务占用的 davinci12。| 组件 | 版本 |
|---|---|
| 操作系统 | openEuler(Linux 5.10.0,aarch64) |
| 昇腾设备 | Ascend910 ×2(Atlas 800,单卡 HBM 64GB) |
| CANN | 8.5.1(npu-smi 25.5.5) |
| Python | 3.11.14 |
| PyTorch | 2.9.0 |
| torch_npu | 2.9.0.post1 |
| vLLM | 0.18.0 |
| vLLM-Ascend | 0.18.0 |
| transformers | 4.57.6 |
pip install -r requirements.txtexport ASCEND_RT_VISIBLE_DEVICES=1 # 逻辑索引 1 = 物理 davinci13(空闲卡)
export PYTORCH_NPU_ALLOC_CONF=expandable_segments:True
vllm serve /path/to/SmolVLM-256M-Instruct \
--host 0.0.0.0 \
--port 8383 \
--served-model-name SmolVLM-256M-Instruct \
--tensor-parallel-size 1 \
--max-model-len 8192 \
--max-num-seqs 8 \
--gpu-memory-utilization 0.2 \
--limit-mm-per-prompt '{"image": 1}' \
--trust-remote-code \
--seed 42启动后暴露的接口:
GET /v1/models —— 就绪检查与模型信息POST /v1/chat/completions —— 图文对话推理(消息 content 支持 text 与 image_url 多模态条目)python inference.py --prompt "Describe this picture." --image scene.png服务启动后的最小验证:
# 1. 就绪检查
curl -sf http://127.0.0.1:8383/v1/models
# {"object":"list","data":[{"id":"SmolVLM-256M-Instruct",...,"max_model_len":8192,...}]}
# 2. 纯文本对话
curl -s -X POST http://127.0.0.1:8383/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model":"SmolVLM-256M-Instruct","messages":[{"role":"user","content":"What is a large language model? Answer in one sentence."}],"max_tokens":80}'
# 3. 图文对话(图片以 base64 data-URI 传入)
python inference.py --prompt "What is in this image?" --image sunset_scene.png实测一次图文推理:
prompt : Describe what you see in this picture, including the colors, objects and scene.
response: A rectangular piece of art depicting two mountains and the sun in the background.
prompt_tokens: 1151 completion_tokens: 16 total_tokens: 1167
latency : 267.0 ms模型正确识别出图像中的「太阳」与「两座山」及其相对关系,图文理解链路完整可用。
在 Atlas 800(Ascend910,davinci13 单卡)上对已部署服务的实测(n=10,热调用,单图 512×512 + 文本提示,max_tokens=120):
| 指标 | 数值 |
|---|---|
| TTFT P50 | 58.0 ms |
| TTFT P90 | 59.4 ms |
| 总延迟 P50 | 228.6 ms |
| 总延迟 P90 | 260.6 ms |
| 吞吐 | 44.39 req/s |
--gpu-memory-utilization 0.2 预分配决定),空闲态 AICore ≈ 0%。SmolVLM-256M-Instruct 为 256M 量级的轻量图文模型,vLLM-Ascend 端以 bf16 运行。功能/精度验证采用图文理解定性比对(模型输出与图像内容语义一致性检查):
| 测试输入 | 模型输出 | 判定 |
|---|---|---|
| 落日场景图(太阳+两座山+湖面) | "A rectangular piece of art depicting two mountains and the sun in the background." | 正确识别主要对象与空间关系 |
| 含 "Ascend NPU" 文字图 | "Ascent NPU." | 正确识别图中文字(OCR 语义) |
| 纯文本 "What is a large language model?" | "A large language model is a computer program that can understand and generate text..." | 语义正确、语句通顺 |
说明:受模型参数量限制,生成文本偏简洁,偶有同义改写(如 "Ascent NPU"),不影响理解正确性;如需更高精度,建议选用 SmolVLM 更大尺寸版本。
ASCEND_RT_VISIBLE_DEVICES(逻辑索引 0/1)映射物理卡(本机 Phy-ID 12/13),启动前请用 npu-smi info 确认空闲卡,勿与同机其他任务冲突。--port 调整。max-model-len;--max-model-len 8192 下单图 + 文本约 1150 输入 token。--limit-mm-per-prompt 格式:vLLM-Ascend 需使用 JSON 字符串格式 '{"image": 1}',旧写法 image=1 会被拒绝。感谢 HuggingFaceTB 团队开源 SmolVLM 系列模型;本仓库的部署与验证基于昇腾 CANN / vLLM-Ascend 生态完成。