2
gcw_BOxvkDDf/ppo-huggy
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

ppo-Huggy · Ascend NPU 适配

Unity ML-Agents 训练的小狗追球 PPO 策略(PaulVialard/ppo-Huggy),适配华为昇腾 NPU(torch_npu)运行。

模型说明

  • 输入:obs_0 float32 [batch, 59](59 维观测向量)
  • 输出:deterministic_continuous_actions [batch, 21](21 维 mean action)
  • 原始 ONNX 图含随机采样分支(RandomNormalLike),onnx2torch 无法转换,故在加载时图剪枝,仅保留确定性输出(mean action)子图,再经 onnx2torch 转换为 torch 模型并迁移至 npu:0。

环境

  • Python 3.11 + torch 2.9.0 + torch_npu
  • CANN:source /usr/local/Ascend/ascend-toolkit/set_env.sh
  • 依赖:onnx、onnx2torch、fastapi、uvicorn

权重缓存

mkdir -p model_weights/PaulVialard/ppo-Huggy
HF_ENDPOINT=https://hf-mirror.com python3 -c "
from huggingface_hub import hf_hub_download
hf_hub_download('PaulVialard/ppo-Huggy', 'Huggy.onnx', local_dir='./model_weights/PaulVialard/ppo-Huggy')"

加载时优先命中本地缓存 ./model_weights/PaulVialard/ppo-Huggy/。

使用

CLI 推理

export ASCEND_RT_VISIBLE_DEVICES=0
python inference.py --input "[0.0, 0.1, 0.2, ... 共 59 个浮点数]"

FastAPI 服务

export ASCEND_RT_VISIBLE_DEVICES=0
python inference.py --serve --port 8011
  • GET / — HTML 推理页面(观测向量 JSON 文本框)
  • POST /predict — 请求 JSON {"obs": [59 个浮点数]},返回:
{"model": "PaulVialard/ppo-Huggy", "device": "npu:0", "obs_dim": 59, "action_dim": 21, "action": [...]}

说明

  • 模型与输入 Tensor 全部位于 npu:0;若 NPU 不可用自动回退 CPU。
  • 代码不含任何 GPU 设备调用,设备选择仅限昇腾 NPU 或 CPU。