gcw_mXoV1I2Z/vla_so101_pick_n_place_full_expert
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

vla_so101_pick_n_place_full_expert · 昇腾 NPU 适配版 (Ascend torch-npu)

模型: anikitakis/vla_so101_pick_n_place_full_expert —— LeRobot SmolVLA 系列 pick-and-place 专家策略(so_follower 机器人,3 相机)。 本仓库为该模型在 昇腾 910 (torch-npu) 上的适配工程,提供 inference.py 双模式推理入口(CLI + FastAPI)。

模型简介

SmolVLA (Vision-Language-Action) 是一个端到端视觉-语言-动作策略,接收 多视角图像 + 语言指令 + 机器人状态, 输出一段 动作轨迹(末端执行器 6 维动作,50 步)。

  • VLM 骨干: HuggingFaceTB/SmolVLM2-500M-Video-Instruct(取前 num_vlm_layers=16 层)
  • 动作头: cross-attn action expert(expert_width_multiplier=0.75)
  • 动作生成: flow-matching 迭代去噪(num_steps=10)
  • 动作空间: 末端执行器 6 维(ee6d), 输出 chunk_size=50 步动作
  • 机器人: so_follower; 相机: front/annotated/target_patch(480×640)

输入 / 输出格式

项说明
输入图像3 个相机视角图像(本工程将单张输入图复制到 3 个视角槽位)
输入指令自然语言文本,如 "put the annotated object in the box"
输入状态6 维末端关节位置(默认 [0, 90, -80, 85, 0, 10])
输出动作trajectory: 形状 [50, 6] 的浮点数组(50 步 × 6 维 ee6d 动作)

NPU 适配要点(模板① CUDA 清理)

  • 全代码域禁止任何 CUDA 调用(.cuda() / torch.cuda.* / device="cuda" / CUDA_VISIBLE_DEVICES / cudnn.*)。
  • 模型与输入 Tensor 全部迁移 npu:0(由 ASCEND_VISIBLE_DEVICES 映射物理卡); 入口 import torch_npu 并 torch.npu.set_device(0)。
  • NPU 初始化失败直接报错退出,不做 CPU/CUDA 回退。
  • 自包含引擎 smolvla_npu/(移植自 huggingface/lerobot v0.5.1 的 smolvla 策略), 移除对完整 lerobot 框架的依赖,仅保留推理所需最小实现:
    • modeling.py / vlm_with_expert.py / configuration.py —— SmolVLA 策略 + SmolVLM2 VLM + expert(近乎原样移植,无 CUDA);
    • get_safe_dtype 对 npu 将 float64 降级为 float32(Ascend910 不支持 fp64)。
  • 权重加载: 用 safetensors.torch.load_model 从本地 model.safetensors(含完整 VLM + expert 权重)加载; 基础 VLM 以 load_vlm_weights=False 从 config 初始化架构(避免重复下载 ~1GB 基础权重),再整体覆盖为模型权重。

使用方式

环境

pip install -r requirements.txt

1. CLI 单图推理

python inference.py --img test_input.png --instruction "put the annotated object in the box"

输出 JSON,含 trajectory (50×6), last_action, stats, inference_ms, exit_status 等。

2. FastAPI 服务

python inference.py --serve --port 8000

请求:

curl -F "file=@test_input.png" -F "instruction=put the annotated object in the box" http://127.0.0.1:8000/predict

返回与 CLI 相同的 JSON 推理结果。

3. 权重缓存

权重自动从 hf-mirror.com(回退 ai.gitcode.com/hf_mirrors)下载并缓存到 ./model_weights/anikitakis/vla_so101_pick_n_place_full_expert/(策略权重)与 ./model_weights/vlm_backbone/SmolVLM2-500M-Video-Instruct/(VLM 骨干 config/tokenizer)。 已缓存直接复用(打印 [cache-hit])。

证据截图

  • assets/agent_workflow.png — NPU 部署依赖安装 + 任务启动总日志
  • assets/npu_device_call.png — CLI 命令行推理成功输出
  • assets/model_result.png — FastAPI 返回推理结果

许可证

模型 Apache-2.0(来源 anikitakis/vla_so101_pick_n_place_full_expert)。