gcw_6a3w2yXz/ppo-Huggy-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

PaulVialard/ppo-Huggy - Ascend NPU Adapted

This is an Ascend NPU-adapted deployment for PaulVialard/ppo-Huggy (PPO on Huggy Unity ML-Agents, reinforcement-learning).

  • Original model: https://huggingface.co/PaulVialard/ppo-Huggy
  • Revision: 1fd517574882e4b765aa24a2b078d91fa1ab9072
  • Architecture: MLP 59->512 Swish x3 -> Mu 21, obs normalization (mean/var/steps) clipped [-5,5], action deterministic Clip(mu,-3,3)/3 -> normalized [-1,1] continuous 21-D
  • Route: offline-rl (PPO continuous decision, closest to Decision Transformer contract: state 59 -> action 21, horizon=1)
  • Device: npu:0 with synchronized timing and CPU-NPU consistency validation
  • Task: Huggy continuous control (59-dim vector observation, 21-dim continuous action)

NPU Device Proof

Model and tensors are explicitly placed on npu:0 and verified:

  • next(policy.parameters()).device == npu:0
  • policy.running_mean.device == npu:0
  • input obs Tensor device == npu:0
  • action device == npu:0, mu device == npu:0

Synchronization uses torch.npu.synchronize() before/after timing.

Consistency Validation

  • CPU vs NPU on identical batch (4 observations including [0.11,0.09,0.53,0.48,0.0,...]):
    • Action [[0.0071, -0.0292, 0.0047, ... 0.0158], ...] batch=4, shape [4,21]
    • Max-abs action diff 2.2e-07 (< 1.1e-03 tolerance = atol 1e-4 + rtol 1e-3 * max_ref), mean-abs 3.8e-08
    • Max-abs mu diff 1.9e-06
    • All finite, action in [-1,1], shape correct => PASS
    • Deterministic mu/3 sampling, same weights (Huggy-2000049.pt 13.5 MB), fp32

Performance (Ascend 910B)

  • First compile+inference ~140-152 ms (includes NPU kernel compilation)
  • Stable avg ~0.35-0.38 ms for batch 4, horizon 1, float32 (after 3 warmups, 10 timed iters)
  • Decisions/s ~10600-11100, actions/s ~223k-233k (21 actions per decision)
  • Reported with torch.npu.synchronize() around each timed forward

Validated on Ascend 910 (2x NPU, ~61 GiB free per card, torch_npu 2.9.0.post1, CANN 8.5.1).

Usage

import torch, torch_npu
from pathlib import Path
# policy automatically downloads checkpoint from HuggingFace if not present
ckpt = torch.load("Huggy-2000049.pt", map_location="cpu")
# Build HuggyPolicy as in inference.py and move to npu:0
# obs: tensor shape [B,59] float32 normalized via running stats
# action, mu = policy(obs) -> deterministic action = Clip(mu)/3 in [-1,1]

See inference.py for full synchronized example with device proof and batch 4.

Evidence

Agent Workflow NPU Device Call Model Result

Files

  • inference.py - NPU inference with device proof, consistency and perf
  • requirements.txt - dependencies
  • assets/*.png - xterm.js evidence screenshots

Limitations

  • Continuous 21-dim Huggy only; not a vision-language-action or diffusion policy
  • Deterministic mu path only; stochastic sampling with log_sigma not used for validation (CPU/NPU would diverge on random noise)
  • Validated on Ascend 910 with CANN 8.5.1, torch_npu 2.9.0; other NPU variants may need recompilation