w
gcw_uQ09W7jl/PaulVialard-ppo-Huggy-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

PaulVialard/ppo-Huggy on Ascend NPU #NPU

Model Introduction

Model Name: PaulVialard/ppo-Huggy
Revision: 1fd517574882e4b765aa24a2b078d91fa1ab9072 (Huggy-1009955.pt 13MB + Huggy.onnx 2.2MB, step 1,009,955)
Model Weight URL: https://huggingface.co/PaulVialard/ppo-Huggy
Model Type: Reinforcement Learning (PPO, ML-Agents Huggy)
Task Type: reinforcement-learning / offline-rl (vector observation → continuous action)
Architecture Family: MLP Policy (512×3 ReLU + continuous Gaussian head)
Pipeline Tag: reinforcement-learning
Weights: Huggy/Huggy-1009955.pt (13 MB, PyTorch) + Huggy.onnx (2.2 MB, ONNX) – upstream repo contains 200+ checkpoints.
License: Unknown (Unity ML-Agents based, check upstream README)

PPO agent trained on Unity ML-Agents Huggy (Huggy the sock-like creature). Input is 59-dim vector observation (raycasts, positions, velocities, etc.), output is 21-dim continuous action (joint torques/forces) sampled from Gaussian N(mu, sigma) where mu is MLP output and log_sigma learned. This adaptation validates deterministic mu (clipped to [-1,1]) on Ascend NPU with exact CPU↔NPU consistency.

Data Contract

FieldValue
Input Formatobs [batch, 59] float32, vector observation
Axis Order[B, OBS_DIM] – MLP input
Observation Dim59 (ML-Agents vector obs; normalized with running_mean/var)
Action Dim21 continuous (mlagents continuous_act_size_vector=21, no discrete)
Horizon / Chunk1 (single-step policy; no action chunk, no diffusion steps)
Normalizerobservation_encoder.processors.0.normalizer + processors.0.normalizer duplicate (running_mean[59], running_var[59], steps=1009956)
Hidden Layers3 × Linear 512 (seq_layers 0,2,4) with ReLU: 59→512→512→512
Action Headmu: Linear(512→21) + log_sigma [1,21] (deterministic inference outputs mu, clipped to [-1,1])
Dtypefloat32 (weights fp32, compute fp32, no fp16/bf16)
Batch (demo)4 (tested also 1 and 16)
Preprocessingnormalized = (obs - mean) / sqrt(var + 1e-8) then MLP; synthetic deterministic N(0.8)+0.1*b seed 42
Data SourceSynthetic deterministic (no Unity env required), reproducible with seed 42
Outputmu [B,21] float32 + clipped [B,21] in [-1,1] – both finite, shape verified

No Unity environment needed; zero-shot forward only.

Environment

  • Python 3.11.14
  • torch 2.9.0+cpu, torch_npu 2.9.0.post1+gitee7ba04
  • huggingface_hub 0.36.2, numpy 1.26.4, safetensors (optional)
  • Ascend CANN 8.5.1, torch.npu.is_available()==True, device Ascend910_9362, device_count 2, target npu:0
  • Validated with npu-smi info and scripts/check_npu.py

Installation

pip install -r requirements.txt

Model weights: auto-loaded from /opt/atomgit/adapt-npu-agent/working/models/ppo-Huggy if present, else from https://huggingface.co/PaulVialard/ppo-Huggy via hf_hub_download (requires HF_ENDPOINT mirror if needed). No tokenizer, no extra Unity binary.

NPU Inference

Default command (runs synthetic demo with NPU):

python inference.py

Expected output includes:

  • model_name, revision, trainer ppo, route offline-rl, arch obs_dim/act_dim
  • config: trainer=ppo hidden=512 layers=3
  • obs shape [4,59], sample values, stats
  • CPU baseline mu shape [4,21], sample, finite, bounds
  • first_param device: npu:0, input device: npu:0, NPU mu shape: [4,21] device: npu:0
  • first run (compile) time with torch.npu.synchronize() and second run time
  • Benchmark avg/min/max/p50/p90/p95 and throughput
  • Consistency max_abs, allclose
  • Final state: SUCCESS

Supports different batch sizes (1, 16 validated).

Real Results (Verified NPU)

Run: python inference.py (batch=4, obs_dim=59, act_dim=21, float32, npu:0)

Input:

  • obs [4,59], sample [1.5415,1.1898,0.7205,-1.6844,0.5427], mean 0.1935 std 0.7956

Output:

  • CPU mu [4,21], sample [-0.00986,-0.25189,0.11080,0.11443,-0.12403] min -0.5048 max 0.5754
  • NPU mu [4,21], sample [-0.00986,-0.25189,0.11080,0.11443,-0.12403] (max_abs 2.08e-07)
  • Clipped same (already within [-1,1])
  • finite True, clipped finite True

Timing (npu:0, synchronized):

  • First run (compile): 141.07 ms
  • Second run: 0.70 ms
  • Stable avg: 0.27 ms (warmup 3, test 10)
  • Throughput: 14870 decisions/s (4 obs), 312286 actions/s (4*21)
  • Memory: allocated 2.2 MB, reserved 56.0 MB

No CPU fallback; all tensors on npu:0, normalizer buffers on npu:0.

Consistency Verification

Saved CPU/NPU outputs to .npy + .json and compared:

python .opencode/skills/npu_adapt_robotics/scripts/validate_policy_outputs.py --cpu /tmp/cpu_ppo_huggy.json --npu /tmp/npu_ppo_huggy.json --atol 1e-4 --rtol 1e-3

Result: count 84 passed True finite True max_abs 2.08e-07 mean_abs 4.7e-08 tolerance 6.7e-04 (fp32 atol=1e-4). Shape [4,21] verified, bounds [-1,1] not exceeded, allclose True. Differences due to NPU fused ops but well within tolerance.

Benchmark also via benchmark_policy.py with latencies list: avg 0.27 ms p50 0.27 p90 0.29.

Performance

Warmup 3, test 10, synchronized:

  • compile/first_run 141.07 ms, avg 0.27 ms, min 0.26 ms, max 0.30 ms, p50 0.27 ms, p90 0.28 ms, p95 0.29 ms
  • batch=4, horizon=1, act_dim=21, dtype float32, device npu:0
  • throughput 14870 decisions/s, 312k actions/s
  • peak NPU memory 2.2 MB allocated, 56 MB reserved
  • preprocessing (synthetic generation) not included; timed region is HuggyPolicy.forward only

Additional: batch 1 latency 0.68 ms shape [1,21]; batch 16 latency 0.65 ms shape [16,21] correct.

Evidence

Three PNGs generated by xterm.js from real logs (render_xterm_evidence.mjs --style raw):

  • assets/agent_workflow.png – workflow (inspect, download, NPU check, inference, compare, benchmark, validation)
  • assets/npu_device_call.png – npu-smi + torch.npu availability + model param device + input/output device
  • assets/model_result.png – full python inference.py output

Images are rendered from actual terminal logs, not screenshots, prompt atomgit@pod-a94f8701860f4700b161b00e290de466:~$ is display label only.

agent workflow npu device call model result

Limitations

  • Vector obs only (59 dims); visual obs not used (vis_encode simple but no camera in this Huggy checkpoint, confirms MLP only).
  • Continuous action only (21 dims, no discrete); deterministic mu reported, stochastic sampling with log_sigma not exercised but log_sigma loaded and shown.
  • Unity environment not required; closed-loop rollout not performed (forward only). Reward/success metrics not applicable per skill rule 6.
  • FP32 only; FP16/BF16 not tested (ML-Agents checkpoint is fp32).
  • Weights not included in repo (download from HuggingFace); single checkpoint Huggy-1009955.pt 13 MB demonstrated, other checkpoints (0–2M steps) share same arch and expected similar NPU behavior.
  • ONNX file Huggy.onnx 2.2 MB available in upstream but torch path used for NPU (ONNX Runtime not NPU-accelerated); conversion to torch verifies same weights.