edbeeching/decision-transformer-gym-hopper-medium8224ec324200b150f10287b8c8c525224e62f319offline-rl (Decision Transformer, state/action/return-to-go sequence -> next action)DecisionTransformerModel (GPT-2 style, 3 layers, 1 head, n_embd 768, hidden_size 128)pytorch_model.bin 6.30 MB, 约 4.0M 参数, FP32transformers + torch_npu, dtype float32, 无 remote code{
"torch": "2.9.0+cpu",
"torch_npu": "2.9.0.post1+gitee7ba04",
"transformers": "4.57.6",
"cann": "8.5.1",
"npu": "Ascend910_9362 x2",
"python": "3.11.14"
}安装:pip install -r requirements.txt
模型权重通过 HuggingFace edbeeching/decision-transformer-gym-hopper-medium 获取,需配置 hf-mirror 或本地缓存 /data/adapt-npu-hf/hub/...。
归一化系数(来自模型卡):
输入观测需做 (state - mean)/std 归一化,return-to-go 为原始标量(约 1500 中位数),timesteps 为递增整数。
默认执行:python inference.py
可选:
python inference.py --mode validate # CPU-NPU 一致性
python inference.py --mode benchmark # 性能
python inference.py --device cpu # CPU 对比
python inference.py --batch 4 --seq-len 20设备判断:torch.npu.is_available() 且 --device npu:0 时使用 NPU,否则 CPU;打印 Model param device: npu:0。
{
"batch": 4,
"seq_len": 20,
"state_dim": 11,
"act_dim": 3,
"states": "normalized Hopper state, shape (4,20,11), dtype float32",
"actions": "shape (4,20,3), dtype float32",
"returns_to_go": "shape (4,20,1), sample ~1500, dtype float32",
"timesteps": "shape (4,20), dtype int64, range 0-19",
"attention_mask": "shape (4,20), ones"
}使用 python inference.py (batch=4, seq=20, seed=42, NPU npu:0):
Model: edbeeching/decision-transformer-gym-hopper-medium
Revision: 8224ec324200b150f10287b8c8c525224e62f319
Route: offline-rl
Model dir: /data/adapt-npu-hf/hub/models--edbeeching--decision-transformer-gym-hopper-medium/snapshots/8224ec324200b150f10287b8c8c525224e62f319
Config: state_dim=11 act_dim=3 max_ep_len=1000 n_layer=3 hidden_size=128 n_embd=768
Backend: transformers + torch_npu
Device: npu:0 (Ascend910_9362)
Model param device: npu:0
Input summary: batch=4 seq_len=20 state_dim=11 act_dim=3
Output: action_preds shape (4, 20, 3) device npu:0 dtype torch.float32
Action sample last step batch0: [0.8388814330101013, 0.8591884970664978, -0.506158709526062]
Action sample last step batch1: [0.34092772006988525, 0.34669429063796997, -0.22991016507148743]
Synchronized latency: 2.997 ms (batch=4 seq=20)
Finite check: True max=0.9831
PASSnpu:0,计时前后调用 torch.npu.synchronize()。python inference.py --mode validate 共用权重、观测、seed=42,比较完整动作序列:
CPU-NPU consistency: max_abs=9.182841e-07 mae=1.300049e-07 tolerance atol=1e-4 rtol=1e-3
Consistency: PASS
{"count": 240, "finite": true, "max_abs": 9.18e-07, "passed": true, "tolerance": 0.00108}阈值 FP32 atol=1e-4 rtol=1e-3,实际 max_abs 9.18e-07 << tolerance,验证通过 via validate_policy_outputs.py。
python inference.py --mode benchmark (batch=4, seq=20=20 decisions, npu:0):
Benchmark: samples=20 avg=2.88ms min=2.85 max=2.92 p50=2.87 p90=2.91 p95=2.92 decisions/s=1387.7
First compile latency: 237.8 ms
Synchronized latency: 3.011 ms (batch=4)torch.npu.synchronize()。decisions/s = batch*1000/avg_ms。


三张图片均由 xterm.js 根据本次真实日志生成,包含 SHA-256 与 exit code。
#NPU #Ascend #Ascend910