gcw_6a3w2yXz/ppo-Pendulum-v1-npu-model
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

HumanCompatibleAI/ppo-Pendulum-v1 - Ascend NPU Adapted

This is an Ascend NPU-adapted deployment for HumanCompatibleAI/ppo-Pendulum-v1 (PPO on Pendulum-v1, reinforcement-learning).

  • Original model: https://huggingface.co/HumanCompatibleAI/ppo-Pendulum-v1
  • Revision: 6a0fe838119427278252dde3bf723ed7a3266df5
  • Architecture: SB3 PPO MlpPolicy with net_arch pi:[64,64] vf:[64,64] ReLU, continuous 1-D action Box [-2,2], obs dim 3 [cos(theta), sin(theta), theta_dot]
  • Route: offline-rl (PPO continuous decision, closest to Decision Transformer contract: state→action, horizon=1)
  • Device: npu:0 with synchronized timing and CPU-NPU consistency validation
  • Task: Pendulum-v1 continuous torque control (observations: cos/sin of angle + angular velocity)

NPU Device Proof

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

  • next(extractor.parameters()).device == npu:0
  • action_net.weight.device == npu:0
  • log_std param device == npu:0
  • input obs Tensor device == npu:0
  • mean/action device == npu:0, value device == npu:0

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

Consistency Validation

  • CPU vs NPU on identical batch (4 observations including [1.0,0.0,0.0] upright):
    • Mean raw [[0.40988], [-5.1887], [3.0893], [-4.0313]] batch=4, shape [4,1]
    • Action clipped to [-2,2] => [[0.40988], [-2.0], [2.0], [-2.0]]
    • Values [ -13.49, -129.67, -129.33, -66.31] batch=4, shape [4,1]
    • Max-abs mean diff ~9.5e-07 (< 1e-4 + 1e-3*max), value diff <1.6e-05 (<1e-3)
    • All finite, actions in bounds [-2,2], shape correct => PASS
  • Deterministic mean clipped sampling (no gSDE noise), no dropout, same weights (policy.pth 40,641 bytes, log_std [64,1]), fp32
  • FP32 atol=1e-4 rtol=1e-3, continuous action bounds verified

Performance (Ascend 910B)

  • First compile+inference ~127.95 ms (includes NPU kernel compilation)
  • Stable avg ~0.2655 ms for batch 4, horizon 1, float32 (after 3 warmups, 10 timed iters)
  • Min 0.2520 ms Max 0.2830 ms P50 0.2644 ms P95 0.2830 ms
  • Decisions/s ~15068, actions/s same (1 action per decision)
  • Reported with torch.npu.synchronize() around each timed forward
  • Batch 4, obs 3 dim, action dim 1, float32

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, torch.nn as nn
from pathlib import Path
ckpt = torch.load("policy.pth", map_location="cpu")  # from https://huggingface.co/HumanCompatibleAI/ppo-Pendulum-v1
# Build extractor + heads as in inference.py and move to npu:0
# obs: tensor shape [B,3] float32 [[cos, sin, theta_dot]]
# latent_pi, _ = extractor(obs_npu)
# mean = action_net(latent_pi)  # device npu:0
# action = torch.clamp(mean, -2.0, 2.0)
# value = value_net(latent_vf)

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 1-D torque Pendulum-v1 only; not a general offline-RL RTG-conditioned policy
  • Validated on Ascend 910 with CANN 8.5.1, torch_npu 2.9.0; other NPU variants may need recompilation
  • gSDE log_std [64,1] is loaded for completeness but deterministic path uses mean only (SB3 predict with deterministic=True)