Tunamelon/ppo-LunarLander-v2 - Ascend NPU Adaptation
Model: Tunamelon/ppo-LunarLander-v2
Revision: f0b8ee438f823e7bbadf44d71821cd5c7257a4c1
Route: offline-rl (state -> discrete action)
Backend: torch_npu on Ascend910 (npu:0)
Task: LunarLander-v2 discrete control (4 actions)
任务与契约
- 输入: 8-dim continuous observation (Box, float32) :
[x, y, vx, vy, angle, angular_velocity, leg1_contact, leg2_contact] standardized range approx [-90,90] for pos, [-5,5] for velocities, [-3.14,3.14] for angle. Horizon=1, batch=1, dtype=float32.
- 输出: discrete ActionPlan over 4 actions (0: no-op, 1: left engine, 2: main engine, 3: right engine). Logits shape (1,4), deterministic argmax. Horizon 1, action_dim 4, coordinate_frame: discrete.
- Sampler: deterministic argmax, seed 42, no stochastic sampling, no diffusion steps.
模型结构
- SB3 PPO MlpPolicy :
policy_net 8->64 (Tanh) ->64 (Tanh) -> action_net 64->4 ; value_net parallel. Total params ~12k, FP32. Loaded from PPO_90/policy.pth (stable checkpoint with mean_reward ~300, compatible with gymnasium 1.3 / SB3 2.9). Weight bytes ~43KB.
真实结果
- NPU device: Ascend910_9362, npu:0, torch_npu 2.9.0.post1, CANN 8.5.1,
torch.npu.is_available()=True, device_count=2
- 输入 device: npu:0, 模型 device: npu:0, 输出 device: npu:0, all verified via
torch.npu.synchronize() timing.
- CPU logits:
[1.7262803316116333, 1.8573778867721558, -1.182193636894226, -0.5340890288352966] (action 1)
- NPU logits:
[1.7262804508209229, 1.8573781251907349, -1.1821937561035156, -0.5340891480445862] (action 1)
- 一致性: max_abs=2.38e-07, mean_abs=1.5e-07, tolerance atol=1e-4 rtol=1e-3 => PASS
- 有限值/Bounds: all finite, action in [0,3], shape (1,4) PASS
性能
- 首轮编译: ~125 ms (first NPU run includes graph compilation)
- 稳定推理: avg 0.29 ms / decision, min 0.276 ms, max 0.336 ms, p50 0.282 ms, p90 0.295 ms, p95 0.336 ms (10 samples, batch=1, 1 decision/call)
- 吞吐: ~3451 decisions/s, ~3451 actions/s, horizon 1
- 显存: < 100MB, single Ascend910 64GB OK, no model sharding.
环境限制
- 单卡 Ascend910B, CANN 8.5.1, PyTorch 2.9.0 + torch_npu 2.9.0.post1, Python 3.11, SB3 2.9.0, gymnasium 1.3.0, numpy 1.26.4 (patched for _core compat), no Box2D env needed for policy inference (obs synthesized). NPU proof requires
torch.npu.synchronize() around timing.
- Remote code: no
trust_remote_code, no network fetch at inference (local ckpt fallback to HF Hub only if missing).
复现
pip install -r requirements.txt
python inference.py
# Expected: device=npu:0, status=PASS, max_abs < 1e-4
证据

权重