HuggingFace 模型 sb3/dqn-LunarLander-v2 (Stable-Baselines3 DQN 强化学习策略,非 LLM)在华为昇腾 NPU(torch_npu)上的推理适配。
Box(-inf, inf, (8,), float32))Discrete(4),{0,1,2,3})dqn-LunarLander-v2.zip(numpy 2.x 序列化,内置 pickle 兼容补丁)ASCEND_RT_VISIBLE_DEVICES=0# 权重缓存:model_weights/sb3/dqn-LunarLander-v2/dqn-LunarLander-v2.zip(存在即跳过下载)
# CLI 推理(缺省为 8 维零向量,或传 8 维 obs JSON)
python inference.py
python inference.py --input "[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]"
python inference.py --img "[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]" # --img 为 --input 别名
# FastAPI 服务(端口 8022)
python inference.py --serve --port 8022
# GET / -> 观测 JSON 文本框页面
# POST /predict -> {"obs": [8 浮点]} 或空体(用缺省观察)-> JSONpolicy.to("npu:0").eval(),模型/输入 tensor 全部 npu:0;get_device() 带 try-exceptq_values = policy.q_net(obs_tensor) → action = q_values.argmax(dim=1)。
DQN 无 get_distribution(),且不使用 model.predict()(自带 device 管理)action_space 由 custom_objects 重建 Discrete(4)(zip 内 _np_random Generator
无法被 numpy 1.26 反序列化){model, device, obs_dim, action_dim, q_values, action, ...}numpy._core.* 子模块别名 + BitGenerator 反序列化python inference.py --input "[0.0,...8个浮点]" → exit 0,npu:0 输出合法 JSONPOST /predict → 合法 JSON(缺省/自定义 obs 均可用)