f
gcw_pCMO8DfP/ppo-seals-CartPole-v0
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

ppo-seals-CartPole-v0 (Ascend NPU)

NPU-adapted inference for the reinforcement-learning control policy HumanCompatibleAI/ppo-seals-CartPole-v0 — a stable-baselines3 PPO (MlpPolicy) agent for the CartPole balancing task.

The policy MLP is reconstructed from the checkpoint and executed on an Ascend NPU via torch-npu. No CUDA is used anywhere.

ItemValue
EnvironmentCartPole (obs dim 4, discrete actions 2)
AlgorithmPPO (MlpPolicy)
Networkobs(4) → Linear(4,64)+ReLU → Linear(64,64)+ReLU → Linear(64,2)
ActivationReLU
Devicenpu:0 (Ascend), CPU fallback

1. Get the weights

The checkpoint is fetched from HF (via hf-mirror) and cached locally:

mkdir -p model_weights/ppo-seals-CartPole-v0
HF_ENDPOINT=https://hf-mirror.com python3 -m huggingface_hub.snapshot_download \
  HumanCompatibleAI/ppo-seals-CartPole-v0 \
  --local-dir model_weights/ppo-seals-CartPole-v0

The SB3 zoo repo nests the checkpoint one folder deep, so the policy weights end up at model_weights/ppo-seals-CartPole-v0/ppo-seals-CartPole-v0/policy.pth. inference.py probes both the flat and nested paths automatically.

Weights are git-ignored; only code and assets/ are published.

2. CLI inference

Given a 4-dim CartPole observation vector, the model prints the predicted action as JSON:

python3 inference.py --state 0.1,-0.2,0.3,0.4

Example output:

{"model": "ppo-seals-CartPole-v0", "device": "npu:0", "action": 0, "logits": [0.9, -0.4], "probabilities": [0.787, 0.213]}

action is the deterministic (greedy) action: argmax(logits).

3. FastAPI service

Serve the model over HTTP:

python3 inference.py --serve --port 8000

Health check:

curl http://127.0.0.1:8000/health
# {"status":"ok","model":"ppo-seals-CartPole-v0","device":"npu:0"}

Prediction:

curl -X POST http://127.0.0.1:8000/predict \
  -H "Content-Type: application/json" \
  -d '{"state": [0.1, -0.2, 0.3, 0.4]}'
# {"model":"ppo-seals-CartPole-v0","device":"npu:0","action":0,"logits":[...],"probabilities":[...]}

Request schema: {"state": [4 values]} — the observation vector for CartPole [cart_position, cart_velocity, pole_angle, pole_angular_velocity].

4. Notes

  • Model and tensors are moved to npu:0; NPU init is wrapped in try-except with a CPU fallback.
  • No CUDA calls; verified by grep for cuda (case-insensitive) in inference.py.
  • Observation ranges for CartPole are roughly [-4.8, 4.8]; raw values are used directly.

5. Directory layout

.
├── inference.py            # dual-mode NPU inference (CLI + FastAPI)
├── README.md
├── assets/                 # 3 screenshots (NPU workflow / CLI / web)
└── model_weights/          # git-ignored weight cache
    └── ppo-seals-CartPole-v0/policy.pth