liuhongwei-2026/ppo-Pyramids
模型介绍
文件和版本
Pull Requests
讨论
分析

ppo-Pyramids — 昇腾 NPU 推理

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

环境依赖

  • Python 3.10+
  • PyTorch + torch_npu(Ascend CANN 8.x)
  • 参见 requirements.txt

快速开始

权重获取

权重在仓库 Pyramids/ 目录(来自 HuggingFace Nablaaa/ppo-Pyramids),也可从 AtomGit 镜像拉取:

git clone https://atomgit.com/hf_mirrors/Nablaaa/ppo-Pyramids.git --branch main

昇腾 NPU 推理

# 在 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       # 推理结果截图

License

Apache 2.0