原模型 graceesthi/ug-cppo-finai-2025 是 stable-baselines3 的 PPO / CVaR-PPO (CPPO) 强化学习交易策略
(Uncertainty-Gated CVaR-PPO,金融多股交易,观测状态向量 → 动作向量)。
本仓库将其适配到 昇腾 Ascend910 (torch-npu),提供可复现的 NPU 推理入口与完整验证证据。
PPO(Actor-Critic MLP 策略)cppo_seed42.zip(CVaR-PPO,seed 42,250k 训练步)Box(-inf, inf, (81,), float32)(81 维市场状态特征)Box(-1.0, 1.0, (10,), float32)(10 支股票的权重调整,确定性推理)npu:N,入口用 try-except 捕获 NPU 初始化失败并拒绝 CPU/CUDA 回退。numpy._core 命名空间且 __bit_generator_ctor 只认字符串,
故注入 numpy._core 别名并 patch __bit_generator_ctor(见 inference.py 顶部)。np_random 状态无法在 numpy 1.26 反序列化,
使用 PPO.load(..., custom_objects=...) 提供等效 observation_space / action_space
(维度经 pickle 字节与 policy.pth 双重确认:obs 81 / action 10 / Box[-1,1])。pip install -r requirements.txt
# CLI: 观测状态向量 (81 维 JSON 数组)
python inference.py --state "[0.1, 0.2, ..., 0.81]" --device npu:1
# CLI 兼容模板: --img 指向 .json/.txt 状态向量文件
python inference.py --img state.json --device npu:1
# FastAPI: 启动服务
python inference.py --serve --port 8000 --device npu:1
# 请求推理
curl -X POST http://127.0.0.1:8000/predict \
-H "Content-Type: application/json" \
-d '{"state": [0.1, 0.2, ...]}'
# 或 multipart 文件上传
curl -X POST http://127.0.0.1:8000/predict -F "file=@state.json"{
"model": "graceesthi/ug-cppo-finai-2025",
"requested_device": "npu:1",
"actual_device": "npu:1",
"npu_name": "Ascend910_9362",
"exit_status": 0,
"inference_ms": 1.15,
"obs_dim": 81,
"action_dim": 10,
"action": [0.72, -0.37, 0.79, ...],
"deterministic": true
}assets/agent_workflow.png — NPU 依赖安装与环境日志assets/npu_device_call.png — CLI 命令行 NPU 推理成功输出assets/model_result.png — FastAPI /predict 返回推理结果权重自动从 GitCode HuggingFace 镜像 https://ai.gitcode.com/hf_mirrors/graceesthi/ug-cppo-finai-2025
下载并缓存到 ./model_weights/graceesthi/ug-cppo-finai-2025/(仅下载最小运行文件集,
已缓存则打印 [cache-hit],429 自动退避重试)。