waylong/ppo-Huggy-NPU-2e05dc
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

PPO-Huggy - Ascend NPU Adaptation

Model Overview

  • Base Model: PaulVialard/ppo-Huggy
  • Checkpoint: Huggy/Huggy-1129997.pt (global_step 1129997) + Huggy/Huggy-1129997.onnx (2.2M)
  • Task: Reinforcement Learning - Continuous Control for Unity Huggy environment (PPO)
  • Route: offline-rl / ppo-continuous-control - state vector (59) → continuous action (21)
  • Architecture: MLP 59→512→512→512→21 with SiLU (x*sigmoid(x)) activation, running mean/div normalization, deterministic Clip(mu,-3,3)/3 and stochastic sigma sampling. Parameters ~0.8M, weight_bytes ~15M.
  • Original Framework: PyTorch + ML-Agents / ONNX (opset Clip, Gemm transB=1, SiLU)
  • Adapted Backend: torch + torch_npu (Ascend 910_9362, npu:0, float32)

Observation / Action Contract

  • Input: obs_0 : float32[batch, 59] - Unity observation vector, normalized as Clip((obs - running_mean)/Div_56, -5, 5) where Div_56 extracted from ONNX initializer, running_mean from checkpoint.
  • Output: deterministic_continuous_actions : float32[batch, 21] in [-1,1] computed as Clip(mu, -3,3)/3. Raw mu is Linear(512→21) output; stochastic branch clip(mu + N(0,1)*exp(log_sigma), -3,3)/3 uses learned log_sigma (1,21).
  • Horizon: 1 step, action_dim 21, batch tested 1-2.
  • Sampling: Deterministic path compared for CPU-NPU consistency; stochastic uses fixed seed + torch.npu.synchronize() around each timed forward.

NPU Adaptation Details

  • Device Proof: torch.npu.is_available()==True, device_count=2, device_name=Ascend910_9362, first param device=npu:0, running_mean and div and input tensor all on npu:0, output on npu:0. No .cpu() fallback.
  • Precision: FP32 atol=1e-4, rtol=1e-3.
  • Weight Loading: Fixed revision local files Huggy-1129997.pt / .onnx via torch.load + ONNX Div extraction; no dummy weights, no model replacement.

Validation - Real NPU Results

  • Environment: Ubuntu 22.04, Python 3.11.14, torch 2.9.0+cpu, torch_npu 2.9.0, CANN 8.5.1, npu-smi shows 2× Ascend910, single-card npu:0 used. Command python inference.py loads weights, runs CPU and NPU forward on identical observation (seed 42, batch 2, 59 dims std normal).
  • CPU deterministic_action[0,:5]: [0.5838958024978638, 1.0, 0.615189254283905, -0.7273572087287903, -0.7950353026390076]
  • NPU deterministic_action[0,:5]: [0.583895742893219, 1.0, 0.6151891350746155, -0.7273570895195007, -0.7950356006622314]
  • Consistency: max_abs=0.000001, MAE≈0.000000 (mu max_abs 0.000003), finite=True, bounds [-1,1] satisfied. ONNX vs NPU max_abs=0.000001. Threshold atol=1e-4, rtol=1e-3 → PASS.
  • Validation Script: /tmp/npu_validation/cpu.json vs npu.json via validate_policy_outputs.py → {"count":21,"finite":true,"max_abs":4.17e-07,"passed":true}.

Performance - Synchronized Benchmark

  • Method: torch.npu.synchronize() before/after each forward, warmup 3, measured 10 runs, batch 2.
  • Latency (ms): avg=0.302 min=0.284 max=0.347 p50=0.299 p90=0.308 p95=0.328 (representative run); first_latency includes compile ~0.32ms.
  • Throughput: decisions/s ≈ 6627 (batch=2), actions/s ≈ 139176 (batch*21). Separate benchmark with batch 1: avg≈0.298ms → actions/s≈70556, decisions/s≈3359 via benchmark_policy.py --items-per-call 21 --unit actions.
  • Notes: Compiler cache not included in steady-state avg; all input/weights on npu:0, dtype float32, horizon 1.

Environment Limitations

  • Single NPU npu:0 (Ascend910_9362), CANN 8.5.1, torch_npu 2.9.0. Model fits easily (<1GB). No Unity env rollout; single-step deterministic action validation is primary proof. Stochastic action uses same sigma and RandomNormalLike logic as ONNX but fixed seed for reproducibility.

Usage

pip install -r requirements.txt
python inference.py

Expected output: prints model/revision, route, backend, device, dtype, input summary, CPU/NPU actions, sync latency, benchmark, consistency and PASS: True.

Evidence

  • agent workflow
  • npu device call
  • model result

Files

  • inference.py - NPU inference and benchmark
  • requirements.txt - dependencies
  • assets/ - xterm.js rendered evidence PNGs from real logs

License

Apache-2.0 (base model). Adaptation retains original license.