hums6666/smolvla-so101-pick-orange-npu
模型介绍
文件和版本
Pull Requests
讨论
分析

edge-inference/smolvla-so101-pick-orange — 昇腾 NPU 适配

昇腾NPU

原模型:edge-inference/smolvla-so101-pick-orange(HuggingFace / GitCode 镜像)

  • 模型类型:SmolVLA(Vision-Language-Action) 机器人策略(SO101 机械臂 · 拾取橙子任务)
  • 原始权重:https://ai.gitcode.com/hf_mirrors/edge-inference/smolvla-so101-pick-orange
  • 适配框架:torch-npu(CANN + torch_npu),推理设备 npu:0

适配要点(CUDA 清零 + NPU 迁移)

  • 全局 CUDA 清零:工程代码不使用任何 torch.cuda / .cuda() / device='cuda' 调用, 模型与输入统一迁移 npu:0。
  • NPU 初始化保护:torch.npu.set_device(0) 包在 try-except 中,失败即抛明确错误。
  • lerobot 运行时打补丁:不改第三方库源码,通过补丁让 is_torch_device_available / get_safe_torch_device / auto_select_torch_device / is_amp_available 识别 npu 设备, 使 config.device 自动回退为 npu:0。
  • 预/后处理管线设备改写:device_processor 覆盖为 npu:0,tokenizer 走本地 VLM 组件。
  • VLM 组件本地化:SmolVLM2 的 config / tokenizer / processor 缓存于 vlm_deps/, 推理时不依赖外网。

模型输入 / 输出

模态键名形状说明
输入observation.images.front(3, 480, 640)前视相机图像 (C,H,W),值域 [0,1]
输入observation.images.wrist(3, 480, 640)腕部相机图像 (C,H,W),值域 [0,1]
输入observation.state(6,)SO101 关节状态向量
输入taskstr语言指令(默认 "Pick up the orange and place it on the plate")
输出action(6,)单步动作(关节位置,度)
输出action chunk(50, 6)动作序列 chunk

权重缓存目录:./model_weights/edge-inference/smolvla-so101-pick-orange(本地,不入库) 归一化统计量已内嵌于 policy_preprocessor_* / policy_postprocessor_*,推理脚本自动加载。

环境要求

  • Python 3.11
  • CANN / torch_npu(已就绪的昇腾 NPU 环境)
  • pip install -r requirements.txt

快速开始

0. 下载权重(缓存到本地,命中跳过)

python3 download_weights.py

1. 命令行推理(NPU)

python3 inference.py \
  --img test_images/front.png \
  --img-wrist test_images/wrist.png \
  --state "0,0,0,0,0,0" \
  --task "Pick up the orange and place it on the plate"

输出示例:

{
  "status": "success",
  "model": "edge-inference/smolvla-so101-pick-orange",
  "device": "npu:0",
  "action": [5.77, -10.89, 15.50, 30.51, 4.16, 8.05],
  "action_dim": 6,
  "action_chunk_size": 50
}

2. FastAPI 服务(NPU)

python3 -m uvicorn inference:app --host 0.0.0.0 --port 8000

调用推理接口:

curl -s -X POST http://127.0.0.1:8000/predict \
  -F "front=@test_images/front.png" \
  -F "wrist=@test_images/wrist.png" \
  -F "state=0,0,0,0,0,0" \
  -F "task=Pick up the orange and place it on the plate"

文件说明

文件说明
inference.pyNPU 推理主脚本(CLI + FastAPI 双模式,共用同一套 NPU 加载/推理逻辑)
download_weights.py权重下载脚本(本地缓存,命中跳过)
make_screenshots.py取证截图生成脚本(assets/*.png)
assets/取证截图(agent_workflow.png / npu_device_call.png / model_result.png)
vlm_deps/SmolVLM2 VLM 组件本地缓存(config/tokenizer/processor)
test_images/示例测试图像(拾取橙子场景)