Model: edbeeching/decision-transformer-gym-hopper-medium
Route: offline-rl
Backend: transformers DecisionTransformerModel
Hardware: Ascend 910B NPU (npu:0)
Revision: main
Decision Transformer 是离线强化学习策略模型,将 state / action / return-to-go / timestep 序列映射到下一连续动作。本仓库验证 Hopper Medium checkpoint 在单卡 Ascend NPU 上的 观测序列 → 动作预测 契约。
states (B,K,11), actions (B,K,3), rewards (B,K,1), returns_to_go (B,K,1), timesteps (B,K), attention_mask (B,K)。
复现时使用 context_len=20, state_dim=11, act_dim=3, max_ep_len=1000,所有浮点张量 float32 同步在 npu:0 上计算。action_preds (B,K,3),取最后位置 action_preds[0,-1,:] 作为 next_action,经 tanh 约束在 [-1,1] 内,对应 Hopper 3 自由度关节力矩。hidden_size=128, n_positions=1024, n_head=1, n_embd=768, 总参数 858K, 权重 6.6MB。一致性 (CPU vs NPU, 相同权重/输入/seed):
torch.npu.synchronize() 包围计时last_action: [-0.6166139841079712, 0.7437871694564819, -0.611660361289978]last_action: [-0.6166141629219055, 0.7437872290611267, -0.611659824848175]max_abs=1.14e-06, mae=2.02e-07, 阈值 atol=1e-4 rtol=1e-3 (tolerance~0.00105) -> PASSvalidate_policy_outputs.py --atol 1e-4 --rtol 1e-3 返回 passed:true, count:60, finite:true设备证据:
torch.npu.is_available()=True, device_count=2, device_name=Ascend910_9362, npu-smi 健康 OKnpu:0, 全部浮点输入 npu:0, 输出 npu:0,torch.npu.synchronize() 同步计时,无 .cpu() fallback。性能 (同步计时, warmup 3, 测量 10):
338.7 decisions/s, 1 action per decision (batch=1, horizon=20 序列一次性推理, decisions/s = actions/s for DT)sync latency_ms ~3.08 (单次推理示例),dtype float32, 单卡单流无编译缓存干扰首轮已预热。https://huggingface.co/edbeeching/decision-transformer-gym-hopper-medium 下载 (pytorch_model.bin 6.6MB + config.json)pip install -r requirements.txt
python inference.py默认从 /tmp/dt_hopper_medium 或 Hugging Face 加载权重,自动选择 npu:0,打印 route/backend/device/dtype、输入摘要、ActionPlan、同步耗时与 PASS/FAIL。


