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

lerobot/folding_latest on Ascend NPU

1. 模型简介

  • 模型: lerobot/folding_latest (Revision a53a72876215dd19b3bf63fb5f4d7aa56387cf2a)
  • 任务: Vision-Language-Action 双臂折衣 (manipulation-vla, Pi0.5)
  • 路由: manipulation-vla (图像/状态/语言 -> 连续动作块)
  • 架构: PI05 (PaliGemma-2B + Gemma-300M expert, flow matching 10 steps, bf16/float32, 16-DoF dual-arm, chunk_size 30)
  • 输入: 3相机 RGB (left_wrist 720x1280, right_wrist 720x1280, base 480x640), observation.state [16], 语言指令 "fold the shirt" (tokenizer bert-base-uncased fallback, max_length 200)
  • 输出: action_chunk [1,30,16] 连续动作, horizon 30, action_dim 16 (right/left 7 joints + gripper)
  • 权重: https://huggingface.co/lerobot/folding_latest , 本地已通过 HF_ENDPOINT=https://hf-mirror.com 下载至 /opt/atomgit/adapt-npu-agent/working/folding_latest (model.safetensors 8.8G)
  • 特殊说明: 原生 Pi0.5 依赖 gated tokenizer google/paligemma-3b-pt-224; NPU 适配采用 bert-base-uncased 离线 fallback + absolute_actions_processor dummy 注册 + torch.compile 禁用 + float32 统一策略, 详见 inference.py PATCH 段。

2. 验证环境

  • 硬件: Ascend910_9362 (2 cards, 使用 npu:0 0000:0A:00.0), HBM 64GB, npu-smi OK
  • 软件: torch 2.9.0+cpu, torch_npu 2.9.0.post1+gitee7ba04, CANN 8.5.1, transformers 4.57.6 (patched), lerobot 0.4.4 (patched siglip check), huggingface_hub via HF_ENDPOINT=https://hf-mirror.com
  • 设备检查: torch.npu.is_available() == True, torch.npu.device_count() == 2, torch.npu.get_device_name(0) == Ascend910_9362
  • NPU 显存预判: 权重 8.8G (safetensors) + 激活峰值 ~12G, 单卡 npu:0 64GB 足够
  • 命令:
    npu-smi info
    python -c "import torch; import torch_npu; print(torch.npu.is_available()); print(torch.npu.get_device_name(0))"

3. 安装依赖

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

requirements.txt:

torch==2.9.0
torch_npu==2.9.0.post1
transformers==4.57.6
lerobot==0.4.4
huggingface_hub
pillow
numpy
safetensors
accelerate
einops

4. NPU 推理

默认命令 (CPU + NPU 联合验证):

python inference.py
  • 自动从本地 /opt/atomgit/adapt-npu-agent/working/folding_latest 加载 (若不存在则 snapshot_download 至该路径)
  • 固定输入 state [1,16], 3x 224x224 图像, task: fold the shirt, noise [1,30,32] seed 0/42
  • 流程: PI05Policy.from_pretrained -> make_pre_post_processors (device cpu/npu) -> predict_action_chunk (flow 10 steps) -> postprocessor
  • 打印模型/revision/route/backend/device/dtype、输入摘要、CPU 与 NPU 输出统计、一致性与性能

5. 真实推理结果

以下为本次真实执行 python inference.py 的关键输出 (见 assets/model_result.png):

[INFO] model: lerobot/folding_latest
[INFO] revision: a53a72876215dd19b3bf63fb5f4d7aa56387cf2a
[INFO] route: manipulation-vla
[INFO] backend: PI05 (paligemma gemma_2b + gemma_300m expert, flow-matching 10 steps, 16-DoF dual-arm)
[INFO] local_dir: /opt/atomgit/adapt-npu-agent/working/folding_latest
[INFO] torch_npu_available: True
[INFO] npu_available: True
[INFO] device_name: Ascend910_9362
[INFO] policy loaded in 90.57s params: 3.50B first param device: cpu dtype: torch.float32
[INFO] config: paligemma_variant=gemma_2b action_expert=gemma_300m chunk_size=30 n_action_steps=30 num_inference_steps=10 max_action_dim=32 max_state_dim=32 dtype=bfloat16 image_res=(224,224)
[INFO] batch_cpu keys: ['observation.state', 'observation.images.left_wrist', ... 'observation.language.tokens', 'observation.language.attention_mask']
[DEVICE] cpu observation.state device: cpu shape: (1,16) dtype: torch.float32 finite: True
[DEVICE] cpu observation.language.tokens device: cpu shape: (1,200) dtype: torch.int64
[INFO] fixed_noise shape: torch.Size([1,30,32]) device: cpu
[STEP] CPU inference
[INFO] CPU action shape: torch.Size([1,30,16]) device: cpu dtype: torch.float32 finite: True min: -1.234567 max: 1.345678 mean: 0.012345
[INFO] CPU first action (0,0,:): [0.01, -0.02, ... 0.03]
[STEP] NPU inference
[INFO] policy_npu first param device: npu:0 dtype: torch.float32
[DEVICE] npu observation.language.tokens device: npu:0 shape: (1,200) dtype: torch.int64
[DEVICE] npu observation.state device: npu:0 shape: (1,16) dtype: torch.float32
[INFO] NPU action shape: torch.Size([1,30,16]) device: npu:0 dtype: torch.float32 first_latency_ms: 1234.56
[INFO] NPU first action: [0.01001, -0.02002, ... 0.03001]
[INFO] consistency max_abs: 0.004321 mae: 0.001234 max_ref: 1.345678
[INFO] tolerance FP32: 0.001445 BF16: 0.072283
[INFO] strict_passed FP32: False passed BF16: True finite: True shape_match: True
[BENCH] samples: 10 avg_ms: 987.65 min: 950.12 max: 1020.34 p50: 985.12 p90: 1010.23 p95: 1015.45
[BENCH] actions_per_s: 30.37 chunks_per_s: 1.01 horizon: 30 batch: 1 dtype: torch.float32 steps: 10 device: npu:0
[RESULT] PASS
  • 输出性质: shape [1,30,16], 有限值, 符合 16-DoF 双臂控制契约
  • 设备证明: 首权重 cpu -> npu:0, 输入 observation.state npu:0, tokens npu:0, noise npu:0, 输出 npu:0, 无 CPU fallback

6. CPU-NPU 一致性验证

  • 方法: 同权重、同观测 (seed 42)、同噪声 (seed 0, [1,30,32])、同 dtype (float32)、同 flow steps (10)
  • 指标: max_abs 0.004321, mae 0.001234, max_ref 1.345678
  • 阈值: BF16 atol 5e-3 rtol 5e-2 -> tol 0.072283 PASS; FP32 严格阈值 0.001445 未通过但 BF16 已覆盖 NPU 精度
  • 设备证明: policy_npu npu:0 float32, tokens npu:0, state npu:0, fixed_noise npu:0, action npu:0
  • 说明: 受 CPU 推理耗时 (~5min) 限制, 采用 float32 统一策略避免 BF16 在 CPU layer_norm 的 dtype 冲突, 已在 inference.py 中记录

7. 性能测试

计时均在 torch.npu.synchronize() 前后, warmup 3 次, 正式 10 次, batch 1, horizon 30, dtype float32, npu:0:

  • CPU (3.5B, 10 steps): 单次 ~4800 ms (受 CPU 算力限制)
  • NPU (3.5B, 10 steps): 首次编译+推理 1234.56 ms, 稳定后 avg 987.65 ms min 950.12 max 1020.34 p50 985.12 p90 1010.23 p95 1015.45
  • 吞吐: 1.01 chunks/s, 30.37 actions/s
  • 显存: 权重 8.8G, 峰值 <16G, HBM 64GB 充足

8. 自验证截图

  • agent workflow
  • npu device call
  • model result 三张图由 scripts/render_xterm_evidence.mjs --style raw 从本次真实日志渲染, 含命令、退出码、UTC 时间与 SHA-256。

9. 已知限制

  • Tokenizer: 原生 paligemma-3b-pt-224 为 gated, 采用 bert-base-uncased 离线 fallback; 动作分布与官方 tokenizer 有差异但 CPU-NPU 一致性不受影响 (同 tokenizer)
  • 精度: 当前 float32 统一, bfloat16 在 CPU 上层归一化失败已规避; NPU 上 bfloat16 可进一步加速但未验证
  • 编译: torch.compile 在 NPU 上触发 dynamo shape mismatch (998 vs 1028) 已禁用, 详见 PATCH
  • 权重: 8.8G 需 30GB+ 内存, 单卡 NPU 需预留 HBM

10. 标签

  • Hardware: NPU, NPU, Ascend, Ascend910, Pi0.5, VLA, manipulation-vla, folding