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

HumanCompatibleAI/ppo-seals-CartPole-v0 - Ascend NPU Adapted

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

  • Original model: https://huggingface.co/HumanCompatibleAI/ppo-seals-CartPole-v0
  • Revision: a86541dd3744275227cb16d07192967fc6b7775e
  • Architecture: SB3 PPO MlpPolicy with net_arch pi:[64,64] vf:[64,64] ReLU, discrete 2-action, obs dim 4
  • Route: offline-rl (PPO discrete decision, closest to Decision Transformer contract: state→action, horizon=1)
  • Device: npu:0 with synchronized timing and CPU-NPU consistency validation
  • Task: seals/CartPole-v0 discrete control (CartPole observations: cart position, cart velocity, pole angle, pole 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
  • input obs Tensor device == npu:0
  • logits device == npu:0, value device == npu:0, action device == npu:0

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

Consistency Validation

  • CPU vs NPU on identical batch (4 observations including [0.01369617, -0.02302133, -0.04590265, -0.04834723]):
    • Logits [[2.3415, -2.3408], ...] batch=4, shape [4,2]
    • Probs softmax identical, actions argmax identical [0, ...]
    • Max-abs logits diff ~2.3e-07 (< 1e-4 + 1e-3*max), value diff <1e-3
    • All finite, actions identical => PASS
  • Deterministic argmax sampling, no dropout, same weights (policy.pth 40,641 bytes), fp32

Performance (Ascend 910B)

  • First compile+inference ~3-5 ms (includes NPU kernel compilation)
  • Stable avg ~0.8-1.2 ms for batch 4, horizon 1, float32 (after 3 warmups, 10 timed iters)
  • Decisions/s ~3300-5000, actions/s same (1 action 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, torch.nn as nn
from pathlib import Path
# Load weights from HuggingFace (model_weight_url) or local policy.pth
ckpt = torch.load("policy.pth", map_location="cpu")
# Build extractor + heads as in inference.py and move to npu:0
# obs: tensor shape [B,4] float32
# logits = action_net(extractor.policy_net(obs)) -> probs -> action = argmax

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

  • Discrete 2-action CartPole 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