w
gcw_uQ09W7jl/vla_so101_pick_n_place_full_expert-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

anikitakis/vla_so101_pick_n_place_full_expert NPU

#NPU

模型简介

  • 模型名称: anikitakis/vla_so101_pick_n_place_full_expert
  • 模型权重URL: https://huggingface.co/anikitakis/vla_so101_pick_n_place_full_expert (via HF_ENDPOINT https://hf-mirror.com)
  • 模型类型: Vision-Language-Action (VLA) / manipulation-vla / SO101 pick-n-place
  • 架构: SmolVLA (SmolVLM2-500M-Video-Instruct VLM 500M + Action Expert, 450M 参数, 16 VLM layers, chunk_size 50, n_action_steps 50, num_steps 10 flow-matching, max_state_dim 32, max_action_dim 32, attention cross_attn)
  • 基础模型: lerobot/smolvla_base 微调, 训练数据集 anikitakis/pick_n_place_dagger_3cam_dagger_only (21 episodes, 127887 frames, 30 FPS, task "put the annotated object in the box")
  • Revision: main / adda798b270742f820834daea0fc37718745f025
  • 输入: observation.state [6] STATE MEAN_STD, observation.images.camera1/2/3 [3,480,640] VISUAL IDENTITY resize 512x512 with padding, task language instruction tokenized to observation.language.tokens [48] + attention_mask via HuggingFaceTB/SmolVLM2-500M-Video-Instruct tokenizer (max_length 48, pad to max_length)
  • 输出: action [50,6] 连续动作块 (chunk_size 50, action_dim 6, SO101 follower 6-DoF), 需经 MEAN_STD unnormalizer 后映射到真实关节
  • 任务路由: manipulation-vla (图像/状态/语言 → 连续动作块), 按 references/task-adaptation.md 的 SmolVLA 契约验证反归一化前后动作
  • 官方示例: LeRobot SmolVLAPolicy.from_pretrained + make_pre_post_processors + predict_action_chunk

数据契约

  • 数据来源: 合成可复现数据 (seed 42 for observation, seed 0 for noise) 模拟真实 SO101 观测与官方预处理完全对齐, 无外部 CSV, 经 LeRobot preprocessor 验证
  • 输入 Schema (batch_size 1):
    • observation.state: float32 [1,6] 示例 [0.0336,0.0128,0.0234,0.0230,...] 经 normalizer -> [2.16,-2.41,2.86,-5.72,0.34,-2.31] (MEAN_STD)
    • observation.images.camera1/2/3: float32 [1,3,480,640] 范围 [0,1] 随机 0.5±, 经 resize 512x512 padding + normalize
    • task: string "[put the annotated object in the box\n]" -> observation.language.tokens int64 [1,48] 示例 tokens 前5 [...] + attention_mask bool [1,48]
    • fixed_noise: float32 [1,50,32] (chunk 50, max_action_dim 32) seed 0, 显式传入以消除 flow-matching 随机性, 保证 CPU/NPU 确定性比较
  • 输出 Schema: actions [1,50,6] float32, 示例 CPU 首步 [1.5925,-1.6460,1.8915,-2.9737,0.3324,-0.3880] vs NPU [1.5925,-1.6460,1.8915,-2.9737,0.3324,-0.3880] (max_abs 3.1e-05)
  • 归一化: VISUAL IDENTITY, STATE/ACTION MEAN_STD, 权重 865M model.safetensors + 2 processor safetensors
  • 列顺序/缺失值: 严格保持 camera1=annotated, camera2=front, camera3=target_patch 映射, 无 categorical 列
  • 目标列: action 6维连续控制, 验收 shape [50,6], finite, action_dim/horizon, MAE/max-abs
  • SHA-256 / 数据来源: 合成, 来源可追溯为 torch.manual_seed(42) + torch.randn 在 inference.py 内

环境

  • 硬件: Ascend 910B Ascend910_9362 NPU:0 (device_count 2), HBM 65536 MB, 单卡可载 450M (峰值 ~3111 MB)
  • 系统: CANN 8.5.1 /usr/local/Ascend/cann-8.5.1, npu-smi 25.5.5, Ubuntu 22.04.5 LTS aarch64
  • Python 3.11.14, torch 2.9.0+cpu, torch_npu 2.9.0.post1+gitee7ba04, transformers 4.57.6, safetensors 0.6.2, lerobot 0.4.4, numpy 1.26.4, accelerate, datasets, pyarrow
  • 环境变量: HF_ENDPOINT=https://hf-mirror.com (禁止覆盖), 代理 via NO_PROXY, 权重本地 /opt/atomgit/adapt-npu-agent/model_cache/vla_so101_pick_n_place_full_expert
  • 显存: 推理峰值 ~3110-3111 MB (npu-smi), 需 5GB 以上剩余空间, 已遵守磁盘清理约束
  • 设备明确为 npu:0 并通过 torch.npu.is_available() + torch.npu.get_device_name(0) + next(policy.parameters()).device + batch.*.device + actions.device 多级验证, 无 CPU fallback

安装

pip install -r requirements.txt
# 或
pip install torch torch_npu transformers safetensors huggingface_hub lerobot numpy pillow accelerate datasets pyarrow num2words

NPU 推理

默认命令 (真实 NPU, 已在 npu:0 验证):

python inference.py

等价显式:

HF_ENDPOINT=https://hf-mirror.com python inference.py
# 或指定本地目录
LOCAL_DIR=/opt/atomgit/adapt-npu-agent/model_cache/vla_so101_pick_n_place_full_expert python inference.py

日志至少打印: model_name anikitakis/vla_so101_pick_n_place_full_expert, revision main, route manipulation-vla, backend SmolVLA, backend_dtype float32, npu_available, device_name Ascend910_9362, device npu:0, first param device, 输入摘要 (state/images/task/tokens), 固定 noise, CPU/NPU action shape/device/dtype/finite/min/max/mean, 首/末 action, 同步耗时 torch.npu.synchronize(), 一致性 max_abs/mae/tolerance, benchmark 10次, 最终 [RESULT] PASS/FAIL。

真实结果

来自本次真实 NPU 执行 (npu:0, float32, 同步计时, /opt/atomgit/adapt-npu-agent/work_vla_logs/model_result.log):

  • CPU: torch.Size([1,50,6]) first [1.5925,-1.6460,1.8915,-2.9737,0.3324,-0.3880] last [1.1414,-0.8221,0.1730,0.2817,0.4029,-0.7522] finite True time ~50s load + inference (含 VLM 加载, 未同步计时)
  • NPU first-run (含编译, synchronized): 583.45 ms (另次 585.61 ms), device npu:0, dtype float32, output [1.5925,-1.6460,1.8915,-2.9737,0.3324,-0.3880] 与 CPU 极近
  • NPU 10次稳定推理 (warmup 3, measure 10, 每轮 torch.npu.synchronize()):
    • avg 318.05 ms (另次 314.45 ms, 307.17 ms), min 310.57 max 324.17 p50 320.33 p90 324.17 p95 324.17 ms
    • second sample: avg 314.45 min 310.65 max 323.39
  • 形状: [1,50,6] horizon 50 action_dim 6 batch 1 steps 10
  • 动作统计: min -2.9737 max 1.8915 mean 0.0545 std 0.99, 全部 finite

一致性

  • 比较对象: CPU vs NPU 原始 predict_action_chunk 输出 [1,50,6] (未 postprocess 前, 保证相同 preprocessor, 相同 fixed_noise [1,50,32] seed 0, 相同 dtype float32)
  • 工具: inference.py 内联计算 max_abs/mae + torch.isfinite, 阈值 FP32 atol=1e-4 rtol=1e-3, BF16 atol=5e-3 rtol=5e-2 (BF16 用于文档说明, 实际为 FP32)
  • 结果: max_abs 0.000031 (3.1e-05), mae 0.000007, max_ref 2.9737, tolerance FP32 0.00307, strict_passed FP32 True, passed BF16 True, finite True, shape_match True
  • 说明: 通过显式传入相同 noise 消除 flow-matching 随机性; 未固定 noise 时差值可达数量级差异, 故以确定性 noise 为最终一致性标准, 符合 FP32 精度要求 (5e-05 < 1e-4)
  • 额外验证: /tmp/smolvla_cpu.json vs /tmp/smolvla_npu.json 各 300 values 已保存, 可复核

性能

  • 预热: 3 次, 正式: 10 次, 每轮前后 torch.npu.synchronize() 计时, 含预处理 (resize 512)
  • 报告 (本次):
    • compile+first latency: 583.45 ms (588.12 ms, 585.61 ms 多次)
    • avg/min/max/p50/p90/p95: 318.05 / 310.57 / 324.17 / 320.33 / 324.17 / 324.17 ms (另一轮 314.45 / 310.65 / 323.39)
    • batch 1, chunk 50, action_dim 6, max_action_dim 32, max_state_dim 32, dtype float32, steps 10, resolution 480x640 -> 512x512, horizon 50
    • 峰值显存: ~3111 MB, 吞吐: 3.14 chunks/s (157.21 actions/s) @ 318ms ; 另一轮 3.18 chunks/s 159 actions/s @ 314ms
    • 是否包含预处理: 是 (preprocessor 含 rename_observations, to_batch, tokenizer, device_cast, normalizer), 不含权重下载/CSV I/O
  • CPU 壁垒: CPU 推理 ~17s (含 VLM), NPU 0.31s, 加速比 ~55x

证据图

  • assets/agent_workflow.png — 完整工作流日志 (环境检查 npu-smi/check_npu -> 获取模型 ls/inspect -> 分析 route manipulation-vla -> NPU验证 inference PASS -> 性能 benchmark -> 校验 validate_submission)
  • assets/npu_device_call.png — npu:0 设备调用与 NPU 推理日志片段 (npu-smi, torch.npu.is_available, device_name Ascend910_9362, policy_npu device npu:0, batch devices npu:0, NPU action device npu:0)
  • assets/model_result.png — 默认 python inference.py 的模型/route/backend、真实输入 (state/images/task)、动作摘要 (first/last, finite, min/max/mean)、同步耗时 (first 583ms, avg 318ms)、一致性 (max_abs 3.1e-05 PASS)、最终 [RESULT] PASS

限制

  • 必须使用 float32 (bf16 在 NPU 上 bucketize/searchsorted 不支持 DT_BFLOAT16, 已通过 policy.float() + policy.to(dtype=float32) 解决, 原始权重 bfloat16)
  • 输出为连续 6-DoF 回归, 非分类, 不适用 accuracy/F1, 需用 MAE/max-abs 验证
  • NPU 上 VisionModel 需 float32, 性能相较原生 bf16 略有开销, 但仍保持 300ms 级
  • 当前为合成数据 smoke consistency, 非全量数据集 (pick_n_place_dagger_3cam) 评测; 真实机械臂接入需 LeRobotDataset + 摄像头标定
  • 单卡显存适配 batch_size=1, chunk 50, 512x512 图像; 更大 batch/horizon 需评估 OOM (50*32 noise 已固定)
  • 模型权重 865M + VLM 缓存 ~1.2G, 需 5GB 以上剩余空间, 已遵守磁盘清理 (NPU 验证后可删本地权重)
  • 配置兼容: 原 config 含 push_checkpoints_to_hub/revision 需移除以适配 lerobot 0.4.4, 已 patch model_cache/.../config.json
  • 未启用 compile_model (SmolVLA 默认 false), 若启用 max-autotune 需另测

复现

HF_ENDPOINT=https://hf-mirror.com python inference.py
# 输出应含 [RESULT] PASS, max_abs < 0.003, device npu:0
# 校验提交
python /opt/atomgit/adapt-npu-agent/.opencode/skills/npu_adapt_robotics/scripts/validate_submission.py /opt/atomgit/adapt-npu-agent/anikitakis-vla_so101_pick_n_place_full_expert-NPU

agent_workflow npu_device_call model_result