超
gcw_g59KKkes/lerobot-smolvla-metaworld
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

lerobot/smolvla_metaworld · 昇腾 NPU 视觉-语言-动作 (VLA) 推理

本仓库将 lerobot/smolvla_metaworld(SmolVLA 视觉-语言-动作策略,Meta-World metaworld-push 任务微调版)适配到昇腾 (Ascend) NPU(torch-npu,设备 npu:0)。权重在首次使用时自动从镜像下载到 model_weights/lerobot/smolvla_metaworld/,无需手动干预。

  • 模型权重镜像(声明主源,未实际镜像 → 自动回退):https://ai.gitcode.com/hf_mirrors/lerobot/smolvla_metaworld
  • 工作镜像:https://hf-mirror.com/lerobot/smolvla_metaworld
  • HuggingFace 原始仓库:https://huggingface.co/lerobot/smolvla_metaworld
  • 基础模型:lerobot/smolvla_base(VLM 主干 HuggingFaceTB/SmolVLM2-500M-Video-Instruct + 动作专家头)

模型信息

字段值
模型lerobot/smolvla_metaworld
架构SmolVLM2-500M 视觉语言主干(16 层文本层截断)+ 动作专家头(flow matching 采样,num_steps=10)
任务Meta-World metaworld-push(“Push the puck to a goal”),动作 4 维(x, y, z, gripper)
输入单路顶部相机帧(训练为 480×480,推理时任意尺寸 resize 到 512×512 并填充)+ 4 维 agent state + 指令文本
输出50 步动作块(chunk_size=50),每步 4 维;返回**真实(反归一化)**动作
归一化图像 IDENTITY;state / action 均为 MEAN_STD(来自 checkpoint 的 pre/postprocessor)
权重文件config.json、model.safetensors(约 906 MB)、policy_preprocessor.json、policy_preprocessor_step_5_normalizer_processor.safetensors、policy_postprocessor.json、policy_postprocessor_step_0_unnormalizer_processor.safetensors、train_config.json

昇腾 NPU 适配说明

  1. 无任何 CUDA 代码 — 项目全文件(含 model_code/ 内 vendor 的 SmolVLA 源码)均无 .cuda() / torch.cuda / device="cuda";模型与所有输入张量都在 npu:0 上。
  2. NPU 初始化 包裹在 init_npu() 中(try-except,失败输出 JSON 错误并退出)。
  3. 权重自动下载 — 首次运行从 GitCode 镜像下载(该 URL 返回 HTML 页面时立即回退到 hf-mirror.com),缓存于 model_weights/lerobot/smolvla_metaworld/;下载后对 safetensors 做 8 字节 header + JSON + 数据偏移 + NaN/Inf 校验。
  4. VLM 主干本地构建 — SmolVLM2 的 config/processor/tokenizer 自动下载到 model_weights/vlm/SmolVLM2-500M-Video-Instruct/,只用其构建架构(不重复下载主干权重,主干权重已内含在 model.safetensors)。若 tokenizer.json 下载损坏,会自动跳过并使用慢速 GPT2Tokenizer 回退。
  5. vendored 模型代码 — model_code/ 收录了 HuggingFace LeRobot 仓库中 SmolVLA 策略源码(src/lerobot/policies/smolvla/* 与 src/lerobot/policies/common/{vla_utils,flow_matching}.py),做了 CUDA 清理与 LeRobot 依赖剥离。检查点加载:先按 config.json 构建 SmolVLAPolicy,再严格加载 model.safetensors(缺失/多余键数为 0,已验证)。

使用方法

命令行(单图推理)

ASCEND_RT_VISIBLE_DEVICES=0 python3 inference.py --img examples/demo_metaworld.png 2>cli.err | tee cli.log

可选参数:

  • --instr "Grasp the block" 覆盖指令(默认:Push the puck to a goal)
  • --state x,y,z,g 覆盖 4 维 agent state(默认使用数据集的 state 均值,归一化后≈0)

输出 JSON 到 stdout(设备 npu:0):

{
  "model": "lerobot/smolvla_metaworld",
  "source": "https://ai.gitcode.com/hf_mirrors/lerobot/smolvla_metaworld",
  "device": "npu:0",
  "status": "success",
  "instruction": "Push the puck to a goal",
  "action": [x, y, z, gripper],
  "action_dim": 4,
  "chunk_size": 50,
  "action_chunk": [[...], ...],
  "elapsed_ms": 1234.56
}

action / action_chunk 均为**真实(反归一化)**动作值(action_real = action_norm * std + mean)。

FastAPI 服务

ASCEND_RT_VISIBLE_DEVICES=0 python3 inference.py --mode server --port 8785
  • GET / — 最小化深色终端风格 HTML 上传页
  • POST /predict — multipart 上传图片(file)+ 可选指令字段(instr)→ 同上 JSON

示例:

curl -s -F file=@examples/demo_metaworld.png http://127.0.0.1:8785/predict
curl -s -F file=@examples/demo_metaworld.png -F "instr=Push the puck to a goal" http://127.0.0.1:8785/predict

示例图片

examples/demo_metaworld.png 是从真实 Meta-World 数据集 lerobot/metaworld_mt50(data/chunk-000/file-000.parquet,episode 0,顶部相机 480×480 RGB 帧)中提取的真实机器人相机帧,非合成图片。

环境

  • Python 3.11.14,PyTorch(昇腾版),torch_npu,Ascend 910
  • 依赖:transformers==4.57.6 safetensors numpy Pillow fastapi uvicorn python-multipart num2words
  • 物理 NPU:ASCEND_RT_VISIBLE_DEVICES=0(代码内固定 npu:0)

文件说明

  • inference.py — 双模式推理入口(CLI + FastAPI,NPU 适配)
  • model_code/ — vendored SmolVLA 策略源码(CUDA 已清理,无 LeRobot 依赖)
  • make_screenshots.py — 生成验证截图
  • examples/demo_metaworld.png — 真实 metaworld 顶部相机帧
  • assets/ — 验证截图(agent_workflow / npu_device_call / model_result)

引用

@article{shukor2025smolvla,
  title={SmolVLA: A Vision-Language-Action Model for Affordable and Efficient Robotics},
  author={Shukor, Mustafa and Aubakirova, Dana and Capuano, Francesco and Kooijmans, Pepijn and Palma, Steven and Zouitine, Adil and Aractingi, Michel and Pascal, Caroline and Russi, Martino and Marafioti, Andres and Alibert, Simon and Cord, Matthieu and Wolf, Thomas and Cadene, Remi},
  journal={arXiv preprint arXiv:2506.01844},
  year={2025}
}