jsjs1258/lerobot-diffusion-pusht-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

lerobot/diffusion_pusht on Ascend NPU (910B)

This repository ports lerobot/diffusion_pusht (Diffusion Policy for PushT) to Huawei Ascend NPU (Ascend910) via torch_npu. The original model is a visuomotor diffusion policy trained on the PushT environment (gym-pusht) with LeRobot. All weights and configs are kept identical; only the runtime is moved from CUDA to npu:0.

  • Model: lerobot/diffusion_pusht @ 84a7c23178445c6bbf7e1a884ff497017910f653
  • Route: demonstration-policy (LeRobot DiffusionPolicy, ACT/Diffusion family)
  • Task: PushT planar pushing – observation image (96×96 RGB) + state (2D agent_pos) → continuous action chunk (horizon 16, executed 8 steps, dim 2)
  • Backbone: resnet18 (GroupNorm, 32 keypoints SpatialSoftmax) + DiffusionConditionalUnet1d (down_dims 512,1024,2048, kernel 5, diffusion_step_embed_dim 128, FiLM) + DDPM 100 steps (squaredcos_cap_v2, clip_sample True range 1.0)
  • Preprocess: resize None, crop_shape [84,84] centered in eval, visual MEAN_STD, state/action MIN_MAX
  • Verification: Real weights on npu:0 with torch.npu.synchronize() timing, CPU vs NPU numerically compared (same local snapshot, same synthetic observation, same noise seed 999, same scheduler). See evidence.

Input / Output Contract

Input (per step):

  • observation.state: [B,2] or [B,n_obs_steps,2] float32 agent xy in MIN_MAX normalized range
  • observation.image: [B,3,96,96] float32 RGB in [0,1] (preprocessor will center-crop to 84×84)
  • For diffusion generation: stacked as observation.state [B,n_obs_steps,2] and observation.images [B,n_obs_steps,1,3,96,96]

Output:

  • action_chunk: [B, n_action_steps, 2] float32 (horizon 16 sliced to 8). Values in normalized action space (clip to [-1,1]), corresponds to delta xy for the pusher. Shape/dtype/device/sampler are logged.

NPU Inference

python inference.py
# loads DiffusionPolicy.from_pretrained(local_snapshot) -> npu:0, runs generate_actions with fixed noise
# prints model/revision, route, backend, device, dtype, input summary, action summaries, synchronized latency, PASS/FAIL

No manual http_proxy handling required – HF_ENDPOINT=https://hf-mirror.com is respected via env.

Real Results (Ascend910_9362, npu:0, single card)

  • Source: local snapshot /opt/atomgit/adapt-npu-agent/.cache_hf/models--lerobot--diffusion_pusht (model.safetensors 1.0GB)
  • Input used: synthetic deterministic batch B=1, n_obs_steps=2 – state ~ N(0,1) seed 0, images ~ U(0,1), noise ~ N(0,1) seed 999, shape [1,16,2]
  • CPU baseline (same weights, same inputs, same noise, same DDPM 100 steps):
    • first_action [-1.0, 0.7120] last_action [-1.0, 0.6949] mean -0.1533 std 0.8747 shape [1,8,2] finite true
  • NPU (npu:0, float32, DDPM 100 steps, torch_npu):
    • first_action [-1.0, 0.7265] last_action [-1.0, 0.6761] mean -0.1556 std 0.8724 shape [1,8,2] device npu:0 finite true
    • npu_first_param device=npu:0, noise device=npu:0, output device=npu:0, global_cond on NPU
  • CPU↔NPU consistency (16 values): max_abs=0.018759 mae=0.00457 tolerance=0.055 (atol 5e-3 rtol 5e-2, max_ref 1.0) → PASS via validate_policy_outputs.py
  • Performance (10 runs, 3 warmup, synchronize before/after each): avg 2486.78 ms, min 2486.46 ms, max 2487.14 ms, p50 2486.66 ms → 3.22 actions/s, 0.40 chunks/s (batch 1, horizon 16, n_action_steps 8, float32, 100 diffusion steps). First compilation included in warmup; steady-state reported.

NPU Evidence

NPU device call and model results are rendered from real logs (no mock):

  • npu-smi info shows 2×Ascend910 devices, test used Ascend910_9362 on npu:0 (Phy-ID 2, Bus 0000:0A:00.0)
  • torch.npu.is_available()==True, device_count=2, get_device_name(0)=Ascend910_9362, first param / inputs / sampler noise / output all on npu:0
  • Timings use torch.npu.synchronize() around each generate_actions call

agent workflow npu device call model result

Limitations

  • 100-step DDPM is intentionally slow (≈2.5s per chunk on NPU, ≈21s on CPU). Reducing num_inference_steps (e.g., to 10 via DDIM) drastically speeds up but changes the action distribution; this port keeps the original 100-step schedule for fidelity.
  • Weights (~1.0GB, 262.7M params) fit single Ascend910 (64GB). No sharding needed. use_amp=False, pretrained_backbone_weights=None.
  • normalize_inputs/unnormalize_outputs buffers from the checkpoint are warnings on load (unknown keys) – the diffusion core itself runs in normalized space; the wrapper normalizer is handled at dataset level and does not affect this single-step synthetic validation.

References

  • https://huggingface.co/lerobot/diffusion_pusht
  • Diffusion Policy: Visuomotor Policy Learning via Action Diffusion (https://arxiv.org/abs/2303.04137)
  • gym-pusht (https://github.com/huggingface/gym-pusht), LeRobot (https://github.com/huggingface/lerobot)