jsjs1258/decision-transformer-gym-hopper-medium-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

Decision Transformer Gym Hopper Medium - Ascend NPU

模型信息

  • 原始模型: edbeeching/decision-transformer-gym-hopper-medium
  • Revision: 8224ec324200b150f10287b8c8c525224e62f319
  • 类型: Offline RL - Decision Transformer (Gym Hopper)
  • 路由: offline-rl
  • 架构: DecisionTransformerModel (hidden 128, n_layer 3, n_embd 768, state_dim 11, act_dim 3)
  • 权重大小: 6.3 MB (858,767 params)
  • 许可证: MIT

任务契约

  • 输入: 固定长度的 state、action、return-to-go 和 timestep 序列
    • states: [batch, context_length, 11] float32
    • actions: [batch, context_length, 3] float32
    • returns_to_go: [batch, context_length, 1] float32
    • timesteps: [batch, context_length] long (0..max_ep_len 1000)
    • attention_mask: [batch, context_length] long (1)
    • 默认测试 batch=1, context=20, RTG 随机, timestep 随机采样
    • 数据集归一化: 使用官方 Hopper medium 统计 (RTG 非语言 prompt)
  • 输出: 下一连续动作
    • action_preds: [batch, context, 3] float32, action_tanh=True 限制在 [-1,1]
    • 验收对象: 最后位置的 action prediction (horizon=1, action_dim=3)

NPU 适配

环境

  • 设备: Ascend910_9362 (2x, 使用 npu:0)
  • torch: 2.9.0+cpu, torch_npu 2.9.0.post1, transformers 4.57.4
  • CANN 8.5.1

设备证明

  • 模型首参数 device: npu:0
  • 浮点输入 Tensor device: npu:0 (states, actions, returns_to_go 均为 npu:0)
  • 输出 Tensor device: npu:0 (action_preds npu:0)
  • 计时: torch.npu.synchronize() 包围每次推理

一致性验证

  • CPU 与 NPU 共享权重、观测、预处理、seed=42、eval 模式、float32、相同采样
  • 固定输入 batch=1 context=20, seed 42 下:
    • cpu_last_action: [0.4532738, -0.41783097, -0.90261614]
    • npu_last_action: [0.45327407, -0.41783115, -0.90261632]
    • max_abs: 6.71e-07, tolerance 0.001087 (atol 1e-4 rtol 1e-3) -> PASS
    • 额外全序列验证: validate_policy_outputs.py 对 60*3=180 值比较 max_abs 0.00031 < tol 0.00109 PASS, finite True
    • shape: [1,20,3] 一致, 无 NaN/Inf, 动作在 [-1,1] 边界内

性能

  • 预热 3 次, 正式 10 次同步计时:
    • avg 3.28 ms, min 3.22 ms, max 3.32 ms, p50 3.27 ms, p90 3.31 ms, p95 3.32 ms
    • decisions/s ≈ 304 (actions/s 等同)
    • 首轮 (含编译) 3.30 ms, 无明显编译开销 (小模型)
    • batch 1, horizon 1, dtype float32, 包含模型 forward 不含预处理
    • benchmark_policy.py --unit decisions 结果一致

使用方法

pip install -r requirements.txt
python inference.py

默认从本地缓存 /tmp/dt_hopper 或 hub cache 加载 (HF_ENDPOINT 已配置镜像), 无需下载权重到仓库。

证据图

  • 侦察/验证/性能完整日志: agent workflow
  • NPU 设备与张量 device 证明: npu device call
  • 模型推理结果与耗时: model result

限制

  • 单卡 npu:0 推理, 显存需求 < 1GB, 无需多卡
  • 仅验证单步 action prediction, 闭环 Gym rollout 为额外评估未作替代验证
  • 权重未提交, 需自行从 https://huggingface.co/edbeeching/decision-transformer-gym-hopper-medium 拉取 (revision 固定)