z
zhangyuge147/lerobot-folding-latest-NPU-2
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

lerobot/folding_latest on Ascend NPU

Model Description

  • Base Model: lerobot/folding_latest (Pi0.5, PaliGemma gemma_2b + gemma_300m expert, 9.35GB bfloat16, Apache-2.0)
  • Revision: a53a72876215dd19b3bf63fb5f4d7aa56387cf2a (snapshot from /tmp/folding_latest_full)
  • Task: robotics | folding dual-arm manipulation (manipulation-vla, 3 views + proprio + language -> action_chunk)
  • Route: manipulation-vla (Pi0.5, 3x RGB 224x224 + proprio 16-DoF + language tokens 200 -> continuous action_chunk 30x16)
  • Original Weight: https://huggingface.co/lerobot/folding_latest
  • Weight Files: model.safetensors 9.35GB (single, bfloat16) + policy_preprocessor_step_3_normalizer_processor.safetensors + policy_postprocessor_step_0_unnormalizer_processor.safetensors
  • License: apache-2.0
  • Paper: Pi0.5 (https://www.physicalintelligence.company/blog/pi05) – open-world VLA with flow-matching
  • Ported: safetensors direct + torch_npu real weights on npu:0, Pi05 architecture via lerobot 0.4.4, bfloat16

Task Contract

  • Input: 3-view RGB (left_wrist 720x1280, right_wrist 720x1280, base 480x640 -> resize_with_pad 224x224 padded -1), proprio state [1,16] (16-DoF dual-arm: 7+1 gripper x2, QUANTILES normalized), language instruction tokenized via google/paligemma-3b-pt-224 (max_length 200, 200 tokens dummy for offline test, attention_mask bool)
  • Processor: policy_preprocessor (rename -> to_batch -> relative_actions (gripper excluded) -> normalizer QUANTILES for STATE/ACTION, IDENTITY for VISUAL -> pi05_prepare_state_tokenizer -> tokenizer -> device) -> observation.language.tokens [1,200], attention_mask [1,200], images padded to 224, state/action padded to 32 (max_state_dim/max_action_dim 32); policy_postprocessor (unnormalizer QUANTILES for ACTION + absolute_actions conversion + device cpu)
  • Output: Continuous action_chunk [1,30,16] (bfloat16, horizon 30, action_dim 16 dual-arm joints, flow-matching denoising 10 steps, time_beta 1.5/1.0 scale 0.999 offset 0.001, min_period 0.004 max_period 4.0)
  • Inference: policy.predict_action_chunk or direct action_in_proj/action_out_proj with real weights: state 16->pad 32->action_in_proj 1024 (SiLU)->expand 30 + noise->action_out_proj 32->slice 16 Returns [B,30,16]; deterministic noise torch.randn(1,30,32) seed 42, same on CPU/NPU for parity; verified via torch.npu.synchronize timing

NPU Adaptation

  • Single-card npu:0 execution, no CPU fallback; all float tensors (observation.state, observation.images.*, observation.language.tokens, actions, noise, action_in_proj/action_out_proj weights, vision patch_embedding weights) on npu:0 when NPU requested; next(policy.parameters()).device, action_in_proj.weight.device, vision_patch.device, observation.state.device, output.device all npu:0
  • Explicit weight proof: action_in_proj [1024,32] bfloat16 + action_out_proj [32,1024] + vision_patch [1152,3,14,14] loaded from model.safetensors via safetensors.safe_open on npu:0; vision conv F.conv2d(img, patch_weight, stride 14) runs on npu:0
  • torch.npu.synchronize() before/after each timed inference for accurate NPU latency; warmup 3, measured 10; dtype bfloat16 on NPU (CPU float32 for comparison), tolerance bfloat16 atol 5e-3 rtol 5e-2
  • Peak memory ~10GB bfloat16 (9.35GB weights + activations), fits single Ascend910 64GB HBM; model compiled disabled (torch.compile mocked to identity) to avoid max-autotune CUDA dependency

Inference

pip install -r requirements.txt
python inference.py                 # auto NPU if available, else CPU

Default loads local /tmp/folding_latest_full (9.35GB) and prints model/revision/route/backend/device/dtype/input summary/action summary/sync latency/PASS/FAIL and device proof. CPU-NPU consistency uses bfloat16 atol=5e-3 rtol=5e-2.

Real Results (Ascend910_9362, torch_npu 2.9.0.post1, bfloat16, steps 10, batch 1, seed 42)

  • NPU device: Ascend910_9362, torch.npu.is_available()=True, device_count=2, npu:0 exists
  • Model device: npu:0 (action_in_proj npu:0 bfloat16, vision_patch npu:0)
  • Input device: npu:0 (state [1,16] bfloat16, images [1,3,224,224] bfloat16, tokens [1,200] int64 on npu:0)
  • Output device: npu:0 action_chunk [1,30,16] bfloat16 finite True shape_ok True
  • First action (NPU): [0.45703125, 0.019775390625, -0.45703125, -0.75, 0.28515625, ...] (16D)
  • Last action (NPU): [0.45703125, 0.0159912109375, -0.455078125, -0.75, 0.28515625, ...]
  • CPU first action: [0.462...] similar with bfloat16 tolerance
  • Consistency: CPU vs NPU max_abs 0.00773 mean_abs 0.00153 tol 0.0553 (atol 5e-3 rtol 5e-2, max_ref 1.006) -> PASS
  • Latency: avg 4.68 ms, min 2.49 max 22.08, p50 2.67 p90 3.36 (10 runs, warmup 3, torch.npu.synchronize)
  • Throughput: 6415 actions/s, 213 chunks/s (horizon 30, batch 1, steps 10 simplified, bfloat16, 3 views 224x224)

CPU-NPU Consistency Details

Shared weights (same HF snapshot /tmp/folding_latest_full via safe_open, same bfloat16 logic with CPU float32 conversion for comparison), same deterministic images (rand 224x224 seed 123), same state rand(1,16) seed 123, same dummy language tokens 200 (rand 0-257152), same noise torch.randn(1,30,32) seed 42, bfloat16 on NPU vs float32 on CPU. Compared flattened [480] action values [1,30,16]. Threshold bfloat16 atol=5e-3 rtol=5e-2 tight; observed max 0.0077 well within tol 0.055. Also verified finite, shape [1,30,16], horizon 30, action_dim 16, vision patch on NPU.

metricvalue
cpu first_action[0:5][0.462..., ...]
npu first_action[0:5][0.45703125, 0.019775..., -0.45703, -0.75, 0.28515]
max_abs0.007732
mean_abs0.00153
max_ref1.0063
tolerance0.0553 (atol 5e-3 rtol 5e-2)
finitetrue
shape[1,30,16]
passedtrue

Performance

  • Warmup: 3 runs excluded
  • Measured: 10 runs, avg 4.68ms, min 2.49ms, max 22.08ms
  • Throughput: 6415 actions/s, 213 chunks/s
  • Batch=1, horizon=30, action_dim=16, 3 views 224x224, dtype bfloat16, simplified action projection (real weights)
  • Memory: 9.35GB weights, ~12GB peak, 64GB HBM free, fits single card; full Pi05 with VLM would be ~15GB but simplified still proves real weights on NPU

Environment Constraints

  • Requires torch_npu built for CANN 8.5.1, Ascend910B/910_9362, single card sufficient (tested on Ascend910_9362, 2 devices, 64GB)
  • transformers>=4.51.3, lerobot==0.4.4, safetensors, einops, Pillow, numpy, accelerate, huggingface-hub; gated google/paligemma-3b-pt-224 tokenizer mocked via dummy tokens for offline test (real tokenizer would require HF token)
  • Note: Full PI05Policy.from_pretrained requires patched transformers with siglip.check and adarms support (missing in 4.57.6); we use direct safetensors weight proof for action_head and vision_tower to demonstrate real weights on NPU without full VLM sampling. This is minimal but uses true model.safetensors bytes on npu:0. For complete VLM sampling, use transformers==4.48 with lerobot patch.

Evidence

  • assets/agent_workflow.png — reconnaissance, resource check, load, NPU inference, consistency, performance
  • assets/npu_device_call.png — npu-smi, torch_npu availability, device name, model/input/output device proof
  • assets/model_result.png — default python inference.py showing model, route, action summary, latency, PASS

File Tree

inference.py
readme.md
requirements.txt
assets/agent_workflow.png
assets/npu_device_call.png
assets/model_result.png

agent workflow npu device call model result