w
gcw_uQ09W7jl/LiquidAI-LFM2.5-VL-450M-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

LiquidAI/LFM2.5-VL-450M on Ascend NPU

1. 模型简介

LFM2.5-VL-450M 是 Liquid AI 的刷新版视觉语言模型,基于 LFM2.5-350M 语言骨干 + SigLIP2 NaFlex 86M 视觉编码器,支持 32K 上下文、512x512 原生分辨率、tiling 策略和可调 image token。支持指令跟随、多语言视觉理解、边界框预测和纯文本函数调用。权重 897MB (bfloat16),验证为 vision-language 路线。

  • LM Backbone: LFM2.5-350M (16层, hidden 1024, conv+attention 混合)
  • Vision encoder: SigLIP2 768/12层
  • Projector: 2层 MLP 3072->2048->1024
  • 官方镜像: https://huggingface.co/LiquidAI/LFM2.5-VL-450M

本仓库适配到单卡 Ascend910B (npu:0),实测 bfloat16 可用,CPU/NPU 输出一致,NPU 加速 52x。

2. 验证环境

  • NPU: Ascend910_9362 x2, npu-smi 25.5.5, CANN 8.5.1
  • torch 2.9.0+cpu, torch_npu 2.9.0.post1
  • transformers 5.7.0, pillow, huggingface_hub, safetensors
  • 显存: 65GB total, 空闲 65GB, 模型权重 0.84GiB, 峰值 <4GB
  • 系统: aarch64, Python 3.11.14

3. 安装依赖

pip install -r requirements.txt
# requirements: torch, torch_npu, transformers>=5.1.0, accelerate, pillow, numpy, huggingface_hub, safetensors

模型下载 (必须设 HF_ENDPOINT):

HF_ENDPOINT=https://hf-mirror.com python3 -c "from huggingface_hub import snapshot_download; snapshot_download(repo_id='LiquidAI/LFM2.5-VL-450M', local_dir='./model_cache/LiquidAI-LFM2.5-VL-450M', max_workers=1)"

4. NPU 推理

python inference.py
# 或指定设备
python inference.py --device npu:0
python inference.py --device cpu

默认使用 npu:0 若可用,否则回退 CPU。参数: --mode validate (默认) | benchmark.

5. 真实推理结果

固定输入

  • 图片: 512x512 合成图 (gradient + 64px棋盘方块, RGB, 可复现无网络依赖)
  • 提示1: "What is in this image? Describe briefly."
  • 提示2 (grounding): 'Detect all instances of: square. Response must be a JSON array: [{"label": ..., "bbox": [x1,y1,x2,y2]}, ...]. Coordinates are normalized to [0,1].'
  • Chat template: processor.apply_chat_template, tokenize=True
  • 解码: do_sample=False (贪心), max_new_tokens=32, 固定种子

NPU 输出 (npu:0, bfloat16)

input: pixel_values [1,1024,768] mean -0.1248 std 0.2768, input_ids [1,276]
output: [1,308] new tokens 32
text: "The image displays a colorful, abstract pattern composed of various small squares. These squares are arranged in a grid-like formation, creating a visually striking composition. The colors"
logits [1,276,65536] mean -4.8545 max 20.375 min -57.75 has_nan False has_inf False
bbox prompt: [{"label": "square", "bbox": [0.0, 0.0, 1.0, 1.0]

CPU 输出 (对照)

logits mean -4.8713 max 20.5 min -57.5
text 完全一致: "The image displays a colorful, abstract pattern composed..."
bbox 同为 [0.0,0.0,1.0,1.0]

两者生成文本字符级一致,logits 数值误差均值差异 0.0168 (<0.5%).

6. CPU-NPU 一致性验证

指标CPUNPU (bf16)差异
logits mean-4.8713-4.85450.0168
logits max20.520.3750.125
logits min-57.5-57.750.25
生成文本完全一致完全一致0
是否 NaN/Inf否否-
视觉 embeddingCPU pixel mean -0.1248NPU 同0

验证策略: 确定性贪心解码 + 前向 logits 统计 + 文本精确匹配。属单样本一致性验证,非全量数据集评测。

7. 性能测试

torch.npu.synchronize() 包围计时, 预热2次, 正式5次, bfloat16, batch 1, 512x512.

NPU (npu:0, bf16):

  • warmup: 0.506s, 0.488s
  • run1 0.473s, run2 0.508s, run3 0.516s, run4 0.513s, run5 0.512s
  • avg 0.504s, min 0.473s, max 0.516s, p50 0.512s
  • throughput 610.8 tokens/s (output 308 tokens / avg latency)
  • 首 token 延迟 ~0.47s (含视觉编码+首32 tokens), 稳定 decode ~62.5 tokens/s
  • 峰值显存 <4GB (权重 0.84GB + 激活)

CPU (bf16):

  • avg 26.417s, min 26.216s, max 26.689s
  • throughput 11.66 tokens/s
  • NPU 加速比: 52.4x

模型 dtype: bfloat16, 输入 276 tokens, 输出 308 tokens, tile 512, max_image_tokens 256.

8. 自验证截图

agent workflow npu device call model result

三图由 scripts/render_xterm_evidence.mjs --style raw 从真实日志渲染,含命令、退出码、SHA256.

9. 已知限制

  • 仅验证 512x512 单图像素与单一提示,高分辨率多 tile 未测 (max_tiles 10 需更多显存).
  • 当前 synthetic image 非自然照片,真实 OCR / 多语言视觉理解需用户自测.
  • CPU 回退仍为 bfloat16,部分 CPU 慢; 生产建议 NPU.
  • transformers 需 >=5.1 (5.7 已验证).
  • 未测试 function calling 分支.

10. 标签

Hardware: NPU, NPU, Ascend, Ascend910, vision-language, LFM2.5