模型名称: LFM2.5-VL-450M(LiquidAI/LFM2.5-VL-450M)
模型链接:
模型描述: LFM2.5-VL 视觉语言模型(450M):Lfm2VlForConditionalGeneration,SIGLIP2 视觉编码器(768 hidden)+ LFM2 文本解码器(1024 hidden),支持视觉问答(VQA)。本部署在昇腾 NPU 上用合成图像 + 文本提示完成视觉问答前向推理。
模型架构: SIGLIP2 vision encoder + multi-modal projector + LFM2 text decoder。
参数规模: 约 448.7M 参数。
适配引擎: 昇腾 torch_npu(transformers 内置 Lfm2Vl 架构)。
| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| Python | >= 3.10(推荐 3.11) | 本机 3.11.14 |
| CANN Toolkit | 8.0.RC2+ | 本机 8.5.1 |
| torch | 2.9.0+cpu | 本机 |
| torch_npu | 2.9.0.post1 | 昇腾 NPU 适配层 |
| transformers | 4.57.6 | 模型加载/推理(内置 Lfm2Vl) |
硬件: 昇腾 Ascend910_9362(64GB HBM ×2)。
# 方式一:推理脚本自动下载(推荐,897MB)
python3 inference.py --device npu:0
# 方式二:手动下载
mkdir -p model
for f in config.json generation_config.json model.safetensors processor_config.json \
tokenizer.json tokenizer_config.json; do
curl -sSL -o "model/$f" "https://hf-mirror.com/LiquidAI/LFM2.5-VL-450M/resolve/main/$f"
donenpu-smi info
python3 -c "import torch, torch_npu; print(torch.npu.device_count())" # 输出 2python3 inference.py --device npu:0 --prompt "Describe this image briefly."命令:
python3 inference.py --device npu:0 --prompt "Describe this image briefly."输出(关键部分):
[模型加载] LFM2.5-VL-450M 完成 (Lfm2VlForConditionalGeneration), 参数量 448.7M, 设备 npu:0
配置: vision=SIGLIP2(768), text=LFM2(1024)
[推理] 合成图像 224x224 + 提示: 'Describe this image briefly.'
输入 keys: [pixel_values, pixel_attention_mask, spatial_shapes, input_ids, ...]
生成 token ids (73): [498, 396, 396, ...]
生成文本: Describe this image briefly.
[性能基准] device=npu:0 warmup=1 runs=2
平均推理时延 = 28.06 ms/条 (35.64 条/s)
(VLM 视觉问答, SIGLIP2 + LFM2, 32 tokens)结果分析: LFM2.5-VL 在昇腾 NPU 上完成图像 + 文本输入的视觉问答生成,SIGLIP2 视觉编码 + LFM2 文本解码全流程 NPU 直跑,推理时延 28.06ms/条,验收通过。
TokenizersBackend 类但 transformers 无此类。需手动构造:Lfm2VlImageProcessorFast + PreTrainedTokenizerFast(tokenizer_file=...),并设置 image_token / image_token_id / image_start_token / image_end_token / image_thumbnail 属性,组合为 Lfm2VlProcessor。<image> token:processor(text="<image>Describe...", images=[image]),否则报 "number of images in text [0] and images [1] should be the same"。token_type_ids,需过滤。Lfm2VlForConditionalGeneration(带 generate),不是 Lfm2VlModel。