| 项目 | 内容 |
|---|---|
| 模型名称 | HumanCompatibleAI/ppo-Pendulum-v1 |
| 模型来源 | HuggingFace |
| 模型类型 | Stable-Baselines3 PPO (强化学习策略网络) |
| 架构 | MLPPolicy (ActorCriticPolicy + MLPExtractor) |
| 训练环境 | Pendulum-v1 (Gymnasium) |
| SB3版本 | 2.2.0a3 |
| 参数量 | ~130K |
| 适配状态 | 适配成功 |
输入层 (3维: [cos(θ), sin(θ), θ̇])
│
├── 策略网络 (policy_net): Linear(3,64)+Tanh → Linear(64,64)+Tanh
│ │
│ └── action_net: Linear(64, 1) → 关节扭矩
│
├── 价值网络 (value_net): Linear(3,64)+Tanh → Linear(64,64)+Tanh
│ │
│ └── value_net: Linear(64, 1) → 状态价值
│
└── log_std: Parameter(64, 1) - SDE探索噪声pip install -r requirements.txt核心依赖:
git clone https://gitcode.com/gcw_coj3XaOd/HumanCompatibleAI_ppo-Pendulum-v1.git
cd HumanCompatibleAI_ppo-Pendulum-v1# 在Ascend NPU上运行推理
python3 inference.py --device npu:0 --num-episodes 10 --benchmark
# 在CPU上运行推理
python3 inference.py --device cpu --num-episodes 10# 检查NPU设备状态
npu-smi info
# 验证torch_npu可用
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"
# 确认模型权重文件存在
ls model_weights/ppo-Pendulum-v1/policy.pth# 获取最优动作(Pendulum-v1 初始状态)
python3 inference.py --device npu:0 --model-path model_weights/ppo-Pendulum-v1/policy.pth
# 运行完整episode评估
python3 inference.py --device npu:0 --num-episodes 10 --benchmark| 参数 | 说明 | 默认值 |
|---|---|---|
--model-path | policy.pth模型路径 | 内置路径 |
--device | 推理设备 (cpu / npu:0) | cpu |
--num-episodes | 运行episode数量 | 10 |
--benchmark | 运行性能基准测试 | False |
--stochastic | 使用随机策略 | False |
============================================================
PPO Pendulum-v1 Inference on Ascend NPU
============================================================
Model path: model_weights/ppo-Pendulum-v1/policy.pth
Device: cpu
PyTorch version: 2.9.0+cpu
NumPy version: 1.26.4
Gymnasium version: 1.3.0
[Test 1] 最优动作预测
Initial obs: [cos(theta)=-1.0000, sin(theta)=0.0000, theta_dot=0.0000]
Optimal action (torque): -1.908298
[Test 2] Running 10 episodes...
Episode 1: reward=-135.91, steps=200
Episode 2: reward=-135.91, steps=200
Episode 3: reward=-135.91, steps=200
Summary (10 episodes):
Mean reward: -135.91 +/- 0.00
Min reward: -135.91
Max reward: -135.91
[Test 3] Latency benchmark...
Avg latency: 0.35ms
Throughput: 2891 inferences/sec
============================================================Pendulum-v1 是一个倒立摆控制任务,目标是通过施加关节扭矩使摆保持直立。
初始状态: 摆垂直向下 (θ=π, θ̇=0) 最优动作: -1.91 (施加扭矩使摆开始向上摆动)
Episode奖励分析:
| 算子 | 类型 | Ascend兼容性 |
|---|---|---|
| nn.Linear | Torch原生 | ✅ 完全兼容 |
| nn.Tanh | Torch原生 | ✅ 完全兼容 |
| torch.clip | Torch原生 | ✅ 完全兼容 |
所有算子均为原生PyTorch算子,无CUDA/Triton自定义算子,100%兼容Ascend NPU。
本项目采用torch_npu直接推理方案,不涉及vLLM框架修改。
适配流程:
测试环境: Pendulum-v1 (Gymnasium), deterministic policy, 10 episodes
评测指标:
| 指标 | 结果 |
|---|---|
| Episode Reward (mean) | -135.91 |
| Episode Reward (std) | 0.00 |
| Episode Reward (min) | -135.91 |
| Episode Reward (max) | -135.91 |
| Episode Length | 200 steps |
| 任务成功率 | 0% (持续控制,未达到直立稳定) |
评测命令:
python3 inference.py --device cpu --num-episodes 10分析: Pendulum-v1 的任务目标是保持倒立摆直立(cos(θ)≈1)。从直立位置(θ=π)开始,策略网络输出初始扭矩 -1.91 使摆获得角速度向上摆动。由于策略为确定性策略且训练环境与测试一致,10轮episode reward完全一致(-135.91),表明策略行为稳定可复现。



本仓库仅包含推理适配代码,模型权重归原始作者所有。