模型适配 · 强化学习视觉-语言-动作 (VLA) 模型 · 昇腾 NPU
Beta 版本头信息
{hardware NPU}{hardware NPU} Ascend 910B(torch_npu 2.9.0.post1)| 组件 | 版本 |
|---|---|
| torch | 2.9.0 |
| torch-npu | 2.9.0.post1 |
| python | 3.11.14 |
| transformers | 4.57.6 |
| CANN | 8.5.1 |
| NPU | Ascend 910B (Ascend910_9362) × 2(本任务用 npu:0) |
| 依赖 | numpy / torch-npu / transformers / safetensors / pillow / fastapi / uvicorn |
同一权重(
YuankaiLuo/SimVLA-LIBERO)、同一合成桌面图 + 指令 + 状态、同一初始噪声 seed=42(flow-matching 为随机策略,固定噪声才能公平对比)。动作 chunk 形状[1, 10, 7]。
| 对比 | 余弦相似度 | 最大绝对误差 | 平均绝对误差 |
|---|---|---|---|
| CPU(float32) vs NPU(float32) | 1.000000 | 9.4×10⁻⁵ | 1.7×10⁻⁵ |
两平台输出逐元素一致到小数点后 3-4 位,Euler 积分轨迹完全重合,验证 NPU 适配无精度损失。
model.safetensors(3.2GB,float32)已包含完整权重(vlm.* 视觉语言骨干 489 个张量 + transformer.* 动作头 297 个张量),因此:
HuggingFaceTB/SmolVLM-500M-Instruct base 权重;base_smolvlm/(SmolVLM-500M-Instruct 的 config/tokenizer/preprocessor)做架构与语言初始化;state_dict 键名与 vendored SmolVLMVLA 子模块完全一致,strict 加载 0 missing / 0 unexpected。attn_implementation="eager"(昇腾 NPU 上 SDPA/FlashAttention 融合内核部分算子报 ERR00100,eager 注意力结果与官方一致);generate_actions 支持传入固定初始噪声 noise,保证 CPU/NPU 公平对比与可复现。simvla/models/(configuration/modeling/processing/transformer/action_hub),无远程代码依赖。pip install -r requirements.txt
# 若环境中无 torch_npu,按昇腾官方安装 CANN 8.x + torch_npu# 方式一: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。
# 使用合成桌面图推理(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"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"])| 指标 | 数值 |
|---|---|
| 输入图像分辨率 | 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
SUCCESSSimVLA-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}