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

Decision Transformer Gym Hopper Medium - Ascend NPU

Model Description

This is edbeeching/decision-transformer-gym-hopper-medium (revision 8224ec324200b150f10287b8c8c525224e62f319) adapted for Huawei Ascend NPU (910B, npu:0). The model is a Decision Transformer (GPT-2 backbone with 3 layers, hidden_size 128, n_head 1, state_dim 11, act_dim 3, max_ep_len 1000) trained on medium trajectories from Gym Hopper-v3 for offline reinforcement learning.

Offline-RL Contract

Route: offline-rl (state/action/history/return-to-go sequence → next action)

Observation / Input Schema:

  • states: (batch, seq_len, state_dim=11) float32 — Hopper proprioception (normalized with mean [1.311279, -0.08469521, ...] / std [0.17790751, ...])
  • actions: (batch, seq_len, act_dim=3) float32
  • rewards: (batch, seq_len, 1) float32
  • returns_to_go: (batch, seq_len, 1) float32 — target return (e.g. 3600 scaled), not language prompt
  • timesteps: (batch, seq_len) long — episode step index in [0, max_ep_len)
  • attention_mask: (batch, seq_len) long — 1 if attended

Output Schema:

  • action_preds: (batch, seq_len, act_dim=3) float32 on npu:0 — tanh-squashed joint torques in [-1,1]; last position is next action to execute
  • state_preds, return_preds preserved as raw_output; validation uses last-step action prediction

Sampling: Deterministic forward; seed 42 fixed for CPU/NPU comparison; no diffusion sampler.

NPU Evidence

Validated on Ascend910_9362 with torch_npu and torch.npu.synchronize() timing.

  • npu-smi info shows 2 devices, device 0 Ascend910 healthy (3110 MiB / 65536 MiB).
  • torch.npu.is_available()==True, device_count==2, device_name==Ascend910_9362.
  • Param device npu:0, all floating inputs (states, actions, returns_to_go, timesteps) and output action_preds on npu:0 (no CPU_FALLBACK).

Agent Workflow NPU Device Call Model Result

CPU-NPU Consistency

Same weights (/tmp/dt_hopper → HF pytorch_model.bin 6.3 MiB), same synthetic batch (seed 42, batch=1, seq_len=20, state_dim=11, act_dim=3), same dtype float32.

  • Comparison of full action_preds (60 values) via validate_policy_outputs.py: max_abs = 6.19e-07, tolerance atol=1e-4, rtol=1e-3 → passed.
  • Last-action diff: CPU [0.45879656, -0.35335338, -0.91613626] vs NPU [0.45879683, -0.35335347, -0.91613626] → max 2.68e-07.
  • Checks: finite true, shape (1,20,3) correct, horizon 20, action_dim 3, bounds [-0.93, 0.93] within tanh, no NaN/Inf.

Performance

Synchronized timing with torch.npu.synchronize() around forward:

  • Warmup 3 iters + 10 measured iters, batch=1, seq_len=20, dtype float32, actions per call = 20
  • First compile ≈ 243 ms, steady-state avg 3.05 ms min 3.01 ms max 3.10 ms p50 3.03 ms p90 3.09 ms
  • decisions/s ≈ 6563 (one forward = one decision), actions/s ≈ 6563 * 1 with horizon 20 → throughput depends on caller; reported avg decisions/s uses 1000/avg_ms.

Usage

pip install -r requirements.txt
python inference.py

inference.py loads from /tmp/dt_hopper if present else from Hugging Face hub, runs on npu:0 if available else cpu, prints device proof, ActionPlan summary, synchronized latency and PASS/FAIL.

Limitations

  • Synthetic states used for hardware proof (deterministic randn seed 42); Gym env not required.
  • Gym rollout reward not validated here; model card target return 3600 is example.
  • Requires transformers>=4.18, torch>=2.0, torch_npu built for CANN 8.5.1 and single Ascend910 with ≥ 8 GiB.