waylong/ppo-CartPole-v1-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

HumanCompatibleAI/ppo-CartPole-v1 NPU (Ascend 910B)

This is an NPU adaptation of HumanCompatibleAI/ppo-CartPole-v1 validated on Ascend 910B (npu:0) with torch_npu.

  • Source: https://huggingface.co/HumanCompatibleAI/ppo-CartPole-v1
  • Revision: 08b61dd5dca1ee9f1a0f2d7a0fcf7740b0af5dac (fixed download via huggingface_hub / stable_baselines3 loader)
  • Policy: MlpPolicy (ActorCriticPolicy, 4 -> 64 -> Tanh -> 64 -> Tanh -> 2 action logits), value head 64->1
  • Env: CartPole-v1 (observation Box shape (4,) discrete Discrete(2))
  • Weights: ppo-CartPole-v1.zip 139331 bytes, policy.pth 40641 bytes, 8898 parameters (~35.5 KiB fp32)
  • License: MIT (inherited)

Task Contract

ItemValue
Routeoffline-rl (discrete decision policy) — CartPole state → deterministic discrete action. Closest to offline-rl family; not VLA/driving.
Observation4-dim float32: cart position, velocity, pole angle, pole angular vel. Input range per Gymnasium: [-4.8, 4.8], [-0.418,0.418] for angle.
Outputdeterministic action 0 (left) / 1 (right) via argmax of logits [2]. Horizon 1. Logits shape (batch,2).
Samplerdeterministic (deterministic=True), no stochastic sampling in validation.
Backendstable-baselines3==2.9.0 PPO.load(..., device="npu:0")
Dtype / Devicefloat32 on both CPU and npu:0. All float tensors, policy params, logits verified on npu:0 with torch.npu.synchronize() timing.

Real NPU Results (single-card Ascend910_9362)

Evidence rendered from this pod's true logs (see assets/*.png).

  • Device: npu:0 Ascend910_9362 (torch.npu.is_available()=True, 2 NPUs visible via npu-smi info)
  • Param device: npu:0 (next(policy.parameters()).device == npu:0)
  • Obs/Logits device: npu:0 on all participating tensors
  • Example batch (batch=3):
obs[0] [0.0,0.0,0.0,0.0] -> logits [-12.70907, -2.86e-06] -> action 1
obs[1] [0.5,0.1,-0.2,0.3] -> logits [-19.9782, 0.0] -> action 1
obs[2] [-0.5,-1.0,0.1,-0.5] -> logits [0.0, -36.00457] -> action 0
  • CPU vs NPU consistency (5 obs × 2 logits = 10 values, atol=1e-4 rtol=1e-3): max_abs 1.9e-06, tolerance 0.036, passed true, finite true; deterministic actions identical 1,1,0,1,0 on both.
  • Performance (torch.npu.synchronize() bounded, 20 samples batch 1): avg 0.627 ms, min 0.607 ms, max 0.676 ms, p50 0.625 ms, p90 0.644 ms, p95 0.647 ms, decisions/s 1593.7. Via inference.py batch 3: avg 0.424 ms → 7069.5 decisions/s.
  • Rollout: 5 episodes CartPole-v1 with seed 0..4 on npu:0 → 500.0 reward each, mean 500.0 (matches model card 500.00 +/-0.00).

CPU–NPU Consistency

Same ppo-CartPole-v1.zip, same normalized 4-dim observations, same deterministic=True, same float32, same eval mode. Compared logits (continuous) rather than only discrete label, using scripts/validate_policy_outputs.py. All 10 matching.

Performance

Reported with torch.npu.synchronize() around every predict/get_distribution. Warm-up 3–5 calls excluded. Units decisions/s = batch / avg_ms *1000, decisions horizon 1, action_dim 2.

Limits

  • Policy runs fully on NPU; environment (gymnasium step) stays on CPU (host-bound simulation, not an NPU operator).
  • Model is CPU-designed MLP (no CNN), GPU/NPU utilization is bandwidth-bound but still verified correct.
  • trust_remote_code not required (pure SB3 zip).

Usage

pip install -r requirements.txt
python inference.py
# loads HumanCompatibleAI/ppo-CartPole-v1 from /tmp/ppo_cartpole or HF hub, runs on npu:0 if available

Evidence:

agent workflow npu device call model result