ActorCriticPolicy MLP 策略网络(PPO Actor-Critic):
[x, y, vx, vy, angle, vangle, leg1, leg2](水平位置/高度/水平速度/垂直速度/倾角/角速度/两腿触地标记);[不做任何事, 左引擎, 主引擎, 右引擎];[64, 64](tanh)→ 4 维动作 logits;[64, 64](tanh)→ 1 维状态值;ppo-LunarLander-v2.zip):观测在送入网络前会先由
CustomFeatureExtractor 计算 time_until_impact(预计触地时间) 特征并拼接为 9 维输入,
再经 MLP 输出动作。mean_reward = 301.34 ± 16.08(10 个回合,deterministic)。/data/models/Tunamelon/ppo-LunarLander-v2/,包含 6 个 checkpoint:
ppo-LunarLander-v2.zip(主模型,自定义架构)、PPO_70/PPO_75/PPO_84/PPO_89/PPO_90.zip(训练阶段快照,标准架构)。| 组件 | 版本 |
|---|---|
| 操作系统 | HCE (aarch64, Linux 5.10) |
| Python | 3.11.14 |
| CANN | 8.5.1 |
| NPU | Ascend 910B(Ascend910_9362 ×2,64GB HBM) |
| torch | 2.9.0 |
| torch-npu | 2.9.0.post1 |
| stable-baselines3 | 2.9.0 |
| gymnasium | 1.3.0 |
| box2d-py | 2.3.8 |
| pygame | 2.6.1 |
| numpy | 1.26.4 |
| cloudpickle | 3.1.2 |
说明:vllm 0.18.0 / vllm-ascend 0.18.0 在本机已安装,但不适用于本题(详见第 6 节); 本题适配唯一可用且已验证的昇腾推理引擎为 torch_npu。
./venv,可跳过)# 在本目录内创建 venv(继承系统已装好的 torch / torch_npu,避免重复安装大包)
python3 -m venv --system-site-packages venv && source venv/bin/activate若系统 Python 已具备 torch / torch-npu / numpy,也可跳过 venv 直接使用系统 Python。
# 在 venv 中安装
pip install -r requirements.txt \
-i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn
# 或
pip install -r requirements.txt \
-i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com说明:
- torch / torch-npu 请使用系统预装版本(昇腾官方 wheel 仓库,与 CANN 配套), 勿从 PyPI 镜像安装(镜像上的 torch 为 CPU/GPU 构建,不与 torch_npu 匹配)。
box2d-py为 LunarLander 物理引擎依赖,需源码编译,请先安装swig(requirements.txt 已含), 并确保swig在 PATH 中(venv 安装后为./venv/bin/swig)。
./venv/bin/python -c "import torch, torch_npu; print('NPU count:', torch.npu.device_count())"./venv/bin/python inference.py --list-cases输出(NPU 实测):
==============================================================================
Tunamelon/ppo-LunarLander-v2 昇腾 NPU 推理 (torch_npu 引擎)
模型目录 : /data/models/Tunamelon/ppo-LunarLander-v2
NPU 可用 : True 设备数: 2
设备信息 : Ascend910_9362 (npu:0)
torch : 2.9.0+cpu torch_npu: 2.9.0.post1+gitee7ba04
gymnasium: 1.3.0 环境: LunarLander-v3
==============================================================================
共 60 组测试用例:
[ 1] PPO_70 整回合推理 seed=0 (deterministic)
...
[ 60] PPO_84 动作概率分布 softmax./venv/bin/python inference.py# 单个用例
./venv/bin/python inference.py --case 21
# 多个用例(共享模型缓存)
./venv/bin/python inference.py --case 1,2,3
# 运行全部 60 组
./venv/bin/python inference.py --all# 指定 checkpoint
./venv/bin/python inference.py --checkpoint PPO_89 --episodes 5
# 指定 NPU 设备
./venv/bin/python inference.py --case 21 --device npu:1
# 无 NPU 环境时 CPU 回退
./venv/bin/python inference.py --device cpu以下为 60 组完整测试用例在昇腾 NPU(torch_npu)上的实测输出汇总(一次 --all 运行,总耗时 6.05s)。
每个用例均可通过 ./venv/bin/python inference.py --case <编号> 复现。
ppo-LunarLander-v2(自定义 time_until_impact 架构)前向推理与整回合| 用例# | 名称 | 指标(NPU 实测) |
|---|---|---|
| 1 | PPO_70 整回合 seed=0 | 回报 307.95 steps=203 成功着陆 |
| 2 | PPO_70 整回合 seed=1 | 回报 271.95 steps=234 成功着陆 |
| 3 | PPO_70 整回合 seed=2 | 回报 251.11 steps=211 成功着陆 |
| 4 | PPO_70 整回合 seed=3 | 回报 245.93 steps=229 成功着陆 |
| 5 | PPO_70 整回合 seed=4 | 回报 263.04 steps=231 成功着陆 |
| 6 | PPO_70 整回合 seed=5 | 回报 282.54 steps=254 成功着陆 |
| 7 | PPO_70 整回合 seed=6 | 回报 300.44 steps=231 成功着陆 |
| 8 | PPO_70 整回合 seed=7 | 回报 274.27 steps=210 成功着陆 |
| 9 | PPO_70 整回合 seed=8 | 回报 296.83 steps=201 成功着陆 |
| 10 | PPO_70 整回合 seed=9 | 回报 248.78 steps=379 成功着陆 |
| 11 | PPO_75 整回合 seed=0 | 回报 297.90 steps=200 成功着陆 |
| 12 | PPO_75 整回合 seed=1 | 回报 275.52 steps=185 成功着陆 |
| 13 | PPO_75 整回合 seed=2 | 回报 256.14 steps=181 成功着陆 |
| 14 | PPO_75 整回合 seed=3 | 回报 249.35 steps=176 成功着陆 |
| 15 | PPO_75 整回合 seed=4 | 回报 261.58 steps=183 成功着陆 |
| 16 | PPO_75 整回合 seed=5 | 回报 285.55 steps=198 成功着陆 |
| 17 | PPO_75 整回合 seed=6 | 回报 326.34 steps=225 成功着陆 |
| 18 | PPO_75 整回合 seed=7 | 回报 276.01 steps=171 成功着陆 |
| 19 | PPO_75 整回合 seed=8 | 回报 299.94 steps=191 成功着陆 |
| 20 | PPO_75 整回合 seed=9 | 回报 316.95 steps=203 成功着陆 |
| 21 | PPO_84 整回合 seed=0 | 回报 313.70 steps=167 成功着陆 |
| 22 | PPO_84 整回合 seed=1 | 回报 279.31 steps=187 成功着陆 |
| 23 | PPO_84 整回合 seed=2 | 回报 260.41 steps=170 成功着陆 |
| 24 | PPO_84 整回合 seed=3 | 回报 250.73 steps=171 成功着陆 |
| 25 | PPO_84 整回合 seed=4 | 回报 266.23 steps=178 成功着陆 |
| 26 | PPO_84 整回合 seed=5 | 回报 289.56 steps=190 成功着陆 |
| 27 | PPO_84 整回合 seed=6 | 回报 324.25 steps=231 成功着陆 |
| 28 | PPO_84 整回合 seed=7 | 回报 276.52 steps=178 成功着陆 |
| 29 | PPO_84 整回合 seed=8 | 回报 296.03 steps=180 成功着陆 |
| 30 | PPO_84 整回合 seed=9 | 回报 317.47 steps=219 成功着陆 |
| 31 | PPO_89 整回合 seed=0 | 回报 308.74 steps=192 成功着陆 |
| 32 | PPO_89 整回合 seed=1 | 回报 273.07 steps=210 成功着陆 |
| 33 | PPO_89 整回合 seed=2 | 回报 254.24 steps=200 成功着陆 |
| 34 | PPO_89 整回合 seed=3 | 回报 243.91 steps=204 成功着陆 |
| 35 | PPO_89 整回合 seed=4 | 回报 261.60 steps=208 成功着陆 |
| 36 | PPO_89 整回合 seed=5 | 回报 283.16 steps=211 成功着陆 |
| 37 | PPO_89 整回合 seed=6 | 回报 321.20 steps=232 成功着陆 |
| 38 | PPO_89 整回合 seed=7 | 回报 270.83 steps=202 成功着陆 |
| 39 | PPO_89 整回合 seed=8 | 回报 288.52 steps=205 成功着陆 |
| 40 | PPO_89 整回合 seed=9 | 回报 317.11 steps=225 成功着陆 |
| 41 | PPO_90 整回合 seed=0 | 回报 304.57 steps=222 成功着陆 |
| 42 | PPO_90 整回合 seed=1 | 回报 268.95 steps=248 成功着陆 |
| 43 | PPO_90 整回合 seed=2 | 回报 248.69 steps=237 成功着陆 |
| 44 | PPO_90 整回合 seed=3 | 回报 244.68 steps=216 成功着陆 |
| 45 | PPO_90 整回合 seed=4 | 回报 262.05 steps=226 成功着陆 |
| 46 | PPO_90 整回合 seed=5 | 回报 275.81 steps=250 成功着陆 |
| 47 | PPO_90 整回合 seed=6 | 回报 322.41 steps=253 成功着陆 |
| 48 | PPO_90 整回合 seed=7 | 回报 270.55 steps=223 成功着陆 |
| 49 | PPO_90 整回合 seed=8 | 回报 291.45 steps=222 成功着陆 |
| 50 | PPO_90 整回合 seed=9 | 回报 316.37 steps=251 成功着陆 |
| 51 | 主模型 单样本前向 npu:0 | logits [-0.0058, 0.0104, 0.0118, 0.0052] → 动作 2 |
| 52 | 主模型 单样本前向 npu:1 | logits [-0.0085, 0.0102, 0.0017, 0.0073] → 动作 1 |
| 53 | 主模型 批量 4 样本前向 | logits 4×4 → 动作 [3, 3, 3, 2] |
| 54 | 主模型 整回合 seed=0 | 回报 -679.42(策略权重为初始化尺度,详见第 5.2 节) |
| 55 | PPO_84 CPU vs NPU 一致性 | 最大偏差 1.907e-06(float32 精度一致) |
| 56 | PPO_84 npu:0 vs npu:1 一致性 | 最大偏差 0.000e+00(完全一致) |
| 57 | PPO_84 随机策略整回合 seed=1 | 回报 281.24 steps=194 成功着陆 |
| 58 | PPO_84 值函数输出 | [157.06, 130.78, 209.82, 74.44](状态值估值) |
| 59 | PPO_84 批量 8 样本动作推理 | 动作 [1, 2, 1, 1, 3, 3, 1, 1](logits 幅度正常) |
| 60 | PPO_84 动作概率分布 | softmax=[0.1463, 0.8478, 0.0009, 0.005] → 动作 1 |
汇总(5 个已训练快照 × 10 回合,NPU 实测):
| checkpoint | 平均回报 | 成功着陆率 |
|---|---|---|
| PPO_70 | 274.28 | 10/10 |
| PPO_75 | 284.53 | 10/10 |
| PPO_84 | 287.42 | 10/10 |
| PPO_89 | 282.24 | 10/10 |
| PPO_90 | 280.55 | 10/10 |
与模型卡片
mean_reward = 301.34(v2 环境, 10 回合)量级一致,NPU 实测略高/略低属正常波动。
ppo-LunarLander-v2.zip 的说明主模型 checkpoint 采用自定义 CustomFeatureExtractor(计算 time_until_impact 拼接为 9 维输入)架构。
经权重分析,其 policy.pth 中各层权重处于 PyTorch/SB3 初始化尺度(action_net 权重 std≈0.00125,
恰为 SB3 last_layer_gain=0.01 的 orthogonal 初始化;其余层 std≈0.177 为 Kaiming/orthogonal 初始化),
即该主 checkpoint 的 policy.pth 未包含训练完成的权重(上游仓库上传产物问题),因此用例 51–54 中
其前向输出 logits 幅度极小、整回合回报为负。
PPO_84.zip 等(标准架构)权重完整、训练充分,在 NPU 上全部成功着陆(平均回报 ≈ 287)。inference.py 同时支持两种架构(自动识别),主模型前向亦可在 NPU 上完整运行,
仅策略质量受限于权重本身。本题不适用 vllm-ascend 或 sglang 推理引擎。 原因如下:
模型架构非 LLM:ppo-LunarLander-v2 是强化学习 MLP 策略网络(torch.nn.Module),
而非 Transformer 自回归语言模型。vllm-ascend / sglang 面向 LLM 推理(PagedAttention、KV cache、
tokenizer/vocab、逐 token 生成),其模型注册表不含 MLP RL 策略架构,无法加载运行。
推理模式非生成式:本题一次前向(8/9 维观测 → 4 维动作 logits)即得决策, 无需逐 token 生成。
唯一可用引擎:torch_npu。策略网络前向算子(Linear / tanh / relu / clamp / where / cat / softmax)
在 device='npu:0' 下均开箱即用。无需关闭任何 CUDA 专属特性(本模型不含 flash attention / torch.compile 依赖)。
torch_npu 推理对比2:
| 特性 | torch_npu(本适配) | vllm-ascend | sglang |
|---|---|---|---|
| 模型加载 ✅ | 支持(policy.pth → MLP) | ❌ 无对应架构 | ❌ 无对应架构 |
| NPU 推理 ✅ | 已验证(60 用例) | ❌ 不适用 | ❌ 不适用 |
| 批量/接口推理 ✅ | 支持 | ❌ | ❌ |
| 精度一致性 ✅ | NPU/CPU 差 1.9e-06 | ❌ | ❌ |
ppo-LunarLander-v2-NPU/
├── inference.py # 推理脚本(torch_npu 昇腾引擎)
├── README.md # 本文件
├── requirements.txt # 依赖包列表
├── assets/ # 资源目录
│ └── .gitkeep # 占位空文件
└── venv/ # Python 虚拟环境(含 torch/torch_npu 继承)/data/models/Tunamelon/ppo-LunarLander-v2/
├── config.json # SB3 PPO 训练配置
├── README.md # 模型卡片
├── results.json # 官方评测结果(mean_reward=301.34)
├── replay.mp4 # 回放视频
├── ppo-LunarLander-v2.zip # 主模型(自定义 time_until_impact 架构)⚠️ 权重为初始化尺度
├── ppo-LunarLander-v2/ # 主模型解压目录(policy.pth 等)
├── PPO_70.zip / PPO_75.zip # 训练阶段快照(标准架构)✅
├── PPO_84.zip # 训练阶段快照(标准架构)✅ 最佳
├── PPO_89.zip / PPO_90.zip # 训练阶段快照(标准架构)✅
└── PPO_8x/ # 各快照解压目录贡献者: z_studio | 赛道: 模型适配赛道
Tunamelon, "ppo-LunarLander-v2", HuggingFace Model Hub, https://huggingface.co/Tunamelon/ppo-LunarLander-v2 ↩
昇腾社区, "torch_npu — PyTorch 昇腾适配插件", https://gitee.com/ascend/pytorch ↩