SB3 (stable-baselines3) 训练的 PPO 强化学习策略, 环境为 Gymnasium Pendulum-v1。
本仓库为 Ascend 910 (torch-npu) 适配版:
npu:0{"observation": [cosθ, sinθ, θ̇]} (3 维), 不是图片action (1 维, 取值范围 [-2, 2])POST /predict 服务两种模式npu:0), CANN ≥ 8.0pip install -r requirements.txt权重缓存于 ./model_weights/HumanCompatibleAI/ppo-Pendulum-v1/:
| 文件 | 说明 |
|---|---|
ppo-Pendulum-v1.zip | SB3 PPO 策略权重 |
config.yml | SB3 算法超参数 |
args.yml | 训练参数 |
env_kwargs.yml | 环境参数 |
缺失时 inference.py 会自动从 hf-mirror.com 下载; 已缓存直接复用。
python inference.py --img test_state.jsontest_state.json 内容:
{"observation": [0.5, 0.866, 0.1]}输出:
{
"action": [0.3456],
"action_clipped": 0.3456,
"action_low": -2.0,
"action_high": 2.0,
"obs": [0.5, 0.866, 0.1],
"inference_ms": 12.34,
"model": "HumanCompatibleAI/ppo-Pendulum-v1",
"actual_device": "npu:0",
"exit_status": 0
}python inference.py --serve --port 8000推理请求 (multipart 上传 JSON 文件):
curl -F "file=@test_state.json" http://127.0.0.1:8000/predict返回 {"action": [...], "action_clipped": ..., "exit_status": 0, ...}。
Pendulum-v1 观测为 3 维: [cos θ, sin θ, 角速度 θ̇]。动作为一维连续扭矩, 取值范围 [-2, 2]。
策略前向使用 PPO GaussianDiagDistribution 的 mode (均值) 作为确定性动作, 全部在 NPU 上完成。