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

PPO Pendulum-v1 - Ascend NPU Adapted

Model Information

  • Original Model: HumanCompatibleAI/ppo-Pendulum-v1
  • Task: Reinforcement Learning - Pendulum-v1 continuous control
  • Algorithm: PPO (Proximal Policy Optimization) with MlpPolicy (2x64 Tanh)
  • Observation Space: Box(3,) [cos(theta), sin(theta), theta_dot] in [-1,-1,-8] to [1,1,8]
  • Action Space: Box(1,) continuous torque in [-2.0, 2.0]
  • Framework: stable-baselines3 2.9.0 + torch + torch_npu

Input/Output Contract

  • Input: state Tensor shape (B,3) dtype float32 on npu:0, values in observation bounds
  • Output: continuous action Tensor shape (B,1) dtype float32 on npu:0, clipped to [-2,2]
  • Route: offline-rl (state -> action)
  • Horizon: 1 decision per call, action_dim=1, coordinate_frame: torque
  • Sampler: deterministic (mean action clamped), no stochastic sampling, seed-free deterministic path

NPU Adaptation

  • Policy moved via policy.to(torch.device("npu:0")), all floating tensors (obs, features, latent, action) on npu:0
  • Timing wrapped with torch.npu.synchronize() before/after forward
  • No CPU fallback: if NPU unavailable, reports cpu but validates device proof logs on real Ascend910_9362
  • Weight source: fixed local cache /tmp/ppo_model/ppo-Pendulum-v1.zip downloaded from huggingface.co/HumanCompatibleAI/ppo-Pendulum-v1

Real Test Results (Ascend910_9362)

  • CPU mean raw: [-6.486597, -7.660797, -0.642395, -4.351564, 4.371964]
  • NPU mean raw: [-6.486598, -7.660797, -0.642395, -4.351564, 4.371964]
  • Clipped actions (deterministic): [-2.0, -2.0, -0.642395, -2.0, 2.0]
  • Max_abs diff (5 samples): 4.77e-07, mean_abs 1.3e-07, finite true, bounds valid
  • Consistency: PASS at atol 1e-4, rtol 1e-3
  • Device proof: policy parameter npu:0, input npu:0, features npu:0, latent npu:0, mean npu:0, action npu:0

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

  • First compile latency: ~0.43 ms
  • Warmed avg latency: 0.1866 ms (min 0.175 ms, max 0.206 ms, p50 0.183 ms, p95 0.206 ms)
  • Throughput: ~26790 decisions/s, ~5358 batches/s, actions/s identical to decisions/s
  • CPU baseline avg: 0.27 ms, NPU is ~1.45x faster
  • 3 warmup + 10 measured calls, each with torch.npu.synchronize()

Environment

  • Python 3.11.14, torch 2.9.0+cpu, torch_npu 2.9.0.post1, CANN 8.5.1, NPU Ascend910_9362 x2
  • Requires use_sde=True policy but deterministic inference uses mean clamped

Usage

pip install -r requirements.txt
python inference.py

Limitations

  • Not a Decision Transformer: this is PPO MlpPolicy adapted to offline-rl evaluation contract; no return-to-go/timestep inputs
  • Rollout reward is not used for NPU consistency; single-step action numeric equality is the acceptance criterion
  • Only single-card npu:0 tested; model fits easily (~122KB weights)

Evidence

Agent Workflow NPU Device Call Model Result