# Research note: DATA, CONFIGS, TRAINING, EVALUATION for decision models

Tags: [paper] [code] [docs] [inferred] [local] (= measured by me on 2026-11-20).

Sources and pinned versions:
- DT repo `kzl/decision-transformer`, master SHA `e2d82e68f330c00f763507b3b01d774740bee53f` (2022-02-07). Paths below are relative to `gym/` or `atari/`.
- DT paper: arXiv 2106.01345, via the ar5iv HTML. Tables are numbered as in the paper.
- [D4RL release source](https://github.com/Farama-Foundation/D4RL/blob/89141a689b0353b0dac3da5cba60da4b1b16254d/README.md#licenses): code Apache-2.0; datasets CC BY 4.0 unless otherwise noted. These terms do not establish reuse rights for paper figures.
- D4RL paper: arXiv 2004.07219.
- IQL paper: arXiv 2110.06169.
- `huggingface/transformers` main, SHA `439bba079891ecd766900e8ce80ee961b94ef132`.
- HF docs: `huggingface.co/docs/transformers/model_doc/decision_transformer`, which points at v5.23.0.

## 1. D4RL data

**Datasets**
- Gym-MuJoCo: {halfcheetah, hopper, walker2d} × {random, medium, medium-replay, medium-expert, expert}, plus ant and `full-replay`.
- Registered in `d4rl/gym_mujoco/__init__.py:5-20` with `max_episode_steps=1000`.
- v0/v1/v2 URLs are in `d4rl/infos.py:287-302`:
  - v2 URL template: `http://rail.eecs.berkeley.edu/datasets/offline_rl/gym_mujoco_v2/{env}_{dset}-v2.hdf5`.
  - Medium-replay in v0 was `*_mixed.hdf5` (`infos.py:39,44`).
- Other domains in `infos.py`:
  - Maze2D: `maze2d-{open,umaze,medium,large}`, sparse and dense (lines 8-21).
  - AntMaze: `antmaze-{umaze,umaze-diverse,medium-play,medium-diverse,large-play,large-diverse}`, v0 and v2 (lines 57-68).
  - Adroit: `{pen,hammer,relocate,door}-{human,cloned,expert}` v0/v1 (lines 24-35, 304-309).
  - FrankaKitchen: `kitchen-{complete,partial,mixed}-v0` (lines 73-75).

**Data format**
- `get_dataset()` asserts keys `observations, actions, rewards, terminals` (`d4rl/offline_env.py:94-113`).
- `timeouts` is optional. `qlearning_dataset` and `sequence_dataset` use it if present, otherwise assume `episode_step == env._max_episode_steps - 1` (`d4rl/__init__.py:103-119, 167-178`).
- [local] A v2 locomotion file contains these datasets: `actions, infos/action_log_probs, infos/qpos, infos/qvel, next_observations, observations, rewards, terminals, timeouts`.
- Dtypes are float32. Dimensions: halfcheetah obs 17 / act 6, hopper 11 / 3, walker2d 17 / 6.

**Normalized score**
- [paper] `100 × (score − random) / (expert − random)`. Random is the mean over 100 episodes of a uniform-random policy. Expert is domain-specific, e.g. SAC for Gym (D4RL paper, text after Table 1).
- [code] `OfflineEnv.get_normalized_score` returns a fraction (`offline_env.py:71-74`); callers multiply by 100.
- Reference scores (`infos.py` `REF_MIN_SCORE` / `REF_MAX_SCORE`; the Gym v0/v1/v2 values are copied from `*-random-v0`):

| Domain | ref_min | ref_max | Source lines |
|---|---|---|---|
| halfcheetah | -280.178953 | 12135.0 | 129-133, 220-223 |
| hopper | -20.272305 | 3234.3 | 139-143, 229-233 |
| walker2d | 1.629008 | 4592.3 | 134-138, 224-228 |
| antmaze | 0.0 | 1.0 | 150-160, 240-250 |
| kitchen | 0.0 | 4.0 | 161-163, 251-253 |
| pen | 96.262799 | 3076.8331 | 117-119, 207-209 |
| hammer | -274.856578 | 12794.1348 | 120-122, 210-212 |
| door | -56.512833 | 2880.5693 | 126-128, 216 |
| relocate | -6.425911 | 4233.8778 | 123-125, 213-215 |
| maze2d-umaze-v1 | 23.85 | 161.86 | 108, 198 |
| maze2d-medium-v1 | 13.13 | 277.39 | 109, 199 |
| maze2d-large-v1 | 6.7 | 273.99 | 110, 200 |

- Ant gym ref_min is -325.6 (`infos.py:144`).
- The values in the table were read directly from the file. Some max rows (e.g. pen, door, relocate expert) were taken from the same lines, but I did not view every adjacent row.

**Dataset sizes**
- D4RL paper Table 1 (appendix, "# Samples"), which describes v0 datasets:
  - Maze2D: umaze 1e6, medium 2e6, large 4e6.
  - AntMaze: 1e6 each.
  - Gym:
    - random, medium: 1e6.
    - medium-expert: 2e6.
    - medium-replay: hopper 200,920; halfcheetah 101,000; walker2d 100,930.
  - Adroit: pen-human 5000, hammer-human 11,310, door-human 6,729, relocate-human 9,942; pen-cloned/expert 5e5; other cloned/expert 1e6.
  - Kitchen: complete 3,680; partial 136,950; mixed 136,950.
- Dataset construction [paper]:
  - "medium" = SAC early-stopped, 1M samples.
  - "random" = randomly initialised policy.
  - "medium-replay" = replay buffer until the policy reaches medium.
  - "medium-expert" = equal mix of expert and medium.
- All 15 locomotion v2 numbers measured by me are in the section 9 table.

**Minari (D4RL successor)**
- Minari is hosted on HF under `farama-minari` ([docs] `minari.farama.org/content/dataset_standards/`).
- Episode format: `EpisodeData{id, observations (includes the initial obs, so T+1), actions, rewards, terminations, truncations, infos}`. This is a different format from D4RL's flat `terminals`/`timeouts`.
- Minari states that the D4RL group (kitchen, antmaze, pen, door, hammer, relocate, pointmaze, minigrid) is "a reproduction… not all datasets are the same as in D4RL" (`minari.farama.org/datasets/D4RL/`).
- MuJoCo locomotion lives in a separate namespace, regenerated with SB3, and is not a byte-copy of D4RL:
  - `mujoco/hopper/medium-v0`: SB3 SAC for 4e6 steps, Hopper-v5, 999,404 steps, 1,327 episodes.
  - D4RL `hopper-medium-v2` [local]: 1,000,000 steps, 2,186 DT-style trajectories.
  - `mujoco/halfcheetah/medium-v0`: 1,000,000 steps, 1,000 episodes (TQC).
  - `mujoco/walker2d/medium-v0`: 999,613 steps, 1,044 episodes (SAC).
- Minari `D4RL/kitchen/complete-v2` has 4,209 steps (D4RL paper: 3,680). `D4RL/pen/human-v2` has 5,000 steps and 25 episodes (matches D4RL).

**Atari (DQN Replay, official)**
- [docs] `google-research/batch_rl` README:
  - DQN trained on all 60 games, sticky actions, 200M frames.
  - About 50M tuples logged per game.
  - Stored at `gs://atari-replay-datasets/dqn`.
  - Legacy ROMs required: `atari-py<=0.2.5`, `gym<=0.19.0`.
- [paper] REM (arXiv 1907.04543): 5 independent runs per game; 25% sticky-action probability.
- DT uses 1% of the data: 500k of 50M transitions, 3 seeds [paper §4.1].
- [code] `create_dataset.py` (this is the "official" part DT adds):
  - Loads replay checkpoint buffers `0..49` from `<prefix>/<game>/1/replay_logs` (run "1" only).
  - Loop (`create_dataset.py:32-74`): `while len(obss) < num_steps` it randomly picks a buffer index in `[50-num_buffers, 49]`, reads transitions sequentially starting at the saved offset, stops after `trajectories_per_buffer` (10) terminals, and truncates the buffer at 100,000 transitions.
  - Per-step "returns" are the 1-step rewards (`update_horizon=1`). RTG is computed per trajectory as a plain sum from step j to end (`:81-91`).
  - Timesteps restart at 0 for each trajectory (`:93-100`).
- Observation is a 4×84×84 uint8 stack, divided by 255 (`run_dt_atari.py:60-61`).

**RoboMimic / RT (brief)**
- RoboMimic [docs]:
  - Multi-Human (MH) = 6 operators × 50 = 300 successful demos.
  - A diagnostic Can "paired" set has 200 demos.
  - Datasets come as low-dim and image hdf5.
- RT-1 [paper] arXiv 2212.06817:
  - About 130k episodes, 700+ tasks (744 in one caption), 13 robots, 17 months.
- I did not verify the RoboMimic PH counts (lift/can/square 200, etc.); not fetched.

## 2. How DT builds trajectories and batches (official gym code)

**Trajectory building**
- `download_d4rl_datasets.py:12-43`:
  - Only `medium`, `medium-replay`, `expert` × 3 envs, v2. No `random`, no `medium-expert`.
  - Walks the flat arrays and ends a path at `terminals[i]` or (`timeouts[i]` if present, else step 999).
  - Stores `observations, next_observations, actions, rewards, terminals` per path.
  - A trailing partial segment with no end flag is dropped. [local]: 506 steps dropped for hopper-expert, 786 for walker2d-expert, 94 for hopper-medium.
  - The "timeout" distinction is lost: the pickle keeps only `terminals`.
- The HF mirror `edbeeching/decision_transformer_gym_replay` has the same 9 pickles with key `dones` instead of `terminals`. `experiment.py:135-138` accepts either.

**State normalisation**
- `experiment.py:86-87`: `state_mean, state_std = mean/std over ALL timesteps`, with `std + 1e-6`. Computed on the full dataset, not on the `pct_traj` subset.
- Statistics are applied to states only (`:148`). Actions are not normalised.

**Return-to-go**
- `discount_cumsum(x, gamma)` (`:18-23`) with `gamma=1.`.
- RTG for the sampled window is `discount_cumsum(traj['rewards'][si:])[:window_len + 1]` (`:141`). It uses the full remaining trajectory, not just the window.
- One extra RTG entry is appended if short (`:142-143`). The model uses `rtg[:, :-1]` (`seq_trainer.py:14`).
- RTG is divided by `scale` (`:152`).

**Scale constants** (`experiment.py:38-58`)

| env | max_ep_len | eval targets | scale |
|---|---|---|---|
| hopper | 1000 | [3600, 1800] | 1000. |
| halfcheetah | 1000 | [12000, 6000] | 1000. |
| walker2d | 1000 | [5000, 2500] | 1000. |
| reacher2d | 100 | [76, 40] | 10. |

**Context length K**
- Default 20 (`:288`). The paper uses 5 for Reacher (Table 9).
- Atari: K = 30, except K = 50 for Pong (`run.sh`, Table 8).
- The Atari model's `block_size` is `3 × context_length` (`run_dt_atari.py:77`).

**Timestep embedding**
- Gym [code] `decision_transformer.py:40,66-71`: `nn.Embedding(max_ep_len, hidden)`; the same time embedding is added to R, s and a. The paper text says "per timestep, not per token".
- Timesteps ≥ `max_ep_len` are clamped to `max_ep_len - 1` (`experiment.py:140`).
- Atari [code] `model_atari.py:130-133, 256-258`: a learned per-token `pos_emb` plus a `global_pos_emb[timestep of window start]`. `max_timestep = max(timesteps)` of the data.

**Padding and masking** (`experiment.py:145-154`)
- Left-pad to K. Padding values:

| tensor | pad value |
|---|---|
| states | 0 (then normalised, so not 0 afterwards) |
| actions | -10 |
| rewards | 0 |
| dones | 2 |
| rtg | 0 |
| timesteps | 0 |
| mask | 0 (1 for real tokens) |

- The loss is computed only where `attention_mask > 0` (`seq_trainer.py:18-19`).
- At inference, `get_action` (`decision_transformer.py:118-133`) takes the last K steps, left-pads with zeros, and builds the mask.

**Batch sampling scheme**
- `experiment.py:103-116, 118-129`:
  - Sort trajectories by return and keep the top ones until `pct_traj × num_timesteps` is reached (`pct_traj=1.0` keeps all).
  - `p_sample = traj_len / sum(traj_len)` over the kept ones.
  - Per sample: pick a trajectory by `p_sample` with replacement, then `si = random.randint(0, T-1)` and take `[si, si+K)`.
  - So the sampling is weighted by length ("according to timesteps"), not by return.
- [local] For hopper-medium-replay, about 9.3% of windows with K=20 are shorter than K, because windows run forward from a uniform start.

**Sequence layout and heads**
- The token sequence is (R, s, a)×K → 3K tokens, followed by `embed_ln` (`decision_transformer.py:73-78`).
- Action head: Linear + Tanh, read from the state token (`:49-51, 99`).
- State and return heads exist but are unused in training (comment `:47`).
- The GPT2 used has positional embeddings removed (`:36-38`).

**Loss**
- MSE on actions only: `torch.mean((a_hat - a)**2)` (`experiment.py:254`), masked, with grad-norm clip 0.25 (`seq_trainer.py:28`).

## 3. Optimiser, schedule and config per benchmark

**Gym DT**

| item | code default | paper | source |
|---|---|---|---|
| embed_dim | 128 | 128 | `experiment.py:292`; Table 9 |
| n_layer | 3 | 3 | `:293`; Table 9 |
| n_head | 1 | 1 | `:294`; Table 9 |
| n_inner | 4×embed | – | `:217` |
| activation | relu | ReLU | `:295` |
| dropout | 0.1 (resid + attn) | 0.1 | `:296`; Table 9 |
| lr | 1e-4 | 1e-4 | `:297` |
| weight_decay | 1e-4 | 1e-4 | `:298` |
| optimiser | AdamW, torch defaults | AdamW | `:237-241` |
| warmup | 10000 | "first 10^5 steps" | `:299`, lambda `min((steps+1)/warmup, 1)` `:242-245` |
| batch size | 64 | 64 | `:290` |
| K | 20 | 20 (Reacher 5) | `:288` |
| grad clip | 0.25 | 0.25 | `seq_trainer.py:28` |
| steps | max_iters 10 × 10000 = 1e5 | 1e5 | `:301-302` |
| eval episodes | 100 per target | not stated | `:300` |
| n_positions | 1024 | – | `:219` |

- The LR schedule is linear warmup then constant. There is no decay.
- Run command: `python experiment.py --env hopper --dataset medium --model_type dt` (`readme-gym.md`).
- Environment pins (`gym/conda_env.yml`): `gym==0.18.3`, `mujoco-py==2.0.2.13`, `torch==1.8.1`, `transformers==4.5.1`, `wandb==0.9.1`. It uses `Hopper-v3`/`HalfCheetah-v3`/`Walker2d-v3` (`experiment.py:39,44,49`).

**Gym BC**
- `MLPBCModel(state_dim, act_dim, hidden_size, n_layer, dropout=0.1, max_length)`.
- It is an MLP over K concatenated states, ReLU + dropout, final Tanh (`mlp_bc.py:14-34`).
- `ActTrainer` has no grad clipping (`act_trainer.py:25-27`). It targets only the last action (`:19`).
- For BC, only the first eval target is used (`experiment.py:62-63`).
- [paper] Table 10 / A.2.2: 3 layers, 256 embedding, batch 64, dropout 0.1, lr 1e-4, wd 1e-4, 2.5×10^4 steps. [code] defaults are 128 / 1e5 steps unless flags are changed.

**Atari DT**

| item | value | source |
|---|---|---|
| layers / heads / embed | 6 / 8 / 128 | `run_dt_atari.py:79-80`; Table 8 |
| context | 30 (Pong 50) | `run.sh`; Table 8 |
| batch | 128 (Pong 512) | `run.sh`; Table 8 |
| epochs | 5 | `:25`; Table 8 |
| lr | 6e-4 | `:85` |
| AdamW betas | (0.9, 0.95) | `trainer_atari.py:42` |
| grad clip | 1.0 | `:43` |
| weight decay | 0.1 on matmul weights only | `:44`; `model_atari.py:213-216` |
| warmup tokens | 512×20 | `run_dt_atari.py:86` |
| final tokens | 2×len(dataset)×context×3 | `:86` |
| decay | linear warmup then cosine to 10% floor | `trainer_atari.py:116-127` |
| encoder | 3 conv (32,64,64; 8/4/3; stride 4/2/1) + Linear(3136, 128) + Tanh | `model_atari.py:149-152` |
| actions | `Embedding(vocab, 128)` + Tanh | `:156` |
| RTG | `Linear(1, 128)` + Tanh | `:154` |
| seeds | 123, 231, 312 | `run.sh` |

- The paper's "Tanh instead of LayerNorm" matches this code (Appendix A.1).
- Atari BC is the same architecture with `--model_type naive` and no RTG.

## 4. Evaluation protocol

**Gym DT**
- Roll out `num_eval_episodes` episodes per target (default 100) with `evaluate_episode_rtg` (`evaluate_episodes.py:65-140`).
- At t = 0 the target return is `target/scale`.
- After each step the RTG is decremented: `R_{t+1} = R_t − r_t/scale` (`:125`). In `delayed` mode there is no decrement (`:126-127`).
- Timesteps are 0..t; the state is normalised with the same mean/std.
- The environment's own raw reward sum is the score (`:134`). The code logs the mean and std of raw return and length per target (`experiment.py:200-205`). The code does not compute D4RL normalized score; the caller does.
- `evaluate_episode_rtg` runs with `max_ep_len=1000`. The env is not seeded.
- [paper] Target choice: expert-level return per env, except HalfCheetah where 50% was found better (A.2.1). Table 9: HalfCheetah 6000, Hopper 3600, Walker 5000, Reacher 50.
- [local] Normalised-score equivalents of the code's targets:

| env | targets | D4RL normalised | RTG/1000 |
|---|---|---|---|
| hopper | 3600 / 1800 | 111.2 / 55.9 | 3.6 / 1.8 |
| halfcheetah | 12000 / 6000 | 98.9 / 50.6 | 12.0 / 6.0 |
| walker2d | 5000 / 2500 | 108.9 / 54.4 | 5.0 / 2.5 |

**Atari DT**
- `get_returns` (`trainer_atari.py:174-222`):
  - 10 episodes.
  - Actions are sampled from the softmax with temperature 1.0 (`sample=True`, `:187, 214`).
  - RTG is decremented by the reward each step (`:211`).
  - The first RTG is the target. The Atari code's RTG is cast to `long` (`:188, 216`), so the target is in raw-score units, not scaled.
- Env (`:225-319`):
  - Frame skip 4 with max-pool of the last 2 frames, up to 30 no-op starts, 84×84 grayscale, history 4.
  - Max episode 108e3 frames.
  - `repeat_action_probability = 0` (`:231`), i.e. no sticky actions at eval, while the data was collected with sticky actions (REM paper). [inferred] a train/eval mismatch.
- Targets in code (`:158-170`): Breakout 90, Seaquest 1150, Qbert 14000, Pong 20 (`naive` BC uses 0).
- Eval happens at the end of every epoch (5 total).
- The paper reports Atari scores as gamer-normalised: `100 × (score − random)/(gamer − random)`, with Random/Gamer values from Table 11:

| Game | Random | Gamer |
|---|---|---|
| Breakout | 2 | 30 |
| Qbert | 164 | 13455 |
| Pong | -21 | 15 |
| Seaquest | 68 | 42055 |

- Cross-check [local arithmetic]: Breakout 76.9 raw → (76.9−2)/28 = 267.5, matching Table 1.
- Atari paper numbers are mean ± std over 3 seeds.

**Paper statements**
- D4RL scores are "mean and variance across three seeds" (Table 2 caption). CQL numbers are taken from the CQL paper, BC numbers were run by the DT authors, and BEAR/BRAC/AWR numbers come from the D4RL paper (§4.2).
- The paper does not state the number of eval episodes or which training iteration is reported.

**Other papers' protocols**
- IQL [paper] Appendix: MuJoCo locomotion = mean over 10 evaluation trajectories and 10 seeds; AntMaze = 100 evaluation trajectories (arXiv 2110.06169, Appendix B/C).
- D4RL paper Table 2: averages over 3 seeds.

## 5. HF `transformers` DecisionTransformer

**Classes**
- `DecisionTransformerConfig(PreTrainedConfig)` at `configuration_decision_transformer.py:24`; fields at `:64-86`.
- `DecisionTransformerModel` at `modeling_decision_transformer.py:508`; output class `DecisionTransformerOutput(state_preds, action_preds, return_preds)` at `:471-483`.
- Supporting classes: `DecisionTransformerGPT2Model` (`:348`), `DecisionTransformerGPT2Block`, `DecisionTransformerGPT2Attention`.

**Config fields and defaults**

| field | default |
|---|---|
| state_dim | 17 |
| act_dim | 4 |
| hidden_size | 128 |
| max_ep_len | 4096 |
| action_tanh | True |
| vocab_size | 1 |
| n_positions | 1024 |
| n_layer | 3 |
| n_head | 1 |
| n_inner | None (→ 4 × hidden) |
| activation_function | "relu" |
| resid_pdrop / embd_pdrop / attn_pdrop | 0.1 each |
| layer_norm_epsilon | 1e-5 |
| initializer_range | 0.02 |
| scale_attn_weights | True |
| use_cache | True |
| bos / eos token id | 50256 |
| scale_attn_by_inverse_layer_idx / reorder_and_upcast_attn / add_cross_attention | False |

- `attribute_map` aliases `max_position_embeddings`→`n_positions`, `num_attention_heads`→`n_head`, `num_hidden_layers`→`n_layer` (`:58-62`).
- Defaults agree with paper Table 9 for layers, heads, embedding, activation and dropout. `state_dim=17`/`act_dim=4` are not the Hopper values (11/3).

**Forward**
- Signature: `forward(states, actions, rewards, returns_to_go, timesteps, attention_mask, ..., return_dict)` (`:542-554`).
- Layers: `embed_timestep = Embedding(max_ep_len, hidden)`, `embed_return/state/action = Linear`, `embed_ln = LayerNorm`, predict heads (`:524-536`).
- It interleaves (R, s, a), applies `embed_ln`, and feeds the transformer with `position_ids = zeros` (`:645-647`). **Correction (critic-1 B2, code-verified in 04 §2.1):** this does NOT neutralise `wpe`. `position_ids = zeros` adds the single vector `wpe[0]` to every token (a learned constant bias), whereas the official repo adds no positional vector at all. HF Hopper has 858,767 parameters vs official 727,695; the 131,072 difference is HF's `wpe` (1024×128), and outputs match only after `wpe` is zeroed (max|diff| = 0.0). Do not call HF and official DT architecturally identical.
- Heads: action preds from the state token, state and return preds from the action token (`:659-661`).
- Docs example (`:570-602`) loads `edbeeching/decision-transformer-gym-hopper-medium` and uses `Hopper-v3`.

**HF checkpoint config** (`edbeeching/decision-transformer-gym-hopper-medium/config.json`)
- Real file: `act_dim 3`, `state_dim 11`, `hidden_size 128`, `max_ep_len 1000`, `n_layer 3`, `n_head 1`, `n_positions 1024`, `action_tanh true`, `activation_function relu`, `*_pdrop 0.1`, `transformers_version 4.18.0.dev0`.
- Quirk: it also contains `"n_embd": 768` alongside `hidden_size: 128`. [inferred] a vestigial field.

**HF training recipe** (blog `huggingface/blog/train-decision-transformers.md`)
- Data collator `DecisionTransformerGymDataCollator`: `max_len=20`, `max_ep_len=1000`, `scale=1000.0` (lines 105-114).
- `p_sample = traj_lens / sum(traj_lens)` (line 132); the code mirrors DT's padding rules.
- `TrainingArguments(num_train_epochs=120, per_device_train_batch_size=64, learning_rate=1e-4, weight_decay=1e-4, warmup_ratio=0.1, optim="adamw_torch", max_grad_norm=0.25)` (lines 239-249). The blog says it trains for fewer iterations than the authors; the 120-epoch, 0.1-warmup-ratio schedule is the HF version, not the DT repo's schedule.
- HF dataset `edbeeching/decision_transformer_gym_replay` (SHA 4441c977): 9 configs `{halfcheetah,hopper,walker2d}-{expert,medium,medium-replay}-v2`, one row per trajectory, fields `observations, actions, rewards, dones`.

## 6. Paper vs code disagreements

| # | Item | Paper | Code |
|---|---|---|---|
| 1 | Atari Qbert target | 2500 (≈5× max) (Table 8) | 14000 (`trainer_atari.py:165-166`) |
| 2 | Atari Seaquest target | 1450 (Table 8) | 1150 (`:163-164`) |
| 3 | Reacher target | 50 (Table 9) | env_targets [76, 40] (`experiment.py:57`) |
| 4 | Reacher K | 5 (Table 9) | default 20 (`:288`) |
| 5 | Gym warmup | "linear warmup for first 10^5 steps" (Tables 9/10, per ar5iv rendering) | 10,000 (`:299`) |
| 6 | Gym BC | 3 layers, 256 dim, 2.5e4 steps | defaults 128 dim, 1e5 steps, no grad clip |
| 7 | medium-expert | in Table 2 | `download_d4rl_datasets.py:13` omits it (also absent from the HF mirror) |
| 8 | Seeds (gym) | 3 seeds | `experiment.py` has no seed argument |
| 9 | Atari final tokens | 2·500000·K (Table 8) | `2 · len(dataset) · context · 3` (`run_dt_atari.py:86`) |
| 10 | Atari README | `--block_size 90` | argument is `--context_length` (block_size = 3×) |
| 11 | Algorithm 1 timestep | `t=[1]` | timestep starts at 0 (`evaluate_episodes.py:97`) |
| 12 | Gym eval target | single value per env (HalfCheetah 6000) | evaluates both `[12000, 6000]` etc. |
| 13 | Atari eval | sticky actions in data | `repeat_action_probability=0` (`:231`) |

- #5 is a paper/code difference, not a correction to the published run: the [paper's Gym appendix](https://ar5iv.labs.arxiv.org/html/2106.01345#A1.SS2) prints $10^5$ steps, equal to its stated training length; the released code defaults to 10,000. The actual run logs are not available here.
- #3 and #6: the code differs from the paper unless flags are passed.

## 7. Atari scores (DT paper Table 1, gamer-normalised, 1% DQN-replay)

| Game | DT | CQL | QR-DQN | REM | BC |
|---|---|---|---|---|---|
| Breakout | 267.5±97.5 | 211.1 | 17.1 | 8.9 | 138.9±61.7 |
| Qbert | 15.4±11.4 | 104.2 | 0.0 | 0.0 | 17.3±14.7 |
| Pong | 106.1±8.1 | 111.9 | 18.0 | 0.5 | 85.2±20.0 |
| Seaquest | 2.5±0.4 | 1.7 | 0.4 | 0.7 | 2.1±0.3 |

- Raw DT scores (Table 12): Breakout 76.9±27.3, Qbert 2215.8±1523.7, Pong 17.1±2.9, Seaquest 1129.3±189.0.

## 8. Standard D4RL locomotion table

**DT paper Table 2** (normalised, v2 datasets; DT is mean ± std over 3 seeds)

| Dataset | Env | DT | CQL | BEAR | BRAC-v | AWR | BC |
|---|---|---|---|---|---|---|---|
| Medium-Expert | HalfCheetah | 86.8±1.3 | 62.4 | 53.4 | 41.9 | 52.7 | 59.9 |
| Medium-Expert | Hopper | 107.6±1.8 | 111.0 | 96.3 | 0.8 | 27.1 | 79.6 |
| Medium-Expert | Walker | 108.1±0.2 | 98.7 | 40.1 | 81.6 | 53.8 | 36.6 |
| Medium | HalfCheetah | 42.6±0.1 | 44.4 | 41.7 | 46.3 | 37.4 | 43.1 |
| Medium | Hopper | 67.6±1.0 | 58.0 | 52.1 | 31.1 | 35.9 | 63.9 |
| Medium | Walker | 74.0±1.4 | 79.2 | 59.1 | 81.1 | 17.4 | 77.3 |
| Medium-Replay | HalfCheetah | 36.6±0.8 | 46.2 | 38.6 | 47.7 | 40.3 | 4.3 |
| Medium-Replay | Hopper | 82.7±7.0 | 48.6 | 33.7 | 0.6 | 28.4 | 27.6 |
| Medium-Replay | Walker | 66.6±3.0 | 26.7 | 19.2 | 0.9 | 15.5 | 36.9 |
| Average (w/o Reacher) | | 74.7 | 63.9 | 48.2 | 36.9 | 34.3 | 46.4 (as printed; recomputed from rows = 47.7, printed pair looks swapped) |

- Reacher rows: ME 89.1±1.3 DT / 30.6 CQL / 73.3 BC; M 51.2±3.4 / 26.0 / 48.9; MR 18.0±2.4 / 19.0 / 5.4. Average over all settings: DT 69.2, CQL 54.2, BC 47.7.
- Provenance: CQL numbers from the CQL paper, BC run by the authors, others from the D4RL paper.

**%BC (DT Table 3)**
- Medium: HalfCheetah 42.9 (10%) / 43.0 (25%) / 43.1 (40%) / 43.1 (100%).
- Medium-Replay Hopper: 70.6 / 58.6 / 31.0 / 27.6.
- Averages: DT 56.1, 10%BC 56.7, 25%BC 52.7, 40%BC 49.4, 100%BC 39.5, CQL 43.5.

**IQL paper Table 1** (arXiv 2110.06169; "averaged normalized scores", v2 locomotion)

| Dataset | BC | 10%BC | DT | AWAC | Onestep | TD3+BC | CQL | IQL |
|---|---|---|---|---|---|---|---|---|
| halfcheetah-medium-v2 | 42.6 | 42.5 | 42.6 | 43.5 | 48.4 | 48.3 | 44.0 | 47.4 |
| hopper-medium-v2 | 52.9 | 56.9 | 67.6 | 57.0 | 59.6 | 59.3 | 58.5 | 66.3 |
| walker2d-medium-v2 | 75.3 | 75.0 | 74.0 | 72.4 | 81.8 | 83.7 | 72.5 | 78.3 |
| halfcheetah-medium-replay-v2 | 36.6 | 40.6 | 36.6 | 40.5 | 38.1 | 44.6 | 45.5 | 44.2 |
| hopper-medium-replay-v2 | 18.1 | 75.9 | 82.7 | 37.2 | 97.5 | 60.9 | 95.0 | 94.7 |
| walker2d-medium-replay-v2 | 26.0 | 62.5 | 66.6 | 27.0 | 49.5 | 81.8 | 77.2 | 73.9 |
| halfcheetah-medium-expert-v2 | 55.2 | 92.9 | 86.8 | 42.8 | 93.4 | 90.7 | 91.6 | 86.7 |
| hopper-medium-expert-v2 | 52.5 | 110.9 | 107.6 | 55.8 | 103.3 | 98.0 | 105.4 | 91.5 |
| walker2d-medium-expert-v2 | 107.5 | 109.0 | 108.1 | 74.5 | 113.0 | 110.1 | 108.8 | 109.6 |
| **locomotion total** | 466.7 | 666.2 | 672.6 | 450.7 | 684.6 | 677.4 | 698.5 | 692.4 |

- The IQL table's DT column is identical to the DT paper's (copied).
- IQL AntMaze (v0, total column "antmaze-v0 total"): BC 100.2, 10%BC 134.2, DT 112.2, AWAC 107.7, Onestep 125.3, TD3+BC 163.8, CQL 303.6, IQL 378.0.
  - Per task, DT: umaze 59.2, umaze-diverse 53.0, others 0.0.
  - IQL: 87.5 / 62.2 / 71.2 / 70.0 / 39.6 / 47.5.
  - CQL: 74.0 / 84.0 / 61.2 / 53.7 / 15.8 / 14.9.
- IQL Table 3 (Kitchen/Adroit): kitchen totals BC 154.5, CQL 144.6, IQL 159.8; adroit totals BC 104.5, CQL 93.6, IQL 118.1. DT is not reported there.

**D4RL paper Table 2** (3 seeds, v0): CQL halfcheetah-medium 44.4, hopper-medium 58.0, walker2d-medium 79.2, and so on. BC: 36.1 / 29.0 / 6.6 (medium), which are far lower than DT's own BC.
- The D4RL paper's CQL column has hopper-ME 98.7 and walker2d-ME 111.0, whereas DT's Table 2 has Hopper-ME 111.0 and Walker-ME 98.7. [inferred] a swap in one of the two papers; I did not check the original CQL paper.

## 9. Ready-to-use real numbers

**D4RL v2 locomotion files** (measured, [local]). The split rule is terminal-or-timeout, as in DT's script. N = timesteps in file. "Dropped" = trailing steps with no end flag. The follow-up [script](./verification/10_d4rl_counts.py) and [JSON receipt](./verification/10_d4rl_counts_output.json) recount all 15 cached HDF5 files and publish counts, length/return means and return standard deviations. This verifier does not recompute the state-normalization vectors, individual RTG rows, min/max or normalized returns below.

| dataset | N | trajectories (DT-style) | dropped | len mean (min–max) | return mean ± std | return max / min | norm. mean |
|---|---|---|---|---|---|---|---|
| halfcheetah-random | 1,000,000 | 1000 | 0 | 1000 | -288.8 ± 80.4 | -85.4 / -526.0 | -0.1 |
| halfcheetah-medium | 1,000,000 | 1000 | 0 | 1000 | 4770.3 ± 355.8 | 5309.4 / -310.2 | 40.7 |
| halfcheetah-medium-replay | 202,000 | 202 | 0 | 1000 | 3093.3 ± 1680.7 | 4985.1 / -638.5 | 27.2 |
| halfcheetah-medium-expert | 2,000,000 | 2000 | 0 | 1000 | 7713.4 ± 2970.2 | 11252.0 / -310.2 | 64.4 |
| halfcheetah-expert | 1,000,000 | 1000 | 0 | 1000 | 10656.4 ± 441.7 | 11252.0 / 2045.8 | 88.1 |
| hopper-random | 1,000,000 | 45,239 | 4 | 22.1 (7–163) | 18.4 ± 17.5 | 292.6 / 2.9 | 1.2 |
| hopper-medium | 1,000,000 | 2186 | 94 | 457.4 (145–1000) | 1422.1 ± 379.0 | 3222.4 / 315.9 | 44.3 |
| hopper-medium-replay | 402,000 | 2041 | 0 | 197.0 (1–1000) | 467.3 ± 511.0 | 3192.9 / -1.4 | 15.0 |
| hopper-medium-expert | 1,999,906 | 3213 | 506 | 622.3 (145–1000) | 2089.9 ± 1040.0 | 3759.1 / 315.9 | 64.8 |
| hopper-expert | 1,000,000 | 1027 | 506 | 973.2 (449–1000) | 3511.4 ± 328.6 | 3759.1 / 1645.3 | 108.5 |
| walker2d-random | 1,000,000 | 48,907 | 3 | 20.4 (7–102) | 1.9 ± 5.8 | 75.0 / -17.0 | 0.0 |
| walker2d-medium | 1,000,000 | 1190 | 5 | 840.3 (60–1000) | 2852.1 ± 1095.4 | 4226.9 / -6.6 | 62.1 |
| walker2d-medium-replay | 302,000 | 1093 | 0 | 276.3 (3–1000) | 682.7 ± 896.0 | 4132.0 / -50.2 | 14.8 |
| walker2d-medium-expert | 1,999,995 | 2190 | 786 | 912.9 (60–1000) | 3796.6 ± 1312.3 | 5011.7 / -6.6 | 82.7 |
| walker2d-expert | 1,000,000 | 1000 | 786 | 999.2 (214–1000) | 4920.5 ± 136.4 | 5011.7 / 763.4 | 107.1 |

- The 9 DT-used datasets' trajectory counts match HF split sizes: hc-expert 1000, hc-medium 1000, hc-MR 202, hopper-expert 1027, hopper-medium 2186, hopper-MR 2041, walker-expert 1000, walker-medium 1190, walker-MR 1093.
- Terminal/timeout counts, for reference: hopper-medium 2185 terminals / 1 timeout; hopper-expert 89 / 938; walker2d-medium 513 / 677.
- Medium-replay sizes in the cached v2 files (202k, 402k, 302k) are approximately **2×, 2× and 3×**, respectively, the HalfCheetah, Hopper and Walker2d counts printed in [D4RL Table 1](https://arxiv.org/abs/2004.07219) (101,000, 200,920, 100,930). The earlier release was not recounted; the cause of the differences is not verified.
- The DT paper says medium-replay is "approximately 25k–400k timesteps"; the v2 files measured here fit the upper end only.
- File sizes (bytes) for download planning: hopper-medium 152,756,557; hopper-medium-replay 75,854,457; hopper-medium-expert 304,537,315; halfcheetah-medium-replay 59,448,533; walker2d-medium-replay 86,323,963.
- Hopper-medium state mean (11-d, [local]): `[1.311, -0.085, -0.538, -0.072, 0.049, 2.107, -0.150, 0.009, -0.285, -0.185, -0.285]`; std `[0.178, 0.054, 0.213, 0.145, 0.612, 0.852, 1.452, 0.675, 1.536, 1.616, 5.607]`.
- Hopper-medium trajectory 0: length 470, `rtg[0] = 1465.18`, so `rtg[0]/1000 = 1.465`; `rtg[-1]` equals the last reward.

**Config defaults at a glance**
- DT gym defaults: K=20, batch 64, embed 128, 3 layers, 1 head, lr 1e-4, wd 1e-4, warmup 1e4, 1e5 steps, 100 eval episodes, dropout 0.1, `scale=1000`.
- DT Atari: 500k transitions, 50 buffers × 10 trajectories each, epochs 5, lr 6e-4, 6 layers, 8 heads, 128 embed.
- HF `DecisionTransformerConfig`: `hidden_size=128`, `n_layer=3`, `n_head=1`, `max_ep_len=4096`.

## 10. What to run locally to verify

1. Re-run the completed HDF5 recount with `python verification\10_d4rl_counts.py <directory-of-v2-files>`; see [receipt](./verification/10_d4rl_counts_output.json).
2. Run the DT download script and print "N trajectories, T timesteps" with `experiment.py:93`; compare with HF `dataset_info` split sizes.
3. Recompute state mean/std for one dataset and confirm `np.std(...)+1e-6` matches the numbers above.
4. Build a batch with `get_batch(64)` and check: `rtg` shape `(64, K+1, 1)`, final RTG pad value, mask, `timesteps` clamped at 999, `a` padded with -10.
5. Check that `p_sample` depends only on `traj_len` (print `np.corrcoef(p_sample, returns)`), confirming it is not return-weighted.
6. Compute the empirical fraction of short windows for hopper-medium-replay and compare to 9.3% (section 2).
7. Instantiate `DecisionTransformerConfig()` and `DecisionTransformerModel`, print `sum(p.numel())`, and compare with the original `DecisionTransformer` at matched dims (hopper: state 11, act 3, max_ep_len 1000).
8. The HF/official comparison was executed in [04 §2.1](./04-clone-and-run.md): `position_ids = zeros` still adds `wpe[0]`; the documented equality is for a matched-weights test with that table zeroed, not the default architectures.
9. Train `python experiment.py --env hopper --dataset medium --model_type dt --max_iters 2 --num_steps_per_iter 1000 --num_eval_episodes 3` and verify logged keys `evaluation/target_3600_return_mean` etc.
10. For Atari, after `gsutil` download of one game, count loaded transitions, trajectories, and `max rtg` printed by `create_dataset.py:91`; compare max RTG against the paper's "≈1×/5× max in dataset" claim (Table 8).
11. Check whether reward clipping is applied in the DQN replay data (see section 11).

## 11. Not verified / open questions

- **Which iteration gets reported.** Neither the paper nor the code says whether Table 2 uses the last of the 10 iterations or the best; `experiment.py` logs every iteration.
- **Paper's eval episode count.** The paper doesn't state one. The code defaults are 100 per target (gym) and 10 (Atari).
- **DT warmup.** The printed value and code default are known (section 6 #5); which warmup the reported run actually used is not verified.
- **medium-expert construction.** DT's pickles for it are not produced by the public script. Presumably concatenated medium + expert; not verified.
- **BC and CQL baselines.**
  - DT's BC (e.g. hopper-medium 63.9) differs from IQL's BC (52.9) and D4RL's BC (29.0).
  - DT's CQL numbers differ from IQL's CQL (e.g. hopper-MR 48.6 vs 95.0). Possible cause: v0 vs v2 data or re-implementation. Not verified.
  - D4RL Table 2 vs DT Table 2 has Hopper/Walker medium-expert CQL swapped. The original CQL paper was not fetched.
- **v0 vs v2 sizes.** Section 9 shows medium-replay doubling. I did not download v0 `*_mixed.hdf5` to confirm the paper's numbers.
- **Atari.**
  - I did not download `gs://atari-replay-datasets` to check the 100,000-transition cap in `create_dataset.py:65` against the README's "~50M".
  - Whether DQN replay rewards are clipped to [-1, 1] is not verified; it changes the RTG scale and the Atari target returns (Qbert 14000 vs 2500).
  - Whether terminal flags in replay buffers include life-loss events is not verified.
  - The Atari eval env uses life-loss as a terminal in training mode and game-over in eval mode (`trainer_atari.py:285-291`).
- **HF docs.** I used v5.23.0 docs and `main` code; defaults may change in later versions.
- **Out of scope / not covered.** Online DT, Multi-Game DT, Trajectory Transformer, Gato, and Maze2D/AntMaze details for DT; DT numbers on AntMaze/Kitchen/Adroit come only from IQL's table. RoboMimic PH sizes not verified. I did not fetch the DT repo's GitHub issues or discussions.
