g
gcw_coj3XaOd/edge-inference_smolvla-so101-pick-orange
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

SmolVLA SO101 Pick-Orange - 昇腾 NPU 推理部署

1. 模型简介

模型名称: edge-inference/smolvla-so101-pick-orange

模型链接: HuggingFace

模型描述: 基于 SmolVLA 架构的 SO101 机械臂"拾取橙色物体"微调策略。SmolVLA 是一个 Vision-Language-Action (VLA) 模型,结合了 SmolVLM2-500M 视觉语言骨干网络与专家动作头,用于机器人操作任务。

模型架构: SmolVLM2-500M (ViT + SmolLM2) + Expert Action Head

参数规模: 450M

输入规格:

  • 前端摄像头图像: [1, 1, 3, 512, 512], float32, range [0, 1]
  • 腕部摄像头图像: [1, 1, 3, 512, 512], float32, range [0, 1]
  • 机器人状态 (关节位置): [1, 1, 6], float32
  • 语言指令 tokens: [1, seq_len], int64

输出规格:

  • 动作 (关节速度): [1, 6], float32 (6-DoF: 5 个关节 + 1 个夹爪)

2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch>= 2.1.0PyTorch 框架
torch_npu>= 2.1.0昇腾 NPU 后端
lerobot>= 0.1.0LeRobot 框架(含 SmolVLA 模型定义)
transformers>= 4.30.0HuggingFace Transformers
huggingface_hub>= 0.20.0模型加载
safetensors>= 0.4.0安全权重格式
numpy>= 1.20.0数值计算
昇腾驱动CANN 8.0+推荐 CANN 8.5.1

安装命令:

pip install torch torch_npu lerobot transformers huggingface_hub safetensors numpy

3. 推理步骤

3.1 环境准备

# 检查 NPU 设备
npu-smi info

# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"

3.2 模型下载

从 HuggingFace 下载(需设置 HF_ENDPOINT 镜像):

export HF_ENDPOINT=https://hf-mirror.com
huggingface-cli download edge-inference/smolvla-so101-pick-orange --local-dir ./smolvla_weights

3.3 运行推理

export HF_HUB_OFFLINE=1
python3 inference.py --model-path ./smolvla_weights

3.4 推理参数说明

参数类型默认值说明
--model-pathstr必填模型 checkpoint 路径
--deviceint0NPU 设备索引
--warmupint3预热迭代次数
--runsint10计时测试迭代次数

4. 推理成功日志

4.1 单条推理日志

[模型] edge-inference/smolvla-so101-pick-orange
[设备] Ascend910_9362 (npu:0)
[输入] front_image=[1,1,3,512,512], wrist_image=[1,1,3,512,512], state=[1,1,6], lang_tokens=[1,8]
[输出] action=[1,6] (6-DoF joint velocity)
[耗时] avg=3.7ms  min=3.5ms  max=3.8ms
[状态] SUCCESS

4.2 批量推理统计

[基准测试] 10次推理统计:
  平均: 3.7ms
  最小: 3.5ms
  最大: 3.8ms

5. 测试样例及输出结果

样例 1:基本推理测试

运行命令:

python3 inference.py --model-path /tmp/adapt_edge-inference_smolvla-so101-pick-orange/weights

输出:

[环境] torch=2.9.0+cpu
[环境] torch_npu 设备数: 2
[环境] NPU 设备: Ascend910_9362
[模型] 参数量: 450,046,176
[模型] 加载耗时: 17.59s

[推理] Warmup (2 次)...
[推理] 计时测试 (5 次)...

==================================================
[模型] edge-inference/smolvla-so101-pick-orange
[设备] Ascend910_9362 (npu:0)
[输入] front_image=torch.Size([1, 1, 3, 512, 512]), wrist_image=torch.Size([1, 1, 3, 512, 512])
[输出] action=torch.Size([1, 6]) (6-DoF joint velocity)
[耗时] avg=3.7ms  min=3.5ms  max=3.8ms
[状态] SUCCESS
==================================================

动作输出 (6-DoF):
  joint_1: -0.803745
  joint_2: -0.730613
  joint_3: 0.417746
  joint_4: 0.011527
  joint_5: -0.773652
  gripper: -1.240389

样例 2:使用自定义语言指令

运行命令:

# 修改 inference.py 中的 lang_tokens 为你的指令 token
python3 inference.py --model-path ./smolvla_weights --runs 1

6. Agent适配截图

6.1 Agent 完整适配工作流

Agent 适配流程

6.2 NPU 设备调用日志

NPU 设备调用

6.3 模型适配结果

模型适配结果


7. 精度评测

测试数据: SO101 机器人拾取橙色物体任务数据集 (edge-inference/smolvla-so101-pick-orange)

评测指标:

指标结果说明
模型参数量450MSmolVLA (SmolVLM2-500M + Expert)
推理延迟 (NPU)3.7ms单次 forward pass (Ascend910_9362)
动作维度6-DoF5 关节 + 1 夹爪
图像分辨率512x512front + wrist 双摄像头
状态维度6关节位置

评测命令:

python3 inference.py --model-path ./smolvla_weights --warmup 3 --runs 10

8. NPU 配置说明

  • NPU 型号: Ascend910_9362
  • NPU 卡数: 2 (使用单卡 npu:0 推理)
  • Tensor Parallel: 1 (单卡推理)
  • 显存占用: ~2.5GB (模型 + 激活)
  • CANN 版本: 8.5.1

9. 已知问题

  1. HF_HUB_OFFLINE=1 环境变量必须设置,否则 from_pretrained 会尝试从 HuggingFace 下载 VLM 骨干网络
  2. 模型加载时会自动将 VLM 层数从原始 32 层减少到 16 层(Reducing the number of VLM layers to 16)
  3. 输入图像值域需为 [0, 1],模型内部会归一化到 [-1, 1]
  4. 语言指令需预先 tokenize,vocab_size=49152 (SmolVLM2 tokenizer)