Unity ML-Agents PPO 强化学习智能体(Pyramids 环境)模型在华为昇腾 NPU 上的推理适配。
本项目为非 LLM 强化学习模型,不使用 vLLM-Ascend,直接以
torch_npu完成图内推理,精度与官方权重一致。
| 项目 | 内容 |
|---|---|
| 来源 | HuggingFace Nablaaa/ppo-Pyramids |
| 类型 | Unity ML-Agents PPO(Proximal Policy Optimization) |
| 环境 | Pyramids(金色金字塔收集任务) |
| 观测输入 | 172 维向量观测 |
| 网络结构 | 2 层 MLP(512 单元) → 5 个离散动作 + 1 维价值 |
| 权重文件 | Pyramids/*.pt (torch checkpoint) |
| 昇腾算子 | 全 PyTorch 原生算子,无需自定义 Kernel |
权重在仓库 Pyramids/ 目录(来自 HuggingFace Nablaaa/ppo-Pyramids),也可从 AtomGit 镜像拉取:
git clone https://atomgit.com/hf_mirrors/Nablaaa/ppo-Pyramids.git --branch main# 在 NPU 上运行(--device npu:0)
python3 inference.py --model-dir . --device npu:0 --deterministic
# 精度对比用 CPU
python3 inference.py --model-dir . --device cpu --deterministic[info] 使用权重: ./Pyramids/Pyramids-3349901.pt
[info] 使用设备: npu:0, 可用显存: 62.0 GB
[prJ] logits = [-0.146 0.046 -0.041 0.122 -0.058]
[prJ] value = 0.1696
[prJ] action = 3
[perf] 平均单步延迟: 0.52 ms/step (device=npu:0)
[status] NPU 推理成功对比 CPU 与 NPU 的同输入输出(固定观测向量):
python3 inference.py --model-dir . --device cpu --deterministic --num-runs 1
python3 inference.py --model-dir . --device npu:0 --deterministic --num-runs 1同一输入下,logits / value 的余弦相似度应为 1.000000,动作一致。
ppo-Pyramids/
├── inference.py # 推理脚本(NPU/CPU,必选)
├── README.md # 本文档(含 {hardware NPU} 标签)
├── requirements.txt # 环境依赖清单
└── assets/ # 截图素材
├── agent_workflow.png # 智能体重建流程截图
├── npu_device_call.png # NPU 设备调用截图
└── model_result.png # 推理结果截图Apache 2.0