HumanCompatibleAI/ppo-seals-CartPole-v0a86541dd3744275227cb16d07192967fc6b7775ediscrete-policy-ppo(PPO discrete policy,CartPole-v0 4-dim 观测 → 2 维 logits → Discrete(2))npu:0(Ascend 910B,torch_npu)强化学习 离散控制策略,stable-baselines3 PPO MlpPolicy pi=[64,64] ReLUppo-seals-CartPole-v0/policy.pth 40641 bytes,本地加载 snapshot_download 固定 revisionBox(4,) float32 [cart_pos, cart_vel, pole_angle, pole_vel],无需归一化(batch,2) → argmax 得离散动作 0:left 1:right,horizon=1,coord_frame=cartpole-discrete,确定性采样 seed=0{
"torch_version": "2.9.0+cpu",
"torch_npu_available": true,
"device_name": "Ascend910_9362",
"device_count": 2,
"python_version": "3.11.14",
"dtype": "float32",
"model_dir": "/opt/atomgit/adapt-npu-agent/.cache_hf/models--HumanCompatibleAI--ppo-seals-CartPole-v0/snapshots/a86541dd3744275227cb16d07192967fc6b7775e",
"policy_path": "ppo-seals-CartPole-v0/policy.pth",
"weight_bytes": 40641
}安装:pip install -r requirements.txt(torch, torch-npu, numpy, huggingface_hub)
默认执行:python inference.py
显式:python inference.py --device npu:0 --dtype float32
inference.py 默认从本地固定 revision 加载权重,打印 model/revision/route/backend/device/dtype、npu-smi、输入摘要、模型/输入/输出 device 证明、torch.npu.synchronize() 计时、CPU-NPU 一致性与最终 PASS/FAIL。
{
"observation_schema": "Box(4,) float32",
"observation_dim": 4,
"observation_fields": ["cart_position", "cart_velocity", "pole_angle", "pole_angular_velocity"],
"normalize": false,
"batch": 8,
"dtype": "float32",
"examples": {
"zero_state": [0.0, 0.0, 0.0, 0.0],
"small_pos": [0.1, 0.2, -0.05, -0.1],
"large_pos": [1.0, 0.5, 0.2, 0.3],
"large_neg": [-1.0, -0.5, -0.2, -0.3],
"mixed": [0.5, 0.0, 0.1, 0.0]
},
"finite": 1.0,
"seed": 0,
"sampler": "deterministic argmax"
}{
"logits_shape": [8, 2],
"actions_shape": [8],
"logits_dtype": "float32",
"logits_device": "npu:0",
"input_device": "npu:0",
"first_param_device": "npu:0",
"sample_logits_row0_cpu": [0.5115560293197632, -0.5097886323928833],
"sample_logits_row0_npu": [0.5115558505058289, -0.5097885727882385],
"actions_cpu": [0, 0, 1, 0, 1, 0, 0, 1],
"actions_npu": [0, 0, 1, 0, 1, 0, 0, 1],
"logits_stats_cpu": {"mean": -0.00074, "std": 4.261033, "min": -7.645267, "max": 7.639793},
"finite": 1.0,
"horizon": 1,
"action_dim": 2,
"coordinate_frame": "cartpole-discrete"
}同一权重、同一观测 batch、同一预处理、同一确定性 argmax、同 dtype float32,比较 logits 数值:
{
"passed": true,
"atol": 0.0001,
"rtol": 0.001,
"max_abs_diff": 9.5367431640625e-07,
"mean_abs_diff": 2.905726e-07,
"shape": [8, 2],
"elements": 16,
"pearson": 1.0,
"actions_equal": true,
"finite_cpu": 1.0,
"finite_npu": 1.0,
"strict_allclose_atol1e-5_rtol1e-5": true
}额外 rollout 演示(单步确定性决策,非替代验证):[0,0,0,0] -> [0.51,-0.50] -> 0,[0,0,0.05,0] -> [-0.83,0.83] -> 1。
torch.npu.synchronize() 包围的稳定计时(warmup 3,正式 10):
{
"avg_ms": 0.162,
"p50_ms": 0.162,
"min_ms": 0.16,
"max_ms": 0.169,
"batch": 8,
"horizon": 1,
"dtype": "float32",
"device": "npu:0",
"warmup": 3,
"stable_runs": 10,
"decisions_per_s": 49307.5,
"actions_per_s": 49307.5,
"batches_per_s": 6163.4,
"throughput_unit": "decisions/s"
}


三张图片均由 xterm.js 根据本次真实日志生成。
npu:0 环境完成验证。argmax 采样;随机采样未测试但 NPU 噪声张量可复用 CPU 同步机制(skill npu-validation)。#NPU #Ascend #Ascend910 #reinforcement-learning #PPO