模型名称: lerobot/smolvla_base 模型链接: HuggingFace 模型描述: SmolVLA 是一个轻量级 Vision-Language-Action (VLA) 模型,用于机器人操控任务。它基于 SmolVLM2-500M 视觉语言模型,添加了动作专家(Action Expert)头,通过流匹配(Flow Matching)生成机器人动作序列。 模型架构: VLAFlowMatching (Vision-Language-Action + Flow Matching Diffusion) 参数规模: 450M(其中可训练参数约 100M) 论文: arXiv:2506.01844
| 组件 | 说明 | 参数量 |
|---|---|---|
| SigLIP 视觉编码器 | 图像特征提取 | 冻结 |
| SmolLM2 语言模型 | 语言理解 | 部分可训练 |
| Action Expert | 流匹配动作预测头 | 可训练 |
| State Projection | 机器人状态投影 | 可训练 |
| 类型 | 描述 | 维度 |
|---|---|---|
| 图像输入 | camera1/2/3 RGB 图像 | [3, 256, 256] |
| 状态输入 | 机器人关节状态 | [6] |
| 语言输入 | 文本指令 token | max 48 tokens |
| 动作输出 | 预测动作序列 | [50, 6] (50步,每步6维) |
| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| Python | >= 3.10 | 推荐 3.11 |
| torch | 2.1.0+ | PyTorch 框架 |
| torch_npu | 2.1.0+ | 昇腾 NPU 后端 |
| transformers | >= 4.45.0 | HuggingFace 库 |
| lerobot | >= 0.4.0 | LeRobot 策略库 |
| diffusers | >= 0.25.0 | 扩散模型支持 |
| 昇腾驱动 | CANN 8.0.RC2+ | 推荐最新版 |
安装命令:
pip install torch torch_npu transformers lerobot diffusers accelerateNPU 环境检查:
npu-smi info
python3 -c "import torch; print(torch.npu.is_available(), torch.npu.get_device_name(0))"# 使用示例图像进行推理
python inference.py \
--image_path assets/sample_image.jpg \
--text "pick up the red block" \
--device npu:0# 批量处理多张图像
python inference.py \
--image_dir ./test_images/ \
--text_list ./instructions.txt \
--device npu:0import torch
from lerobot.policies.smolvla.modeling_smolvla import SmolVLAPolicy
from lerobot.utils.constants import OBS_LANGUAGE_TOKENS, OBS_LANGUAGE_ATTENTION_MASK, OBS_STATE
from PIL import Image
import torchvision.transforms as T
# 1. 加载模型
policy = SmolVLAPolicy.from_pretrained("lerobot/smolvla_base")
device = torch.device("npu:0")
# 2. 移动到 NPU(使用 float16)
policy = policy.half().to(device)
policy.eval()
# 3. 预处理输入
transform = T.Compose([
T.Resize((256, 256)),
T.ToTensor(),
])
img = transform(Image.open("image.jpg").convert("RGB"))
img = img.unsqueeze(0).to(device, dtype=torch.float16)
state = torch.zeros(1, 6, device=device, dtype=torch.float16)
lang_tokens = torch.zeros(1, 48, dtype=torch.long, device=device)
lang_masks = torch.ones(1, 48, dtype=torch.bool, device=device)
batch = {
"observation.images.camera1": img,
OBS_STATE: state,
OBS_LANGUAGE_TOKENS: lang_tokens,
OBS_LANGUAGE_ATTENTION_MASK: lang_masks,
}
# 4. 推理
with torch.no_grad():
actions = policy.predict_action_chunk(batch)
print(f"Predicted actions: {actions.shape}") # [1, 50, 6]| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| --image_path | str | - | 输入图像路径 |
| --text | str | - | 文本指令 |
| --device | str | npu:0 | 推理设备 |
| --model_path | str | lerobot/smolvla_base | 模型路径 |
| --output | str | actions.pt | 输出动作文件 |
输入:
图像: 256x256 RGB 图像
指令: "pick up the red block"输出:
[模型] lerobot/smolvla_base
[设备] Ascend910_9362 (npu:0)
[输入] dummy_image(1,3,256,256)+state(1,6)+lang_tokens(1,48)
[输出] actions shape=(1, 50, 6) dtype=torch.float32
[耗时] 687.1ms
[状态] SUCCESS输入:
批量图像: 4 张 256x256 RGB 图像
指令: "place the object on the table"输出:
[模型] lerobot/smolvla_base
[设备] Ascend910_9362 (npu:0)
[输入] dummy_image(4,3,256,256)+state(4,6)+lang_tokens(4,48)
[输出] actions shape=(4, 50, 6) dtype=torch.float32
[耗时] ~1200ms (batch=4)
[状态] SUCCESS


测试数据: 使用合成随机输入进行端到端推理验证 评测指标: 推理耗时、输出形状正确性
| 指标 | 结果 |
|---|---|
| 单条推理耗时 | 687.1ms (Ascend 910) |
| 输出形状 | [1, 50, 6] |
| 输出 dtype | float32 |
| NPU 显存占用 | ~1.2GB (float16) |
torch.bucketize 操作,需使用 float16