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

PPO seals/CartPole-v0 - Ascend NPU Adapted

Model Information

  • Original Model: HumanCompatibleAI/ppo-seals-CartPole-v0
  • Task: Reinforcement Learning - CartPole-v0 discrete control (PPO)
  • Algorithm: PPO (Proximal Policy Optimization) with MlpPolicy (net_arch pi [64,64] vf [64,64], ReLU)
  • Observation Space: Box(4,) [cart pos, cart vel, pole angle, pole ang_vel] float32
  • Action Space: Discrete(2) (0: left, 1: right)
  • Framework: stable-baselines3 2.9.0 + torch 2.9.0 + torch_npu 2.9.0.post1

Input/Output Contract

  • Input: state Tensor shape (1,4) or (B,4) dtype float32 on npu:0, values within observation bounds [-3.4e38, 3.14] range
  • Output: logits Tensor shape (1,2) dtype float32 on npu:0, probs via softmax -> deterministic action argmax
  • Route: offline-rl (state -> next action) adapted from Decision Transformer contract (single decision horizon=1, action_dim=2 discrete)
  • Sampler: deterministic argmax of logits, no stochastic sampling, no return-to-go/timestep inputs (PPO is state-only)

NPU Adaptation

  • Policy moved via PPO.load(..., device=npu:0) and policy.to(torch.device("npu:0")); all floating tensors (obs, features, latent, logits, probs) verified on npu:0
  • Timing wrapped with torch.npu.synchronize() before/after forward; 3 warmup + 10 measured calls
  • No CPU fallback: PASS requires real npu:0 (Ascend910_9362) with torch.npu.is_available()==True
  • Weight source: fixed local zip /tmp/ppo-cartpole/ppo-seals-CartPole-v0.zip from https://huggingface.co/HumanCompatibleAI/ppo-seals-CartPole-v0 (revision main, 138KB zip, 40KB policy.pth)

Real Test Results (Ascend910_9362, CANN 8.5.1)

  • CPU logits (seed 0 obs [0.01369617, -0.02302133, -0.04590265, -0.04834723]): [-0.00921487808227539, -4.691527366638184] probs [[0.99082738, 0.00917266]] action 0
  • NPU logits (same obs): [-0.00921487808227539, -4.691527366638184] probs [[0.99082738, 0.00917266]] action 0
  • Batch 5 max_abs: 0.0, mean_abs 0.0, finite true, bounds valid
  • Consistency: PASS at atol 1e-4, rtol 1e-3 (tolerance 0.00479)
  • Device proof: policy param npu:0, action_net weight npu:0, obs_tensor npu:0, logits npu:0
  • Rollout demo (deterministic, env seals/CartPole-v0, 200 steps max): ~500 mean_reward (trained model reports 500.0 +/- 0.0 on 10 eval episodes)

Performance (batch 1, horizon 1, decisions/s)

  • Avg latency (10 sync samples after 3 warmup): ~0.434 ms (min 0.419 ms, max 0.453 ms, p50 0.426 ms, p95 0.453 ms)
  • Throughput: ~2302 decisions/s (~2302 actions/s) single sample; batch 5 would be ~11500 decisions/s
  • CPU baseline avg: ~0.27 ms on same host (NPU overhead minimal for tiny MLP)

Environment

  • Python 3.11.14, torch 2.9.0+cpu, torch_npu 2.9.0.post1, CANN 8.5.1, NPU Ascend910_9362 x2 (910_9362)
  • gymnasium 1.3.0 + seals 0.2.1
  • Env render_mode rgb_array available but not used for NPU proof

Usage

pip install -r requirements.txt
python inference.py
# defaults to npu:0 if torch.npu.is_available() else cpu, prints device, logits, timing, PASS/FAIL

Limitations

  • Not Decision Transformer: no sequence/context, no return-to-go; mapped to offline-rl evaluation contract as state->action prediction
  • Rollout reward is supplementary; acceptance is numeric logits equality on npu:0
  • Only single-card npu:0 validated; model fits easily (~9155 params, 40KB)

Evidence

Agent Workflow NPU Device Call Model Result