模型名称: PaulVialard/ppo-Huggy
模型链接: HuggingFace
模型描述: Unity ML-Agents 训练的 PPO 策略网络,用于 quadruped 机器人 "Huggy" 的强化学习策略推理。模型以 ONNX 格式(IRv4, Opset 9)导出,通过提取权重后在昇腾 NPU 上以 PyTorch 运行时推理。
模型架构: Normalization → 3×[Linear(59→512) + Sigmoid + Mul gate] → Linear(512→21) μ head → Gaussian 采样 + clip
参数规模: 566,947 参数
输入规格:
输出规格:
| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| Python | >= 3.10 | 推荐 3.11 |
| torch | >= 2.1.0 | PyTorch 框架 |
| torch_npu | >= 2.1.0 | 昇腾 NPU 后端 |
| onnx | >= 1.15.0 | ONNX 模型加载 |
| numpy | >= 1.20.0 | 数值计算 |
| 昇腾驱动 | CANN 8.0+ | 推荐 CANN 8.5.1 |
安装命令:
pip install torch>=2.1.0 torch-npu>=2.1.0 onnx>=1.15.0 numpy>=1.20.0# 检查 NPU 设备
npu-smi info
# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"方式一:HuggingFace(推荐)
export HF_ENDPOINT=https://hf-mirror.com
huggingface-cli download PaulVialard/ppo-Huggy --local-dir ./model_weights方式二:AtomGit 镜像(HuggingFace 下载慢时使用)
curl -L "https://ai.gitcode.com/hf_mirrors/PaulVialard/ppo-Huggy/resolve/main/Huggy.onnx" -o ./Huggy.onnx# 确定性推理(推荐用于部署)
python3 inference.py --model-path ./model_weights --deterministic
# 随机采样推理
python3 inference.py --model-path ./model_weights
# 指定随机种子
python3 inference.py --model-path ./model_weights --seed 42 --deterministic| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| --model-path | str | 必填 | ONNX 模型文件(.onnx)或包含 .onnx 的目录路径 |
| --seed | int | None | 随机种子(仅随机采样模式有效) |
| --deterministic | flag | False | 使用确定性动作输出(clip(mu/3, -1, 1)) |
| --batch-size | int | 1 | 推理 batch size |
[模型] PaulVialard/ppo-Huggy
[设备] Ascend910_9362 (npu:0)
[输入] observation: shape=torch.Size([1, 59]), dtype=float32
[输出] actions: shape=torch.Size([1, 21]), dtype=float32
[输出样例] [0.9832671 0.11903998 0.7608468 0.5919389 -0.31808838] ... (前5维)
[状态] SUCCESS[基准测试] 10次推理统计 (batch_size=1):
平均: 0.34 ms
最小: 0.31 ms
最大: 0.45 ms
标准差: 0.04 ms
P50: 0.32 ms
P99: 0.45 ms注意: 推理失败时输出
[状态] FAILED和错误信息,不会静默退出。
运行命令:
python3 inference.py --model-path ./model_weights --deterministic输出:
[信息] ONNX模型路径: /tmp/adapt_paulvialard_ppo-huggy/weights/Huggy.onnx
[信息] 设备: Ascend910_9362 (npu:0)
[信息] 模式: 确定性
[基准测试] 10次推理统计 (batch_size=1):
平均: 0.34 ms
最小: 0.31 ms
最大: 0.45 ms
标准差: 0.04 ms
P50: 0.32 ms
P99: 0.45 ms
[模型] PaulVialard/ppo-Huggy
[设备] Ascend910_9362 (npu:0)
[输入] observation: shape=torch.Size([1, 59]), dtype=float32
[输出] actions: shape=torch.Size([1, 21]), dtype=float32
[输出样例] [ 0.9832671 0.11903998 0.7608468 0.5919389 -0.31808838] ... (前5维)
[状态] SUCCESS运行命令:
python3 inference.py --model-path ./model_weights --seed 42输出:
[信息] ONNX模型路径: /tmp/adapt_paulvialard_ppo-huggy/weights/Huggy.onnx
[信息] 设备: Ascend910_9362 (npu:0)
[信息] 模式: 随机采样
[基准测试] 10次推理统计 (batch_size=1):
平均: 0.35 ms
最小: 0.31 ms
最大: 0.44 ms
标准差: 0.04 ms
P50: 0.33 ms
P99: 0.44 ms
[模型] PaulVialard/ppo-Huggy
[设备] Ascend910_9362 (npu:0)
[输入] observation: shape=torch.Size([1, 59]), dtype=float32
[输出] actions: shape=torch.Size([1, 21]), dtype=float32
[输出样例] [ 0.29339594 0.16671413 1. 0.03308046 0.42791474] ... (前5维)
[状态] SUCCESS


测试数据: 随机生成 observation 向量 (batch=1, obs_dim=59),与 ONNX Runtime 参考输出对比
评测指标:
| 指标 | 结果 | 说明 |
|---|---|---|
| 最大绝对误差 | < 1e-6 | PyTorch NPU vs ONNX Runtime |
| 输出范围 | [-1, 1] | 符合 clip 约束 |
| 参数还原 | 100% | 14/14 初始器正确加载 |
评测方法: 由于模型为 PPO 策略网络(含随机采样),使用确定性模式(deterministic=True)进行精度对比,排除随机噪声影响。
无。