中文简介:本仓库是 HumanCompatibleAI/ppo-Pendulum-v1(Stable-Baselines3 PPO,MlpPolicy + gSDE)
在华为昇腾 Ascend910B4(物理 npu:1)上的推理示例。CPU 仅用于编排/反序列化/预处理,策略与价值网络的
前向计算全部在 npu:1 上执行,并对输入/模型/输出的设备位置做严格断言。发布文件集不包含权重字节;
推理脚本从固定的本地不可变检查点严格加载并校验字节数与 SHA256。
HumanCompatibleAI/ppo-Pendulum-v16a0fe838119427278252dde3bf723ed7a3266df5ppo-Pendulum-v1.zip — 137832 bytes, SHA256
d2a5572df0c6d6022519615b76c9e6ca5bce0e7d5cf859ec145cbf99a437b8b0ActorCriticPolicy, MlpPolicy, use_sde=True)npu:1, CANN cann-8.5.1, engine torch_npulicense field; the front matter above
therefore uses AtomGit-valid license: other to denote a non-standard / undeclared license. The
weights are treated as license-not-declared; do not assume a permissive license for
redistribution without upstream confirmation.This is a trained PPO agent playing Pendulum-v1 using the
stable-baselines3 library and the
RL Zoo framework
(HumanCompatibleAI/ppo-Pendulum-v1). The observation space is
Box([-1 -1 -8], [1 1 8], (3,), float32) (cos(theta), sin(theta), angular velocity) and the
action space is a single continuous torque Box(-2.0, 2.0, (1,), float32). The deterministic test
observation is [0, 0, 0].
The deterministic inference produces:
[[0.11721252650022507]], shape (1, 1)[[-74.04744720458984]], shape (1, 1)[-0.16488760709762573], shape (1,)[0.6648876070976257] (self-check: log_prob + entropy = 0.5, the exact
Gaussian-at-mean identity)DiagGaussian/gSDE Normal): loc = [[0.11721252650022507]],
scale = [[0.47045689821243286]], shape (1, 1)All tensors are on npu:1. Timing is NPU-synchronized.
Verified working image (aarch64 / openEuler 22.03 SP4):
| Component | Version |
|---|---|
| Python | 3.11.14 |
| CANN | cann-8.5.1 |
| torch | 2.9.0+cpu (preinstalled, must not be replaced) |
| torch_npu | 2.9.0 (preinstalled, must not be replaced) |
| stable-baselines3 | 2.7.0 |
| gymnasium | 1.2.0 |
| numpy | 1.26.4 |
| cloudpickle | 3.1.2 |
| scipy | 1.17.1 |
| pandas | 2.3.2 |
| matplotlib | 3.10.5 |
| psutil | 7.2.2 |
| decorator | 5.3.1 |
Important:
torch==2.9.0+cpuandtorch_npu==2.9.0are provided by the container and are matched to CANN 8.5.1. Do not reinstall them from ordinary PyPI wheels — that would break the NPU runtime.
export PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/
export PIP_TRUSTED_HOST=mirrors.aliyun.com
# Only non-torch runtime dependencies are installed from the Aliyun mirror.
pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/requirements.txt intentionally does not list torch / torch_npu.
source /usr/local/Ascend/ascend-toolkit/set_env.shnpu-smi info/work/pipeline/models/rl26/ppo-pendulum-v1/ppo-Pendulum-v1.zip, or download
ppo-Pendulum-v1.zip from the HF repo at revision 6a0fe838119427278252dde3bf723ed7a3266df5
and pass it with --model-path.npu:1:
python3 inference.py --device npu:1 --hold-seconds 8 --result-json logs/npu_result.json \
> logs/npu_inference.log 2>&1cat logs/npu_result.jsoninference.py fails nonzero on any of: missing NPU, wrong NPU index, checkpoint bytes/SHA256
mismatch, or any input/model/output placement that is not npu:1.
cd /root/ascend-model-pipeline/jobs/rl26/ppo-pendulum-v1/ppo-pendulum-v1-npu
source /usr/local/Ascend/ascend-toolkit/set_env.sh
python3 inference.py --device npu:1 --hold-seconds 8 --result-json logs/npu_result.json \
> logs/npu_inference.log 2>&1
echo "exit=$?"Actual output (exit=0, PID 7567, captured from the real final run):
[INFO] python=3.11.14 platform=Linux-5.10.0-325.0.0.226.oe2203sp4.aarch64-aarch64-with-glibc2.38
[INFO] device=npu:1 hardware=Ascend910B4-1 cann=cann-8.5.1
[INFO] package torch=2.9.0+cpu
[INFO] package torch_npu=2.9.0
[INFO] package stable_baselines3=2.7.0
[INFO] package gymnasium=1.2.0
[INFO] package numpy=1.26.4
[INFO] package cloudpickle=3.1.2
[INFO] package scipy=1.17.1
[INFO] model_path=/work/pipeline/models/rl26/ppo-pendulum-v1/ppo-Pendulum-v1.zip bytes=137832 sha256=d2a5572df0c6d6022519615b76c9e6ca5bce0e7d5cf859ec145cbf99a437b8b0
[INFO] loading SB3 PPO checkpoint onto npu:1 ...
[INFO] policy device verified: all 13 parameters + buffers on npu:1
[INFO] observation_space=Box([-1. -1. -8.], [1. 1. 8.], (3,), float32) action_space=Box(-2.0, 2.0, (1,), float32) use_sde=True
[INFO] observation value=[[0.0, 0.0, 0.0]] shape=(1, 3) dtype=torch.float32 device=npu:1
MODELAGENT_NPU_READY pid=7567 device=npu:1 hardware=Ascend910B4-1 revision=6a0fe838119427278252dde3bf723ed7a3266df5
[INFO] npu-smi correlation (PID present):
| 1 0 | 7567 | python3 | 120 |
[INFO] sanitized raw npu-smi log -> logs/npu_smi.log
[INFO] holding 8.0s for external npu-smi correlation ...
===== NPU INFERENCE RESULT (deterministic) =====
engine : torch_npu
npu_available : True
npu_device_name : Ascend910B4-1
device : npu:1 (Ascend910B4-1)
input obs : [[0.0, 0.0, 0.0]] shape=(1, 3) device=npu:1
action (mean) : shape=(1, 1) value=[[0.11721252650022507]] device=npu:1
value (critic) : shape=(1, 1) value=[[-74.04744720458984]] device=npu:1
log_prob : shape=(1,) value=[-0.16488760709762573] device=npu:1
entropy : [0.6648876070976257] device=npu:1
dist loc : [[0.11721252650022507]]
dist scale : [[0.47045689821243286]]
elapsed (s) : 0.042375
pid : 7567
===============================================
[INFO] result written to logs/npu_result.json
MODELAGENT_NPU_DONElogs/npu_result.json exposes the required top-level fields:
model_id, engine: "torch_npu", exit_code: 0, npu_available: true,
npu_device_name: "Ascend910B4-1", source_revision: "6a0fe838119427278252dde3bf723ed7a3266df5",
input_device: "npu:1", model_device: "npu:1", output_device: "npu:1", plus a top-level
output object with continuous action, value, log_prob, entropy and the Gaussian
distribution (loc/scale) — each with shapes, npu:1 device, dtype and scalar statistics
(mean/std/min/max) — together with timing (forward seconds + wall seconds) and the inference pid.
logs/npu_smi.log is the sanitized raw device log whose process line PID equals the inference PID
during the hold window.
All screenshots are rendered only from the real final transcript/log/result (no fabricated values):
assets/agent_workflow.png — ModelAgent workflow steps from the real session transcript.assets/npu_device_call.png — NPU device call / placement evidence from logs/npu_inference.log.assets/model_result.png — model result panel from the real result JSON/log.assets/modelagent_live_session.png — live ModelAgent session summary (READMEY/npu-smi correlation and result).ppo-Pendulum-v1.zip) are not
included in the published file set; supply the pinned checkpoint via --model-path.value output is the critic state-value.get_actions(deterministic=True)), so
output is reproducible across runs; gSDE exploration matrices are resampled on NPU but do not
affect the deterministic action.inference.py — deterministic SB3 PPO inference on npu:1 with strict pinned-artifact verification and placement assertions.requirements.txt — non-torch runtime dependencies (Aliyun mirror).logs/npu_inference.log — raw inference log.logs/npu_result.json — structured result JSON.logs/npu_smi.log — sanitized raw npu-smi info device log.README.md / readme.md — this document (byte-identical).SHA256SUMS — SHA-256 manifest of the published file set.assets/*.png — evidence screenshots.