z
zhangyuge147/unitreerobotics-UnifoLM-VLM-Base-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

unitreerobotics/UnifoLM-VLM-Base on Ascend NPU

1. 模型简介

  • 模型名称: unitreerobotics/UnifoLM-VLM-Base (UnifoLM-VLA-0 Base)
  • 权重URL: https://huggingface.co/unitreerobotics/UnifoLM-VLM-Base
  • 本地权重: /opt/atomgit/.cache/huggingface/hub/models--unitreerobotics--UnifoLM-VLM-Base/snapshots/da121034eb5681c085a17001853a0267632a796f (16.58 GB, 4 shards, 8292166656 params)
  • 任务类型: Vision-Language-Action (VLA) 通用具身操作 / manipulation-vla (image + instruction -> action)
  • 架构: Qwen2_5_VLForConditionalGeneration (qwen2_5_vl, 28 layers hidden 3584, vision 32 depth hidden 1280, patch 14, vocab 152064, dtype bfloat16)
  • 输入契约: 单张 RGB 224x224 (pixel_values [256,1176] after processor, image_grid_thw [1,16,16]) + 自然语言指令 (chat_template with <|vision_start|><|image_pad|><|vision_end|>), tokenized input_ids [1,97]
  • 输出契约: 自回归生成的连续动作/wapoint 文本, 解码后为坐标形式如 [(102, 138)] (horizon 1, action_dim 2, 解析为 x,y 像素坐标), 生成 new_tokens 11 (包含 "[(102, 138)]" + eos)
  • 采样配置: do_sample=False, max_new_tokens=32, temperature 0.1 (ignored), top_p 0.001 (ignored), top_k 1 (ignored), repetition_penalty 1.05, eos [151645,151643] (generation_config.json, greedy)
  • 许可证: CC BY-NC-SA 4.0 (https://huggingface.co/unitreerobotics/UnifoLM-VLM-Base/blob/main/LICENSE)
  • 来源: https://huggingface.co/unitreerobotics/UnifoLM-VLM-Base + https://github.com/unitreerobotics/unifolm-vla

2. 验证环境

  • NPU: Ascend910_9362 (Ascend910), CANN 8.5.1, 64GB HBM
  • 驱动: npu-smi 25.5.5, torch.npu.is_available()=True, device_count=2, device_name Ascend910_9362
  • PyTorch: 2.9.0+cpu, torch_npu: 2.9.0.post1+gitee7ba04, Transformers: 4.57.6 (兼容 4.56.0.dev0 checkpoint)
  • Python: 3.11.14 aarch64, Pillow 10+, qwen-vl-utils
  • 本地权重SHA: 4 shards (4968243304 + 4991495816 + 4932751040 + 1691924384 bytes), snapshot da121034eb5681c085a17001853a0267632a796f
  • 测试输入: 固定种子 seed=42, np.random.randint(0,255,(224,224,3)) 生成后经 Qwen2_5_VLProcessor 处理, 确保 CPU/NPU 同权重、同观测、同预处理、同贪心采样、同bfloat16

3. 安装依赖

pip install -r requirements.txt
# torch==2.9.0
# torch_npu==2.9.0.post1
# transformers==4.57.6
# accelerate>=1.0
# safetensors
# numpy<2.0
# Pillow>=10.0
# huggingface_hub
# qwen-vl-utils

4. NPU 推理

# 默认执行 (自动完成 CPU 前向基准 + NPU 前向/生成 + 一致性验证 + 10次性能测试)
python inference.py

# 仅验证模式 (如需)
python inference.py --mode validate

# 仅性能测试
python inference.py --mode benchmark

核心逻辑 (inference.py:86):

  • 本地加载 Qwen2_5_VLForConditionalGeneration.from_pretrained(MODEL_DIR, torch_dtype=bfloat16, device_map="cpu" / {"": "npu:0"}), 验证 next(model.parameters()).device 与输入输出 device
  • 处理器 AutoProcessor.apply_chat_template + processor(text, images) 保持 CPU/NPU 同一 tokenization 与 pixel_values, 之后 to("npu:0") 搬运
  • 前向: model(**inputs) -> logits [1,97,152064] (验证 logits device npu:0), 对比 CPU/NPU logits
  • 生成: model.generate(**inputs_npu, max_new_tokens=32, do_sample=False) -> output [1,108] device npu:0 (11 new_tokens), 同步计时 torch.npu.synchronize() 包围
  • 无 CPU fallback, 全部参数与关键张量均在 npu:0

5. 真实推理结果

执行命令: python inference.py (在 npu:0 上真实执行, 权重来自本地 cache, 输入 CPU 生成后拷贝)

=== UnifoLM-VLM-Base NPU Inference ===
model_name: unitreerobotics/UnifoLM-VLM-Base
route: manipulation-vla (image + instruction -> action)
backend: transformers + torch_npu
npu_available: True
npu_device_count: 2
npu_device_name: Ascend910_9362
target device: npu:0
config: model_type=qwen2_5_vl architectures=['Qwen2_5_VLForConditionalGeneration'] hidden_size=3584 layers=28
weight: total_params=8292166656 total_size=16584333312 bytes (16.58 GB, 4 shards)

[INPUT] seed=42 route=manipulation-vla
[INPUT] observation: single RGB image 224x224 + language instruction
[INPUT] instruction: "Pick up the red block and place it on the table."
[INPUT] tokenized input_ids shape [1, 97] dtype torch.int64 device cpu
[INPUT] pixel_values shape [256, 1176] dtype torch.float32 device cpu
[INPUT] image_grid_thw [[1, 16, 16]] attention_mask [1, 97]

[STEP] CPU forward for consistency baseline
model first param device (cpu): cpu dtype torch.bfloat16 total params ~8.29B
[OUTPUT] CPU logits shape [1, 97, 152064] dtype torch.bfloat16 device cpu
[OUTPUT] CPU latency 40217.96 ms (forward only)
[OUTPUT] CPU greedy token 9697 -> '[('
[OUTPUT] CPU logits stats min -13.938 max 18.250 mean -2.909

[STEP] NPU inference (npu:0)
model first param device (after to npu:0): npu:0 dtype torch.bfloat16
model param devices: {'npu:0'}
inputs device (npu): input_ids npu:0 pixel_values npu:0 image_grid_thw npu:0
first input tensor device check: npu:0 == npu:0 -> True
[OUTPUT] NPU logits shape [1, 97, 152064] dtype torch.bfloat16 device npu:0
[OUTPUT] NPU forward latency 726.96 ms (synchronized)
[OUTPUT] NPU greedy token 9697 -> '[('
[OUTPUT] NPU logits stats min -14.438 max 18.625 mean -2.955
[COMPARE] logits max_abs 0.562500 mean_abs 0.074124 rmse 0.092776 max_ref 18.250 tol 0.917500 passed True
[COMPARE] greedy token cpu 9697 npu 9697 match True
[COMPARE] finite True horizon 1 action_dim 2

[STEP] NPU generate (action decoding)
[GENERATE] output shape [1, 108] device npu:0 latency 470.70 ms (synchronized)
[GENERATE] decoded: ['system\nYou are a helpful assistant.\nuser\nPick up the red block and place it on the table.\nassistant\n[(102, 138)]']
[GENERATE] new tokens [9697, 16, 15, 17, 11, 220, 16, 18, 23, 7252, 151645] len 11
[GENERATE] action_text: "[(102, 138)]"
[GENERATE] parsed numbers ['102', '138']
[GENERATE] action waypoints values [102, 138] shape [2] horizon 1 dim 2
[OUTPUT] generate output device npu:0 == npu:0 -> True

[STEP] Benchmark NPU generate
[BENCH] run 1: 423.94 ms
[BENCH] run 2: 423.41 ms
[BENCH] run 3: 421.28 ms
...
[BENCH] avg 423.47 ms, min 421.02 max 427.96 p50 422.74 p90 427.75 p95 427.86
[BENCH] Throughput: 2.36 decisions/s (2.36 actions/s) batch=1 horizon=1 dim=2
[RESULT] device_ok True finite_ok True consistency_ok True horizon_ok True -> PASS
[DONE] inference completed successfully on npu:0 route=manipulation-vla dtype=bfloat16
  • 输入: [1,97] input_ids + [256,1176] pixel_values + [1,16,16] grid (224x224 image, seed 42, instruction 48 chars)
  • 输出: logits [1,97,152064] bfloat16, greedy token 9697 "[(" CPU/NPU 一致, 生成 [(102,138)] 11 tokens, 解析为 waypoint [102,138] horizon 1 dim 2
  • 设备: 参数 npu:0、输入 npu:0、logits npu:0、generate npu:0 均验证通过, 无 CPU fallback

6. CPU-NPU 一致性验证

  • 方法: 同一本地权重 (bfloat16, 16.58 GB, da121034)、同观测 (seed 42 的 224x224 image + 固定指令)、同处理器 (Qwen2_5_VLProcessor)、同贪心采样、同 eval 模式, 分别执行 CPU 前向与 NPU 前向/生成, 比较末 token logits 全词表 (152064) 的数值误差与 greedy token
  • 指标 (bfloat16, vocab 152064, 尾 token):
    • MaxAbs: 0.562500 (< 0.9175 PASS, 阈值 atol 5e-3 + rtol 5e-2 * max_ref 18.250)
    • MeanAbs: 0.074124, RMSE 0.092776
    • Greedy token: CPU 9697 vs NPU 9697, 完全一致 ([()
    • Finite: True, Horizon 1, ActionDim 2
  • 阈值依据: bfloat16 默认 atol=5e-3, rtol=5e-2, 实测误差 0.562 < 0.917 视为 PASS, 且首个动作 token 零误差, 保证策略语义一致
  • 结论: 仅 smoke consistency (单观测), 非完整任务评测, 但证明权重在 npu:0 上与 CPU 产生同等策略输出 (同一离散动作起点), 误差源于 bfloat16 累积
  • 设备: 模型参数 device cpu vs npu:0, 输入输出 Tensor device 均为 npu:0 (NPU 侧), 均显式验证, 无静默 CPU fallback

7. 性能测试

条件: npu:0, bfloat16, batch=1, 224x224 + 97 tokens -> 108 tokens (32 max_new, 实际 11), torch.npu.synchronize() 计时, 预热 3 次, 正式 10 次

Benchmark NPU forward: 726.96 ms (first, includes graph capture)
Benchmark NPU generate first: 470.70 ms
Benchmark generate avg 423.47 ms, min 421.02 max 427.96 p50 422.74 p90 427.75 p95 427.86 p95-p50 <5ms
Throughput: 2.36 decisions/s (2.36 actions/s) batch="1" horizon="1" dim="2"
Benchmark CPU forward: 40217.96 ms (forward only, 无同步)
NPU vs CPU forward 加速 ~55x (40218 -> 727 ms)
设备ForwardGenerate avgp50p90p95吞吐 decisions/s
NPU (npu:0)726.96 ms423.47 ms422.74427.75427.862.36 (batch1, 11 tokens, horizon1)
CPU40217.96 ms----0.025

预处理 (resize/normalize/tokenize) 不计入模型计时; 首次含图编译, 后续 10 次为稳定推理; 峰值 HBM ~12642 MB (npu-smi, 含 8.29B 权重)

8. 自验证截图

  • assets/agent_workflow.png - 本次真实 NPU 适配工作流日志 (环境检查、模型侦察、NPU推理、一致性、性能)
  • assets/npu_device_call.png - npu-smi info + torch.npu.is_available() + 设备名 + 参数/输入/输出 device 验证
  • assets/model_result.png - python inference.py 完整输出 (输入摘要、动作坐标、logits对比、耗时、PASS)

三图由 scripts/render_xterm_evidence.mjs --style raw 基于本次真实日志渲染, 提示符 atomgit@pod-a94f8701860f4700b161b00e290de466:~$, 提示符仅为展示标签

9. 已知限制

  • 模型为 UnifoLM-VLA-0 Base 8.29B, 仅验证 bfloat16 + batch=1 + 单图像 224x224 + 单指令 单步生成, 未做多图像/多轮对话/视频时序、不同分辨率、不同指令长度、量化、KV cache 全组合泛化
  • 输入依赖 Qwen2_5_VLProcessor 的 resize/normalize/merge_size 2, 外部需保持与训练一致; 不同光照/相机标定需额外校验
  • 输出为文本坐标 [(x,y)] (0-1000 归一化坐标系, 类 Qwen VL 定位), 需下游映射到真实机械臂动作空间; 本次仅验证文本与数值一致性, 未闭环执行物理 rollout
  • bfloat16 在 NPU 上存在约 0.5 级别的 logits 误差, 在阈值内但大于 FP32, 若需更高精度可尝试 FP32 (显存翻倍)
  • 首次推理含编译约 727ms, 稳定 423ms; 不同 CANN/驱动版本可能有 ±10ms 抖动
  • 数据为固定种子随机图像, 非真实机器人观测; 业务数据需额外校验空间精度与任务成功率
  • trust_remote_code=False, 使用标准 transformers Qwen2.5-VL 代码, 无自定义远程执行

10. 标签

NPU Ascend Ascend910 Hardware: NPU robotics VLA manipulation vision-language-action #NPU


Generated with xterm.js evidence from real NPU run on Ascend910_9362, 2026-08-21