模型名称: ppo-LunarLander-v2(Tunamelon/ppo-LunarLander-v2)
模型链接:
模型描述: Stable-Baselines3 训练的 PPO 离散控制智能体(LunarLander-v2 环境):观测 8 维(位置/速度/角度/角速度/触地),策略为共享特征 MLP(64/64, Tanh),输出 4 个离散动作 logits(啥也不做/左引擎/主引擎/右引擎)。本部署使用训练到 84 万步的标准 SB3 检查点 PPO_84/policy.pth,在昇腾 NPU 上直接重建策略网络完成前向推理,无需安装 Stable-Baselines3 / Gymnasium。
模型架构: MLP 策略:obs(8) → Dense64(Tanh) → Dense64(Tanh) → 4 离散动作 logits,附值函数头。
参数规模: 约 5.1K 参数。
适配引擎: 昇腾 torch_npu(SB3 policy.pth → PyTorch 重建 → NPU 推理)。
| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| Python | >= 3.10(推荐 3.11) | 本机 3.11.14 |
| CANN Toolkit | 8.0.RC2+ | 本机 8.5.1 |
| torch | 2.9.0+cpu | 本机 |
| torch_npu | 2.9.0.post1 | 昇腾 NPU 适配层 |
| huggingface_hub | 0.36.2 | 权重下载 |
无需 Stable-Baselines3 / Gymnasium:本脚本直接解析
policy.pth重建等价策略网络。
硬件: 昇腾 Ascend910_9362(64GB HBM ×2)。
# 方式一:推理脚本自动下载(推荐)
python3 inference.py --device npu:0 # 首次自动拉取 PPO_84/policy.pth
# 方式二:手动下载
mkdir -p model
curl -sSL -o model/policy.pth \
"https://hf-mirror.com/Tunamelon/ppo-LunarLander-v2/resolve/main/PPO_84/policy.pth"npu-smi info
python3 -c "import torch, torch_npu; print(torch.npu.device_count())" # 输出 2python3 inference.py --device npu:0 --batch 512 --warmup 3 --runs 10命令:
python3 inference.py --device npu:0 --batch 512 --warmup 3 --runs 10输出(关键部分):
[模型加载] PPO-LunarLander 策略重建完成 (SB3 policy.pth), 参数量 5.1K, 设备 npu:0
架构: obs(8) -> MLP(64/64, Tanh) -> 4 离散动作 logits
[推理] 合成 LunarLander 观测: batch=512 x obs(8) -> 4 离散动作
logits 形状: (512, 4), value 形状: (512,)
action 前 10 个 (argmax): [1, 3, 2, 1, 1, 3, 3, 2, 3, 3]
action 分布: {0: 40, 1: 174, 2: 149, 3: 149}
logits 范围: [-12.3094, 11.6161]
value 范围: [-94.9074, 133.5804]
[性能基准] device=npu:0 warmup=3 runs=10
平均推理时延 = 0.155 ms/批 (3299294 obs/s)
(batch=512 x obs(8), MLP 前向)结果分析: SB3 PPO 策略在昇腾 NPU 上完成离散动作推理,4 个动作的 argmax 分布合理(引擎选择呈现偏好),logits/值函数输出范围合理,推理时延 0.155ms/批(330 万 obs/s),验收通过。
PPO_70/75/84/89/90 多个训练检查点及顶层 ppo-LunarLander-v2/policy.pth。顶层权重含自定义 features_extractor(9 维输入,结构不标准),本部署选用标准 SB3 结构的 PPO_84/policy.pth(obs 8 维)——结构明确、便于忠实重建。policy.pth 是纯 PyTorch state dict,torch.load(weights_only=True) 加载,键含 mlp_extractor.policy_net.* / action_net.* / value_net.*。