liuhongwei-2026/SimVLA-LIBERO
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

YuankaiLuo/SimVLA-LIBERO on Ascend NPU

模型适配 · 强化学习视觉-语言-动作 (VLA) 模型 · 昇腾 NPU

Beta 版本头信息

{hardware NPU}

1. 简介

  • 模型来源: YuankaiLuo/SimVLA-LIBERO(AtomGit 镜像: https://ai.gitcode.com/hf_mirrors/YuankaiLuo/SimVLA-LIBERO)
  • 模型类型: SimVLA —— 轻量级 Vision-Language-Action 模型(论文: SimVLA: A Simple VLA Baseline for Robotic Manipulation),基于 SmolVLM-500M-Instruct 骨干(SigLIP 视觉编码器 + SmolLM LLM,Idefics3 架构),本仓权重是在 LIBERO 机器人操作基准上通过强化学习(behavior cloning / 专家示范模仿)微调得到的策略。
  • 参数量: 811,400,000(811.4M,含 vlm 骨干 + 动作头)
  • 架构: SigLIP 视觉编码器(12 层 · 768 维 · patch16)→ Connector 投影 → SmolLM LLM(32 层 · 960 维)+ 24 层 flow-matching 动作 Transformer(1024 维 · 16 头,concat 条件注入,无 AdaLN);flow-matching 连续动作空间,10 步 Euler 去噪
  • 输入/输出: 3 视角图像 (3×384×384) + 8 维关节状态 + 自然语言操作指令 → 长度为 10 的 7 维动作 chunk(笛卡尔增量位姿 + 夹爪)
  • 适配状态: SUCCESS
  • 适配说明: 该模型为 VLA 强化学习策略,通过 flow-matching 预测连续动作,不是自回归纯文本 LLM,不适用 vLLM-Ascend。本项目在 torch_npu 上适配,与官方实现完全一致的 eager 注意力 + flow-matching Euler 去噪,在昇腾 NPU 上原生推理,并提供 FastAPI 服务化推理。
  • 适配时间: 2026-08-21
  • 硬件: {hardware NPU} Ascend 910B(torch_npu 2.9.0.post1)

2. 验证环境

组件版本
torch2.9.0
torch-npu2.9.0.post1
python3.11.14
transformers4.57.6
CANN8.5.1
NPUAscend 910B (Ascend910_9362) × 2(本任务用 npu:0)
依赖numpy / torch-npu / transformers / safetensors / pillow / fastapi / uvicorn

3. 精度评测 (CPU vs NPU)

同一权重(YuankaiLuo/SimVLA-LIBERO)、同一合成桌面图 + 指令 + 状态、同一初始噪声 seed=42(flow-matching 为随机策略,固定噪声才能公平对比)。动作 chunk 形状 [1, 10, 7]。

对比余弦相似度最大绝对误差平均绝对误差
CPU(float32) vs NPU(float32)1.0000009.4×10⁻⁵1.7×10⁻⁵

两平台输出逐元素一致到小数点后 3-4 位,Euler 积分轨迹完全重合,验证 NPU 适配无精度损失。

4. 适配要点

  • checkpoint model.safetensors(3.2GB,float32)已包含完整权重(vlm.* 视觉语言骨干 489 个张量 + transformer.* 动作头 297 个张量),因此:
    • 无需下载 gated 的 HuggingFaceTB/SmolVLM-500M-Instruct base 权重;
    • 仅用仓库内 base_smolvlm/(SmolVLM-500M-Instruct 的 config/tokenizer/preprocessor)做架构与语言初始化;
    • state_dict 键名与 vendored SmolVLMVLA 子模块完全一致,strict 加载 0 missing / 0 unexpected。
  • NPU 适配点:
    • vlm 骨干强制 attn_implementation="eager"(昇腾 NPU 上 SDPA/FlashAttention 融合内核部分算子报 ERR00100,eager 注意力结果与官方一致);
    • 服务化依赖(fastapi/uvicorn/json_numpy/cv2)从顶层 import 改为 延迟导入,纯推理路径零额外依赖;
    • flow-matching 为随机策略,generate_actions 支持传入固定初始噪声 noise,保证 CPU/NPU 公平对比与可复现。
  • vendored 自包含代码位于 simvla/models/(configuration/modeling/processing/transformer/action_hub),无远程代码依赖。

5. 复现步骤

5.1 安装依赖

pip install -r requirements.txt
# 若环境中无 torch_npu,按昇腾官方安装 CANN 8.x + torch_npu

5.2 下载权重

# 方式一:gitcode 镜像(git + LFS)
export PATH=/opt/atomgit/models/git-lfs-3.5.1:$PATH
git clone https://gitcode.com/hf_mirrors/YuankaiLuo/SimVLA-LIBERO.git /tmp/models/simvla_libero

# 方式二:HF 镜像(需网络可达 hf-mirror.com)
HF_ENDPOINT=https://hf-mirror.com python3 -c "
from huggingface_hub import snapshot_download
snapshot_download('YuankaiLuo/SimVLA-LIBERO', local_dir='/tmp/models/simvla_libero')
"

权重目录需包含 config.json + model.safetensors。

5.3 单次推理

# 使用合成桌面图推理(NPU 卡 0)
python3 inference.py --model-dir /tmp/models/simvla_libero --synthetic-demo \
    --task "pick up the red block and place it on the plate"

# 使用真实图像(支持三视角 --image / --image2 / --image3)
python3 inference.py --model-dir /tmp/models/simvla_libero \
    --image assets/demo_input.png \
    --task "open the top drawer and close it"

5.4 服务化推理

python3 serve.py --model-dir /tmp/models/simvla_libero --port 8090 --npu-id 0

客户端调用:

import base64, requests

img = base64.b64encode(open("assets/demo_input.png", "rb").read()).decode()
resp = requests.post("http://127.0.0.1:8090/infer", json={
    "image": img,                       # 第一视角 base64
    "task": "pick up the red block and place it on the plate",
    "state": [0, 0, 0, 0, 0, 0, 0, 0],  # 8 维关节状态
}, timeout=60)
print(resp.json()["action_first_step"])

6. 结果

指标数值
输入图像分辨率384×384 × 3 视角
输出动作序列10 × 7-DoF
模型加载耗时(CPU→NPU)~34 s
单次推理耗时(CPU float32)24.1 s
单次推理耗时(NPU float32)0.57 s
服务化单次推理耗时(NPU)0.74 s
参数量811.4M
数值有限性(finite)True ✅
CPU vs NPU 余弦相似度1.000000

实际运行输出:

[info] state_dict strict 加载: 0 missing, 0 unexpected ✓
[info] 模型加载耗时 34.1s, 参数量 811.4M, dtype=torch.float32, device=npu:0
[info] 推理耗时: 0.572s (设备: npu:0)
[info] 动作 chunk 形状: [1, 10, 7]
[result] 第一步动作(7 维):   2.0039   0.0589   0.8900  -1.5268  -0.0634   0.1294  -0.9180
[result] 动作有限性 finite: True
SUCCESS

7. 目录结构

SimVLA-LIBERO/
├── inference.py        # NPU 推理脚本(单次推理 + CPU/NPU 对比)
├── serve.py            # NPU 服务化推理(FastAPI)
├── README.md           # 部署说明文档
├── requirements.txt    # 环境依赖清单
├── base_smolvlm/       # SmolVLM-500M-Instruct 本地 config/tokenizer(架构初始化用)
├── simvla/             # SimVLA 模型定义(vendor 自官方 SimVLA 仓库,自包含)
│   └── models/
│       ├── configuration_smolvlm_vla.py
│       ├── modeling_smolvlm_vla.py
│       ├── processing_smolvlm_vla.py
│       ├── transformer_smolvlm.py
│       └── action_hub.py
└── assets/             # 截图素材文件夹
          ├── agent_workflow.png
          ├── npu_device_call.png
          └── model_result.png

贡献者: liuhongwei-2026 | 赛道: 模型适配赛道 | 硬件: {hardware NPU}