Every number on this page carries one of three labels:
01What the model is for, and what it reads
The coach needs to say things like “their carry was last seen mid, he is probably farming there” or “this wave is safe to push”. Each of those is a claim about something the team cannot see. The replay knows the truth, so a model can learn it.
The route chosen in D-67 is the language-model one. Write a team's game as a long sequence of tokens, exactly as the team saw it, and train a transformer to predict the next token. Predicting the next sighting of an enemy well is only possible if the model keeps some internal picture of where the enemies probably are. On top of that next-token objective sit belief heads: small networks that read the model's internal state and output, for each of the five enemies, a probability for every cell of the map. They are trained against the true positions from the replay, which the model never reads as input.
One document per team, fogged
Each game becomes two documents, one per team. A document contains only what that team could know: its own heroes, enemies while they are visible, the scoreboard, announced events. No enemy commands, no gold, no unseen positions, no enemy wards. When an enemy is not visible, the stream repeats every 15 seconds where and how long ago it was last seen.
Dire documents are mirrored (x, y → −x, −y, top and bottom lanes swapped), so every document reads as if our base were bottom-left. The model learns one map, not two. A team token stays in the stream so the side is not lost.
Positions are cells of a 32 × 32 grid over the 16,384-unit map, each cell 512 units wide (a hero's day vision is about 1,800 units, so about 3.5 cells). A cell is one token, c:<id> with id = column × 32 + row; c:611 is column 19, row 3, our bottom (safe) lane. One cell token instead of separate x and y tokens keeps the stream short.
The 5-second step
The replay data comes in 5-second steps, and so does the stream (built by models/stream.py). Each step, in this order:
min:<m>when the minute changes, then a clock tokent:<0–11>(which 5-second slot of the minute).- Five query tokens
?foe:0…?foe:4. They carry no information; they are fixed positions where the belief heads read enemy 0 to 4 (more in Where the heads read). - Every 60 seconds a
[RECAP]: team, rank, result (masked, see below), minute, all ten heroes' level and K/D/A, our last hits, our items, enemy items as last seen, our wards, towers standing. - Our five heroes:
own:k c:<cell>, then hp and mana deciles, level, alive or a respawn bin, only when they changed;go:<cell>(a 16 × 16 grid) when the hero clicked to move somewhere new. - Each visible enemy:
foe:k c:<cell>plus hp and level on change. Every 15 seconds, each unseen enemy:foe:k last c:<cell> ago:<bin>(ornever), andisdeadif dead. - Every 15 seconds our three lanes:
lane:top n:<creeps> front:<progress>; Roshan's hp only with one of our heroes at the pit. - Events: our casts (ability, and target class or cell), skill points, items gained, buyback, glyph, runes, attack-target changes; kills and deaths of both sides; buildings destroyed; our buildings' hp; enemy casts we saw; our wards placed and gone.
An illustrative fragment, built from these token formats (the cells are plausible, the game is not a real one; ability and item names are placeholders):
# illustrative, not from a real game. Minute 12:00, then 12:05. min:12 t:0 ?foe:0 ?foe:1 ?foe:2 ?foe:3 ?foe:4 [RECAP] team:0 rank:6 res:? min:12 own:0 lv:12 k:3 d:1 a:4 lh:6 items it:… … foe:4 lv:11 k:2 d:3 a:3 wards:2 twr_own:10 twr_foe:9 own:0 c:611 hp:7 # our safe lane (column 19, row 3) own:1 c:528 mp:3 # map centre, mid lane own:2 c:83 # our off lane own:3 c:551 go:137 # our jungle, clicked to move own:4 c:67 alive # fountain, just respawned foe:2 c:529 hp:9 # visible now, next to our mid foe:0 last c:115 ago:4 # not visible: last seen in our off lane, 30-60 s ago foe:1 last c:600 ago:5 # 1-2 min ago, their jungle foe:3 last c:528 ago:2 # 10-20 s ago, mid foe:4 last c:921 ago:6 # 2-5 min ago, near their base lane:top n:2 front:7 lane:mid n:3 front:8 lane:bot n:1 front:9 own:1 cast:<ability> c:529 own:3 got:<item> ward:obs c:497 t:1 ?foe:0 ?foe:1 ?foe:2 ?foe:3 ?foe:4 own:0 c:611 own:1 c:529 hp:5 … foe:2 c:529 hp:3 kill own:1 death foe:2
The full corpus (stream v2) is 111,324 documents and 3.11 billion tokens, from about 55,000 games. The vocabulary has 3,779 tokens plus one, res:?, that the trainer adds: 3,780 in all. Held out: the latest 10% of matches (11,134 documents), both documents of a game on the same side of the split.
The truth, and the window
Next to the tokens, for every step, the builder writes a truth row the model never reads: each enemy's true cell now and 30 seconds later, whether it is seen, alive, how long since it was last seen, its last-seen cell, and whether it died since. These are the belief targets and the labels for the evaluation.
Training reads windows of 2,048 tokens starting at random positions inside a document. At roughly 28,000 tokens per document, a window is about 2.5–3 minutes of play estimate. Two details matter:
- The result token (
res:win/res:lossin the recap) is replaced byres:?in half the training windows and always in evaluation. With it in the context the model can also learn “what winning teams do next”, which the later coach may use. Without masking it would simply learn to cheat with it. - The heads are trained only at steps with at least 256 tokens (an eighth of the window) of context behind them, so they are never asked about a step they have no context for.
02The architecture
A small GPT: a decoder-only transformer, the same design as GPT-2, at width 256, 4 layers, 4 attention heads, context 2,048. The code is models/stream_gpt.py, classes Block and GPT.
The picture
Walking through it, with shapes
A training batch is 16 windows of 2,048 tokens: a 16 × 2,048 array of integers.
- Token embedding. Each token id selects a row of a 3,780 × 256 table: now 16 × 2,048 × 256 numbers. The table is learned: tokens that behave alike (two cells next to each other, two similar spells) end up with similar rows.
- Position embedding. A second learned table, 2,048 × 256, one row per slot of the window, added to the token rows. Without it attention would see a bag of tokens with no order. These are positions in the window, not game time; game time is in the stream itself (
min:,t:,ago:tokens). - The residual stream. The result, 256 numbers per position, is the model's working memory. Each block reads it (through a LayerNorm), computes something, and adds the result back. Because blocks add rather than replace, information written early (the identity of the token, its position) survives to the top unless something deliberately cancels it, and gradients flow straight down the spine during training. That is what makes deep stacks trainable.
- Four blocks, each attention then MLP (below).
- Final LayerNorm, then two kinds of output: the LM head at every position, the belief heads at the query positions.
Attention and the causal mask
Attention is the only place where positions exchange information. At every position the block computes three vectors from the normalised residual stream with one matrix multiply (qkv, 256 → 768): a query (“what am I looking for?”), a key (“what do I contain?”), and a value (“what do I hand over if chosen?”). The 256 numbers are split into 4 heads of 64, and each head works independently:
- the score between position i and an earlier position j is the dot product qi · kj, divided by √64 = 8 so the scores do not grow with the head width;
- a softmax over j turns the scores into weights that sum to 1;
- the head's output at i is the weighted sum of the values vj.
The four heads' outputs are concatenated back to 256 numbers and passed through one more matrix (proj, 256 → 256) before being added to the stream. Four heads can look for four different things at once: one the last sighting of this enemy, one our heroes' current cells, one the clock.
The causal mask sets the score to −∞ for every j > i, so a position can only read itself and what came before (the triangle in the diagram). This is what makes next-token prediction honest: when the model predicts token i + 1 from position i, the answer is not visible. It also means a training window gives 2,048 predictions at once, one per position, each with exactly the context it would have had in real time. The code calls PyTorch's scaled_dot_product_attention(…, is_causal=True), which on the GPU runs a fused kernel that never stores the full 2,048 × 2,048 score matrix.
Why it can remember a sighting from 2 minutes ago. In attention, distance costs nothing. Position 1,900 can put all its weight on position 50 as easily as on position 1,899; what decides is whether the query matches the key, not how far apart they are. A recurrent model would have to carry the sighting forward step by step and could blur it; here the model looks it up directly, as long as it is still inside the 2,048-token window. Beyond the window, the stream helps: the foe:k last c:… ago:… lines restate the last sighting every 15 seconds, so even a sighting that has scrolled out of the window is summarised inside it.
The MLP, the norms, the outputs
MLP. After attention has gathered information into a position, the MLP processes it there, position by position, with no mixing across positions: 256 → 1,024 numbers, a GELU non-linearity, 1,024 → 256. The widening to 4× gives it room to compute features that are not straight lines of the inputs: “last seen in our off lane 40 seconds ago, minute 12, a carry” → “probably back in their jungle or farming the lane”. Roughly, attention decides what to read and the MLP decides what it means. Two thirds of each block's parameters are in the MLP.
LayerNorm. Before each sub-layer (“pre-LN”) the 256 numbers of a position are rescaled to mean 0 and variance 1, then multiplied and shifted by learned per-channel factors. This keeps the inputs to every matrix in a stable range however much the stream has grown, which matters for training stability, and in fp16 for not overflowing.
LM head. A 256 → 3,780 matrix gives one score (logit) per vocabulary token at every position; the softmax of those is the model's distribution over the next token. Its weights are tied to the token embedding (the same 3,780 × 256 table, used transposed): a token that should come next is scored by how well the hidden state matches that token's own embedding row. This halves the vocabulary parameters and helps rare tokens, whose input and output rows learn from each other.
Belief heads. At the five query tokens of each step, the final hidden state at ?foe:k goes through a small MLP (256 → 1,024 → GELU → 1,024) whose 1,024 outputs are one logit per map cell; a softmax over them is the probability map for enemy k. The same head is used for all five enemies: what differs is the hidden state, because the query token ?foe:2 is a different token from ?foe:0 and attention there can fetch enemy 2's history. A second head of the same shape predicts the cell 30 seconds later. The loss only counts enemies that are alive (for the +30 s head, alive 30 seconds later).
Why depth matters
Consider the simplest useful thing the model must do: at ?foe:3, find where enemy 3 was last seen. In the stream that is the c:528 right after foe:3 last. The difficulty is that the cell token c:528 on its own does not know whose cell it is; only its neighbour foe:3 does.
- With one layer, the query at
?foe:3can matchfoe:3tokens (but their values do not hold the cell) orc:tokens (but nothing in their keys says “I belong to enemy 3”). The lookup cannot be expressed. - With two layers, a head in layer 1 at each
c:token can copy in “the token before me wasfoe:3”. In layer 2, the query at?foe:3matches that tag and copies the cell. This two-step pattern is what the interpretability literature calls an induction head (Olsson et al., 2022).
That is our reading of the depth sweep, consistent with its numbers but not proven for this model. The sweep (Colab A100, the same 100,000 steps and 3.3B tokens for each, joint at weight 0.2, seed 0) kept the transformer layers at 3.2–3.6M parameters, so deeper models are also narrower:
| Layers × width | 5–10 s | 30–60 s | 60–120 s | 2–5 min | LM probe 30–60 s | Cell-token loss |
|---|---|---|---|---|---|---|
| 1 × 512 | 4.21 | 5.59 | 5.71 | 5.79 | 4.47 | 3.73 |
| 2 × 384 | 3.36 | 5.08 | 5.39 | 5.46 | 3.93 | 2.03 |
| 4 × 256 (current) | 3.30 | 5.05 | 5.37 | 5.43 | 3.80 | 1.98 |
| 8 × 192 | 3.28 | 5.03 | 5.35 | 5.41 | 3.74 | 1.97 |
| 16 × 128 | 3.32 | 5.03 | 5.36 | 5.44 | 3.82 | 2.00 |
| Table2 baseline | 4.01 | 5.89 | 6.10 | 6.27 | 6.08 | – |
What the numbers say:
- One layer is not enough, two almost is. The 1-layer model, although twice as wide, is worse than the count table at 5–10 seconds (4.21 vs 4.01): it cannot even copy a cell that is a few tokens back in its context. Its loss on cell tokens is 3.73 against 1.98. The jump from 1 to 2 layers (5.59 → 5.08 at 30–60 s) is many times larger than anything after it.
- Beyond 4 layers, little. 4 → 8 layers gains 0.02 nats, below the 0.03 run-to-run spread measured by repeating the 4-layer run. 16 layers at width 128 is no better than 8 at 192 on the map and worse on the LM probe (3.82 vs 3.74): at width 128 each layer is too narrow, with only two attention heads of 64.
- Against the reading declared before the sweep (depth matters for inference if the 1 → 4 gain is larger at 30–120 s than at 5–10 s): it is not. The gain is 0.91 nats at 5–10 s, 0.54 at 30–60 s, 0.35 at 60–120 s derived. Depth here buys mostly the lookup, not long chains of inference. The other declared clause (if 1 layer is within 2% of 4 layers at 30–120 s, the model is mostly looking things up) is not triggered either: 1 layer is 9.6% worse at 30–60 s. This reading is this page's, from the reports; it has not yet been written into the decision log.
Caveats: one seed per depth; width changes with depth, so “depth” here means “depth at fixed layer parameters”.
Where the heads read, and the --read-next fix
The query tokens sit right after the clock, before the rest of the step. Under the causal mask, the hidden state at ?foe:k of step s has seen everything up to step s − 1 but nothing of step s: not where our heroes are now, not who is visible now. The heads are trained on every living enemy, visible or not. So the belief answers “where is he, visible or not, as of 5 seconds ago”.
Reading the Fog of War page, Baro saw the consequence: the model put a hidden Pudge's belief on cells our hero and tower could see. If he were there, he would be visible. A coach needs “where is he, given that we cannot see him”.
The fix needs no new corpus. With --read-next, step s's belief is read at step s + 1's query tokens. They come after all of step s, so the hidden state there has seen our positions and every sighting of step s, and still nothing of step s + 1. The trainer checks that the next truth row really is the next step, and drops the last step of a document.
?foe:2.A new metric goes with it: the belief's mass inside our heroes' vision in this step (cells within 4 cells, about 2,000 units, of where our five heroes stand). For a hidden enemy this should be near zero; a uniform belief would put about 0.24 of its mass there. The run comparing the two read positions (4 × 256, weight 0.2, 100k steps, Kaggle) is declared: the fix works if, for hidden enemies at 30–120 s, the mass in our vision falls by more than half and the NLL improves by more than 0.05. Results pending.
Parameter count
From the shapes in the code, for V = 3,780, d = 256, 4 layers, context 2,048, MLP belief heads with per-enemy maps of 1,024 derived:
| Part | Shapes | Parameters |
|---|---|---|
| Token embedding (also the LM head, tied) | 3,780 × 256 | 967,680 |
| Position embedding | 2,048 × 256 | 524,288 |
| One block: 2 LayerNorms | 2 × (256 + 256) | 1,024 |
| qkv | 256 × 768 + 768 | 197,376 |
| proj | 256 × 256 + 256 | 65,792 |
| MLP up | 256 × 1,024 + 1,024 | 263,168 |
| MLP down | 1,024 × 256 + 256 | 262,400 |
| = one block | ≈ 12·d² + 13·d | 789,760 |
| 4 blocks | 4 × 789,760 | 3,159,040 |
| Final LayerNorm | 256 + 256 | 512 |
| Belief head “now” | 256 × 1,024 + 1,024 + 1,024 × 1,024 + 1,024 | 1,312,768 |
| Belief head “+30 s” | same | 1,312,768 |
| Total | the transformer (“body”) 4,651,520 + heads 2,625,536 | 7,277,056 |
This matches the count the trainer printed in the 4-layer run's report (7,277,056) measured. Two things stand out: the 4 blocks are only 43% of the model, and the two belief heads (36%) are almost as large, because a 1,024-wide hidden layer feeding 1,024 outputs is a 1M-parameter matrix. The embeddings are another 20%. When the decision log says “7.3M parameters, body ~4.7M”, this is the split.
The modern block (D-72, adopted)
Everything above describes GPT-2's block (2019), which every model so far used. Open models since 2023 (Llama, Qwen, DeepSeek, Kimi, GLM) keep the same skeleton (attention then MLP, each added back to the residual stream) with better parts. --arch modern swaps in all of them at once; one run against the 31M reference decides whether it becomes the base (the plan and the rule: docs/research/modern-block-2026-10-14.md).
- RMSNorm instead of LayerNorm. LayerNorm subtracts the mean and divides by the standard deviation; RMSNorm skips the mean: x / √(mean(x²) + ε) × a learned gain. Re-centring turned out not to matter for transformers, and dropping it saves a reduction per norm. ε is set explicitly to 10−6: PyTorch's default follows the number format, which would differ between training (bf16) and evaluation (fp16).
- RoPE (rotary position embeddings) instead of the learned position table. Each query and key vector is cut into 32 pairs of numbers; pair i at position t is rotated by the angle t · θi, with θi = 10,000−2i/64 (fast-turning pairs for fine distances, slow ones for long distances). The dot product of two rotated vectors depends only on the difference of their angles, so attention sees how far back a token is, never its slot in the window. For our stream that is the right symmetry: “two steps ago” means the same at slot 100 and at slot 1,900. It also has no table to run out of: learned positions stop at 2,048, RoPE does not, which is what makes the long-context test below possible. It adds no parameters and removes the 1,048,576 of the position table derived.
- QK-norm. An RMSNorm on each head's queries and keys (64 numbers each) before RoPE. Attention logits are dot products; if queries and keys grow during training the softmax saturates and a head locks onto one token, a known cause of loss spikes. Normalising them bounds the logits. Every 2026 model in our research report uses it.
- SwiGLU MLP instead of GELU. Two up-projections, one passed through SiLU (x · sigmoid(x)) and used as a gate on the other: down(silu(gate(x)) ⊙ up(x)). The gate lets each hidden unit switch another on or off, input by input; at equal parameters it is consistently a little better than a plain MLP. To keep the parameters equal, the hidden width is 8d/3 instead of 4d: at d = 512, 1,344 (rounded to a multiple of 64), so 3 × 512 × 1,344 = 2,064,384 weights against GELU's 2 × 512 × 2,048 = 2,097,152 derived.
- No biases in the blocks: the norms already carry the per-channel offsets that matter, and the additive biases mostly cost memory traffic.
- Scaled initialisation of the residual outputs. The attention output and the MLP down-projection start at standard deviation 0.02 / √(2 × layers) instead of 0.02. Each block adds two outputs to the residual stream; with 8 layers that is 16 additions, so without the scaling the stream's variance grows with depth at initialisation. GPT-2 did this; our code had skipped it, which may also have handicapped the deep, thin models of the depth sweep.
| Part | GPT-2 block (R1) | Modern block |
|---|---|---|
| Attention: q, k, v, output | 1,050,624 (with biases) | 1,048,576 |
| MLP | 2,099,712 (GELU, with biases) | 2,064,384 (SwiGLU) |
| Norms | 2,048 (2 LayerNorms) | 1,152 (2 RMSNorms + QK-norm) |
| One block | 3,152,384 | 3,114,112 |
| Whole model (8 blocks, embeddings, heads) | ≈ 31.4M | ≈ 30.0M (no position table) |
Result. The modern block with Muon, on R1's exact configuration (same data, 100k steps, same test moments), against R1: belief NLL 4.695 vs 4.764 at 30–60 s, 5.063 vs 5.126 at 60–120 s, LM probe 3.266 vs 3.374 measured. That is +0.06 to +0.11, the largest gain of the recent levers (twice the parameters, 31M to 65M, bought 0.03, twice the data and steps 0.04), with 1.4M fewer parameters. It led from the first evaluation at 25k steps. It is now the base block. Caveat: one seed; the block and Muon were tested together, so which part gained is not separated; each step took 0.106 s against 0.0665 (see Muon below).
Film 1 puts the two blocks side by side, told by one of our query tokens, ?foe:2, which wants to know where enemy two is. It starts with what attention can't see on its own (order), then the old fix (the numbered table), the new one (turning dials), the block's other parts, Muon, and the score so far. Press Play for sound.
More history: 16,384 tokens (D-73, pays)
The window of 2,048 tokens is about 3 minutes of a median game (one team's whole game is a median 27,292 tokens measured). An enemy unseen for 2–5 minutes was often last seen before the window starts, and “their carry has farmed the bottom jungle for ten minutes” is invisible. With RoPE the trained model can simply be continued at a longer window: 16,384 tokens, about 24 minutes, at the same tokens per step (batch 2 instead of 16).
Cost. The matrix multiplies cost the same per token at any window; attention's two big products (Q·KT and the weighted sum of V) grow with the window. Per token and layer they cost about 2 × 2 × T × d FLOPs, halved by the causal mask: at T = 2,048 and d = 512 that is ~2.1M against the matrices' ~6.3M per token per layer (forward); at 16,384 it is ~16.8M. Per layer that is 23.1M against 8.4M FLOPs per token; with the LM head and belief heads unchanged, a step should cost roughly 2–2.5 times as much estimate. Memory does not explode, because the fused attention kernel never stores the T × T score matrix.
A fair test. Two continuations of the same model for 20,000 steps: one at 16,384 tokens, one at 2,048 (so extra steps alone cannot explain a gain). Both are scored on exactly the same moments: held-out windows that end at the same point of a game, scoring only the rows a 2,048 window would score. The long model just sees more of the past. If memory matters, it shows up for enemies unseen for 2–5 minutes and longer.
Result. On the same 4,096 held-out windows, the 16k arm beats the 2k arm in every bin, and the gain grows with how long the enemy has been unseen: +0.05 at 5–10 s, +0.11 at 30–60 s, +0.12 at 1–2 min, +0.14 at 2–5 min (belief NLL 4.96 vs 5.08 at 1–2 min; 4.95 vs 5.09 at 2 min+) measured. Both thresholds of the declared rule pass by more than 0.07, and no bin got worse. The language model gains the same way (LM probe +0.10 to +0.14 from 30 s to 5 min). Caveats: one seed; both arms continue a model trained at 2,048, so a model trained long from the start may gain more; 16k windows took 1.74× as long per step at the same tokens.
03Training
Two losses, both cross-entropy in nats
Both outputs are probability distributions over a fixed set of choices: the next token (3,780 choices) and an enemy's cell (1,024 choices). Both are trained with cross-entropy: the negative natural log of the probability the model gave to what really happened. Probability 1 costs 0; probability 0.5 costs 0.69; probability 1/1,024 costs 6.93. The unit is the nat (natural log; bits would use log2).
A useful reading: eloss is the effective number of choices. A model that spreads its probability evenly over N cells and always includes the right one has loss ln N. So:
- a uniform belief over the map: 6.93 nats, e6.93 ≈ 1,024 cells;
- the current model for an enemy unseen 30–60 s: 5.04 nats ≈ 154 cells; the Table2 baseline: 5.89 ≈ 361 cells derived;
- the next cell token in the stream (mostly our own heroes' positions): 1.98 nats ≈ 7 choices.
Averages of logs are not logs of averages, so these “cells” are a geometric-mean reading, not a count of where the probability is. They are good for comparing models on the same rows.
loss = 1.0 × LM + 0.2 × (belief_now + belief_30s) LM = mean over all 16 × 2,048 positions of −ln p(next token) belief_now = mean over (step, enemy) rows with the enemy alive, of −ln p(true cell now) belief_30s = the same for the cell 30 s later (same rows)
Typical values late in training: LM about 1.2–1.3, the belief sum about 8.5–10 (two NLLs of roughly 4–5 each, averaged over all horizons).
Probe or joint, and why 0.2
The heads can be trained in two ways:
- As probes (the first design): the hidden state is detached before the heads, so the belief loss trains only the heads; the transformer learns only from predicting the stream. This asks: does the stream alone make the model hold a map?
- Jointly (
--joint, the current default): the belief loss's gradient also flows into the transformer, so the true positions shape the representation. This asks for the best map.
The history, in short (details in the decision log): probes on the stream-only model stayed near the table; joint heads beat it at every horizon. At weight 1 the joint model paid for it in stream quality: cell-token loss 2.19 against 1.95 for the stream-only model, events 2.05 vs 1.71. Three explanations were possible: capacity, the single read position of the first stream, or loss weighting (a belief row costs ~11 nats against ~1.3 for a stream token, and the heads train at twice the learning rate). The control settled it:
| Run | Belief, seen now | 30–60 s | 60–120 s | 2–5 min | Cells loss | Events loss |
|---|---|---|---|---|---|---|
| Joint, belief weight 1 | 3.03 | 5.07 | 5.38 | 5.46 | 2.19 | 2.05 |
| Joint, belief weight 0.2 | 2.97 | 5.04 | 5.37 | 5.43 | 1.99 | 1.78 |
| Map alone (no stream loss) | 3.12 | 5.16 | 5.43 | 5.50 | – | – |
| Stream alone | – | – | – | – | 1.95 | 1.71 |
| Table2 baseline | 3.72 | 5.89 | 6.10 | 6.27 |
Two conclusions. The stream helps the map: without the stream loss the map is worse at every horizon. And the cost to the stream was mostly weighting, not capacity: at weight 0.2 the stream is within 0.05–0.07 nats of stream-only and the map is the best of the three. The intuition: the belief loss is large in absolute terms, so at weight 1 its gradients dominate the shared weights. At 0.2 the two objectives pull with similar force and turn out to cooperate: learning to predict the stream teaches the model the game, which the map then uses. Hence the default: joint, belief weight 0.2. One seed per run; a repeat of the 0.2 run on other hardware gave 2.93 / 5.05 / 5.37 / 5.43, so differences below ~0.03 nats are noise.
Backpropagation, layer by layer (Film 2)
Training turns each loss into a change of every weight: autograd runs the chain rule over the forward pass in reverse, and every operation hands its output's gradient down to its inputs by its own local rule. Film 2 follows one real backward pass. The model is modern-R1 after 100k steps; the game is held out (test A); the window runs 31:35 to 34:30; and the loss is a single one: the belief of ?foe:2 at 34:30, enemy two unseen for 30 s, which gave the true cell 1.9% (3.96 nats). In training this loss is one of about 2,000 belief rows in a batch (weight 0.2), averaged with 32,768 next-token losses; the film isolates it to see where its gradient goes. The film stops three times for a prediction; when it ends, pick a layer and see how far back the blame has reached. Press Play for sound.
What the trace shows measured. The gradient at the query is larger at the bottom than at the top (|∂x| 0.17 after block 8, 0.38 at the embedding): each block adds what comes back through its branches to what the skip path carries unchanged. Only attention moves the gradient between positions; the MLPs, the norms and the heads act per position. So the set of earlier positions that receive more than 1% of the query's gradient grows block by block as it goes down, from none above block 8's attention to 1,435 of 2,008 at the embedding:
In blocks 5–7 the most blamed earlier tokens are the same question asked 15 and 20 s before (?foe:2 at 34:10 and 34:15, 15–23% of the query's gradient), so the belief is carried forward from query to query and the blame runs back along that chain; at the embedding the largest share goes to our hero 0's cell and move target five seconds earlier (1.3–1.4× the query's own). One example, picked as the first held-out case with enemy two hidden 30–60 s and older sightings in the window; other cases will differ in detail. Trace: tools/film/backprop_trace.py (CPU, fp32, each half-block recomputed in the backward pass to fit in memory; same gradients).
The optimiser
AdamW with β1 = 0.9, β2 = 0.95, weight decay 0.1, peak learning rate 6 × 10−4, gradients clipped to norm 1.
- Adam keeps, per parameter, a running mean of the gradient (momentum, β1) and of its square (β2), and steps by mean / √(mean square). Each parameter thus gets its own step size: rare tokens' embedding rows, which see few gradients, still move. β2 = 0.95 instead of the textbook 0.999 makes the square-average forget faster, which is the usual choice for transformers: it reacts sooner to a sudden gradient spike instead of taking a huge step with a stale, small denominator.
- Weight decay (the “W”) shrinks every weight a little each step, independently of the gradient, a mild pull towards simpler solutions. It applies to the weight matrices and the embeddings, not to biases and LayerNorm gains (since 2026-10-13 evening; before, it applied to every parameter). Pulling a LayerNorm gain towards 0 is not “simpler”, it just shrinks a layer's output, which is why the usual GPT recipes exempt them.
- The belief heads are a separate parameter group at twice the learning rate (1.2 × 10−3): they start from nothing and have a simpler job, so they can move faster.
- Clipping the total gradient norm to 1 caps the damage of a rare bad batch.
Muon for the block matrices (D-72, adopted with the block)
With --opt muon, the 56 weight matrices inside the 8 blocks (q, k, v, output, gate, up, down) are trained by Muon instead of AdamW; embeddings, norm gains and the belief heads stay on AdamW.
- What it does. It keeps a momentum of the gradient (0.95, Nesterov form), like SGD. Then, instead of stepping along that matrix, it steps along the nearest orthogonal matrix: the same singular vectors, all singular values set to 1. A raw gradient of a weight matrix is usually dominated by a few directions (large singular values); orthogonalising gives the rare directions an equal-sized step, so the matrix learns in all its directions at once.
- How, cheaply. An exact SVD per matrix per step would be slow. Five steps of a Newton–Schulz iteration (X ← aX + (bA + cA²)X with A = XXT, after dividing X by its norm) push the singular values towards 1 using only matrix multiplies, in bf16, which the GPU does fast.
- Sharing AdamW's learning rate. The orthogonalised update is rescaled by 0.2 × √(max(rows, cols)), which makes its typical entry the size of an AdamW update (Moonlight, 2025). The same peak 6 × 10−4, warmup and decay then apply to both optimisers; weight decay 0.1 as before.
- Making it fast. The first run (D-72) orthogonalised the 56 matrices one at a time, uncompiled: about a thousand small GPU calls per step after a forward and backward pass of only ~0.07 s, and the run took 0.106 s per step against R1's 0.0665. The matrices come in three shapes (32 of 512 × 512 for q, k, v and output; 16 of 1,344 × 512 for gate and up; 8 of 512 × 1,344 for down), so now each shape is stacked and goes through Newton–Schulz as one batched, compiled call (
torch.compile), and the momentum and weight updates are single multi-tensor (foreach) operations: 3 orthogonalisations per step instead of 56. Same maths: on the CPU the two versions give bit-identical updates measured; the old one stays as--muon-impl loopfor timing. On an L4 it changes nothing: there the step is compute-bound, and seconds per step are R1 0.288, modern block on AdamW 0.300, modern + Muon 0.323 (loop) and 0.320 (batched) measured, so the block and Muon cost only 4% and 7% in arithmetic. The A100's 60% was overhead that appears only when the step is four times faster, and it was Muon's small calls: on an A100, seconds per step are R1 0.0725, modern block on AdamW 0.0775, modern + Muon one matrix at a time 0.1125, batched 0.0825 measured. Batching cuts the step by 27%; the modern block with Muon now costs 14% more per step than R1 (7% the block, 7% Muon), not 55%. - Why try it. DeepSeek, Kimi and Qwen moved their weight matrices to Muon in 2025–26 and report faster training per step. Our runs are step-limited, so a faster optimiser is worth one test. The recipe is the published one, not tuned here: a loss would park Muon, not prove it useless at our size.
The learning-rate schedule: warmup, stable, decay
The multiplier on the learning rate is: linear warmup from 0 to 1 over the first 200 steps; flat at 1; then, over the last 15% of the run, a linear fall to 5% of the peak. When --max-steps is set (the A100 runs, 100,000 steps), the 15% is counted in steps (decay from step 85,000); otherwise in wall-clock time (the Kaggle runs, 5 hours).
Why warmup: at the start Adam's square-averages are near zero and the weights random, so full-size steps can throw the model somewhere it never recovers from. Why stable-then-decay rather than a cosine over the whole run: the run can be stopped or extended at any point, and the decay applied only at the end.
Why most of the improvement shows up in the decay. At a constant, high learning rate the weights do not settle: each step follows a noisy mini-batch gradient and overshoots, so the model bounces around the bottom of a valley in the loss surface instead of reaching it. The loss measured during this phase is the loss of a model that is “close but jittering”. Lowering the learning rate shrinks the jitter and the weights slide down to the floor. The learning of the stable phase is real, but it is only cashed in when the rate drops.
Mixed precision: fp16 with a gradient scaler
Inside torch.autocast(dtype=float16) the matrix multiplies and the attention run in 16-bit floats on the tensor cores; operations that need range or precision (LayerNorm, softmax, the losses) run in fp32, and the master weights and the optimiser states stay fp32. Half-size numbers move half the bytes and the tensor cores multiply them several times faster than fp32.
fp16 has only 5 exponent bits: its smallest normal number is about 6 × 10−5, and many gradients are smaller. They would round to zero. The GradScaler multiplies the loss by a large factor (starting at 216) before the backward pass, so the gradients are shifted up into fp16's range, then divides them back before clipping and the optimiser step. If any gradient overflowed to infinity, the step is skipped and the factor halved; after a run of clean steps it is doubled again.
bf16 (8 exponent bits, the same range as fp32, only 7 mantissa bits) needs no scaler, and the A100 runs it as fast as fp16; the T4s on Kaggle, where these runs started, do not support it. That is why the code used fp16. Since the benchmark, A100 runs use --fast: bf16, no scaler, so also no per-step read-back of “did anything overflow?” (section 06).
04Evaluation, baselines, results
How a model is scored
Fixed windows. The final evaluation of every run uses the same 2,048 held-out windows (chosen once with a fixed seed from the held-out documents). Every model is scored on exactly the same rows, so differences between models are not differences between samples. An early version drew different windows per evaluation and the baselines alone moved by 0.17 nats between draws; that is why. (The curves during training use 256 windows, so they are noisier.)
Belief NLL by time since seen. For every alive enemy at every step with a head read, the NLL of its true cell, averaged in bins of how long ago the team last saw it: seen this step, 5–10 s, 10–20 s, 20–30 s, 30–60 s, 60–120 s, 2–5 min, 5 min+, never. The bins matter because the problem changes with time: at 5–10 s the answer is “about where he was”; at 2 minutes it takes an understanding of the game. About 41,000 rows fall in the 30–60 s bin and 22,000 in 60–120 s. Alongside: the probability mass in the 3 × 3 cells around the truth, and the belief's entropy.
The baselines
- Table2, the registered “stronger table”: counted from the training documents, P(cell | last-seen cell, time bin, died since) mixed with P(cell | enemy hero, minute bin, time bin, died since), each smoothed towards P(cell | time bin). The mixing weight is the best of five, chosen per bin on the evaluated rows themselves, which flatters the table.
- Vision-aware tables: Table2 with its probability pushed out of the cells our team can see (our heroes, observer wards, standing towers, lane creep fronts), again with the push strength chosen on the evaluated rows. Used for the LM probe below.
- The snapshot baseline (
models/stream_state.py): an MLP given a hand-made summary of the moment, per step and enemy: hero, last-seen cell, time since (bin and seconds), died since, minute, the other enemies' last cells, our heroes' cells, our wards, lanes, buildings down. It is built from the whole game so far, so it knows more than the GPT's 2,048 tokens; what it lacks is the order of events. It asks: does reading the stream as a sequence add anything over the same facts as a snapshot? - The LM as its own probe: no head at all. Right after a real sighting
foe:kappears in the stream, the next token is that enemy's cell. The LM's own distribution over the 1,024 cell tokens at that point is a belief that was learned only from predicting the stream. Scored by time since that enemy was last seen.
What we know so far, each with its caveat
- The stream is learned. Held-out loss per token class, 4 × 256 model vs a bigram model: cells 1.98 vs 6.91, events 1.79 vs 5.62, move intent 3.38 vs 5.82, vitals 1.53 vs 4.34, last-seen lines 0.24 vs 2.72 measured. Caveat: a bigram is a floor, not a competitor.
- The joint belief beats the stronger table at every horizon, by 20% seen now, 14% at 30–60 s, 12% at 60–120 s, 13% at 2–5 min (weight 0.2: 2.97 / 5.04 / 5.37 / 5.43 vs 3.72 / 5.89 / 6.10 / 6.27) measured. Caveat: one size, one seed; the table, though flattered, conditions on few facts.
- The stream helps the map, once weighted (the control above). Caveat: one seed per run, differences 0.05–0.15 nats against a 0.03 spread.
- The stream alone learns where hidden enemies reappear. The stream-only model's LM probe at re-sightings, against the full vision-aware table: 3.78 vs 5.58 (32%) at 30–60 s, 3.99 vs 5.93 (33%) at 60–120 s, 4.04 vs 6.27 (36%) at 2–5 min; about 50 effective cells against 270 measured. By the rule declared before the check (more than 10% at 30–120 s), the stream-only claim stands. Caveats: the vision model is approximate (no sentries, summons or spell vision; tower positions standard); the probe is conditional on a sighting happening, so it says nothing about enemies who stay hidden; one size, one seed.
- Most of the heads' lead is in the facts, a little in the sequence. Joint heads vs the snapshot MLP vs Table2: 30–60 s 5.04 / 5.28 / 5.89, 60–120 s 5.37 / 5.51 / 6.10, 2–5 min 5.43 / 5.63 / 6.27 measured. The heads beat the snapshot by 4.5%, 2.5%, 3.6%: by the declared rule (between 2% and 5%), a small sequence effect; about 70–80% of the heads' gain over the table is reproduced by a snapshot of the same facts. Caveat: the snapshot sees the whole game and the GPT only 2,048 tokens, so the sequence effect may be understated.
- At least two layers are needed; beyond four, little (the depth sweep above). Caveat: width changes with depth; one seed; 16 layers still running.
- Width pays up to about 31M parameters, then stops. The width ladder, all 100k steps on the same 3.3B tokens, belief NLL at 30–60 s / 60–120 s and the LM probe at 30–60 s: 4 × 256 (7.3M) 4.97 / 5.30 / 3.93; 8 × 512 (31M) 4.76 / 5.13 / 3.37; 8 × 768 (65M) 4.73 / 5.09 / 3.30 measured. The first step gains 0.17–0.55 nats, the second 0.03–0.08: by the rule declared before the runs (each > 0.05), the 65M rung is not worth it. The map is now limited by the data or the objective; 31M stays the reference. Caveat: one seed per rung; the corpus is about to double, which may move the point where width stops paying.
- More data and more steps buy a little, evenly. The 31M model on the corpus with the 49,690 newest-patch games added (1.6× the documents) for 200k steps instead of 100k, scored on the same held-out moments: 4.72 / 5.08 / 3.33 against R1's 4.76 / 5.13 / 3.37 measured, about 0.04 in every bin. That is under the 0.05 declared as “pays”, close enough that the rule asks for a repeat seed. The constant-rate phase was flat from 75k to 175k steps, so the gain came with the final decay. With the width ladder this says the belief is near a plateau at this size and objective. Caveat: one seed; data and steps changed together.
- The modern block gains more than width or data did. RMSNorm, RoPE, QK-norm, SwiGLU and Muon on R1's configuration: 4.70 / 5.06 / 3.27 against R1's 4.76 / 5.13 / 3.37 (belief 30–60 s, 60–120 s, LM probe 30–60 s), every bin from 5 s to 5 min better by 0.05–0.07, 5 min+ flat measured. Caveat: one seed; block and optimiser not separated; 55% slower per step on the A100 as first run; with Muon batched and compiled, 14%.
- The world model knows a little more about the next minute than hand features. Small read-outs on the frozen model (never trained for these) beat a LightGBM on fog features at predicting a deadly fight in 10–25 s (AUC 0.675 vs 0.642), an own hero's death within a minute (0.687 vs 0.672), and an enemy reaching where a hero stands within 30 s (0.890 vs 0.875; 0.843 vs 0.814 when no enemy is in sight); the same network with random weights gets 0.57 / 0.55 / 0.73 measured. Its "this spot is safe" claims cover 27% of spots and are wrong 5% of the time. Long memory adds almost nothing here (≤ 0.003). Caveat: fights and deaths stay hard (≈ 0.68); probes, not trained heads (D-75).
- E3 (which missing information is worth tokens): inconclusive. A LightGBM given exactly what the stream drops (cooldowns, enemy teleports, wave detail, movement, damage, pings) predicted whether a fight starts, a death, spot safety and lane pushes better by only 0.002–0.004 AUC measured. A first reading ("the stream misses nothing") is withdrawn: the targets asked whether events happen, not how fights turn out; spells were merged into counts; waves were judged on a one-minute horizon; there was no positive control; and a one-moment LightGBM is not the world model. The redo measures with the world model itself (D-77).
- E3b (what the world model lacks): it uses what it has; the dropped facts add at most 0.002. On the newest 3,500 games, erasing a seen enemy cast lowers the frozen model's predicted fight-win chance by 1.6 points when that spell is still on cooldown and 0.16 when it is back; a planted cast raises it 1.2 points; moving a wave front changes tower and rotation predictions the way the game's rules say measured. Its predicted chance that an enemy casts its longest spell goes from 4% (certainly down) to 36% (just back) when the cast was seen, and stays flat when it wasn't. Exact cooldowns, enemy teleports and wave detail add at most +0.002 AUC on top of the model; even the true positions of hidden enemies add little (+0.003 on deaths, +0.012 for split pushers). That control was set at +0.02 and failed, so "nothing is missing" is not claimed (D-78).
- History beyond 3 minutes helps. The same model continued at 16,384 tokens against 2,048 for 20k steps, scored on the same moments: belief better in every bin, by 0.05 at 5–10 s rising to 0.14 at 2–5 min measured. Caveat: one seed; a continuation, not a model trained long from the start.
- Read position. The default belief does not know this step's sightings.
--read-nextis declared and running. Results pending.
05The ML-systems side
What one training step asks of the GPU, how much of the GPU it gets, and why. The method follows the course: count the work (chapter 6, neural networks as a workload), count the bytes (chapter 3, the memory hierarchy), put them on a roofline (chapter 4, the roofline), and only then guess at causes; confirming them is a job for a profiler (chapter 5, profiling).
What one training step does
- CPU, in numpy: pick 16 random documents and offsets, read 16 × 2,049 tokens from the memory-mapped corpus, mask the result tokens, find which steps get a head read, gather six truth arrays for them.
- Copy to the GPU: the token array, then for the heads 16 small index arrays and 6 target arrays, each a separate blocking copy from ordinary (pageable) memory.
- Forward: embedding lookups; 4 × (LayerNorm, qkv matmul, fused attention kernel, a transpose copy, proj matmul, add, LayerNorm, MLP up matmul, GELU, MLP down matmul, add); final LayerNorm; the LM head, a 32,768 × 256 by 256 × 3,780 matmul; the logits converted to fp32; cross-entropy. Then the belief heads on the gathered query rows.
- Backward: the same operations in reverse, each matmul twice (gradient for the input, gradient for the weight).
- Optimiser: unscale the gradients, check them for infinities (the CPU reads the answer back, so it waits for the GPU here), clip, AdamW update, update the scale.
FLOPs per token, derived from the shapes
A matrix multiply of an (n × k) by a (k × m) matrix costs n·k·m multiply-adds = 2·n·k·m FLOPs. Per token (n = 1), per layer, forward:
qkv 1 × d by d × 3d 2 · d · 3d = 6 d²
proj 1 × d by d × d 2 · d · d = 2 d²
MLP up 1 × d by d × 4d 2 · d · 4d = 8 d²
MLP down 1 × 4d by 4d × d 2 · 4d · d = 8 d²
linear layers = 24 d² (= 2 FLOPs per weight)
attention scores q·k for the j ≤ i earlier positions: 2 · i · d (summed over heads)
weighted sum of the values: 2 · i · d
average over i in a window of T, causal: i ≈ T/2 → 2 · T · d
(without the mask, every j: 4 · T · d)
LM head 1 × d by d × V 2 · d · V
heads only at query tokens: 2 heads × 2 · (d·1024 + 1024·1024) each
Training ≈ 3 × forward: the backward pass does two matmuls for each forward one (one for the gradient flowing to the input, one for the weight's gradient). With N = 12·d²·L + d·V (the weights that are multiplied for every token), that gives the familiar 6·N, plus attention: 6·L·T·d with the causal mask (the convention used for MFU in the PaLM paper counts 12·L·T·d, i.e. no saving from the mask).
The belief heads run only at query tokens. From the 4 × 256 report: 288,072 alive enemy-rows in 2,048 windows, so at least 288,072 / 2,048 / 5 ≈ 28 steps with a head read per window, ~141 query tokens estimate. That adds about 0.36M forward FLOPs per token on average, 1.1M for training.
| Term | Formula | 4 × 256 | 16 × 128 |
|---|---|---|---|
| Linear layers, 3 × 24·d²·L | 6 · 12d²L | 18.9M | 18.9M |
| LM head, 3 × 2·d·V | 6 · dV | 5.8M | 2.9M |
| Attention, causal | 6 · L·T·d | 12.6M | 25.2M |
| Belief heads (≈141 query tokens per window) | 1.1M | 1.0M | |
| Total, causal attention | 38.3M | 47.9M | |
| Total, PaLM convention (12·L·T·d) | 50.9M | 73.1M |
Two things the table teaches. First, the depth sweep held the linear-layer FLOPs constant (12·d²·L is the same 3.1M weights for 4 × 256 and 16 × 128), but attention grows with L·d, so the deep narrow model does about 25% more work per token. Second, at this context attention is not small: for 4 × 256 it is a third of the work, for 16 × 128 over half. The ratio of attention to linear work per layer is 4·T·d / 24·d² = T / 6d: 1.3 at d = 256, 2.7 at d = 128.
Per step: 16 windows × 2,048 tokens = 32,768 tokens. For 4 × 256: 38.3M × 32,768 ≈ 1.26 TFLOP per step (1.67 by the PaLM convention); 100,000 steps process 3.28 billion tokens.
Memory
- Weights and optimiser: 7.28M parameters × (4 bytes fp32 weight + 4 gradient + 8 for Adam's two averages) ≈ 116 MB derived. Small.
- Activations kept for the backward pass, per token per layer, roughly: block input (fp32, 4d bytes), LayerNorm outputs and their fp16 copies (2 × 6d), q, k, v (6d), attention output (2d), the residual after attention (4d), the MLP's widened output before and after GELU (2 × 8d): about 44·d bytes. For 4 × 256: 44 × 256 × 32,768 × 4 ≈ 1.5 GB; for 16 × 128: ≈ 3.0 GB estimate.
- The logits: 16 × 2,048 × 3,780 = 124M numbers, the largest single tensor in the step: 0.25 GB in fp16, 0.5 GB as the fp32 copy the loss uses, and the same again for its gradient. Roughly 1–1.5 GB at its peak, the same for every depth, because it depends on the vocabulary, not the width estimate.
- Attention scores are never stored. A full 2,048 × 2,048 score matrix per head would be 16 × 4 × 2,048² × 2 bytes ≈ 0.54 GB per layer; the fused kernel computes it in tiles that stay on-chip (chapter 3's point about keeping data in the fast level of the hierarchy) and keeps only one number per row for the backward pass.
Add the CUDA context and the allocator's cache and the estimate for 16 × 128 lands at 4.5–5 GB. Measured: 5.2 GB used of the A100's 80 GB during the 16-layer run measured. Memory is not the constraint: 94% of it is idle.
Arithmetic intensity and the roofline
Arithmetic intensity is FLOPs per byte moved between the GPU's memory (HBM) and its chips. For one of the block's matmuls, X (n × k) times W (k × m), all fp16 (2 bytes per number):
FLOPs = 2 · n · k · m bytes = 2 · (n·k + k·m + n·m) read X, read W, write Y AI = n·k·m / (n·k + k·m + n·m) with many rows (n = 32,768 ≫ k, m), the k·m term is negligible: AI ≈ k·m / (k + m) MLP up k = d, m = 4d : 4d² / 5d = 0.8·d MLP down k = 4d, m = d : 4d² / 5d = 0.8·d qkv k = d, m = 3d : 3d² / 4d = 0.75·d proj k = d, m = d : d² / 2d = 0.5·d
The intensity grows with the width d and not with the number of rows: a wider model does more work per byte. The A100's ridge point, where a kernel stops being limited by memory and starts being limited by compute, is peak compute over bandwidth: 312 TFLOP/s (fp16 dense, tensor cores) / ~2.0 TB/s (80 GB model) ≈ 155 FLOP/byte. Source: NVIDIA A100 Tensor Core GPU datasheet (312 TFLOPS FP16 tensor without sparsity; 2,039 GB/s for the 80 GB SXM, 1,935 GB/s for the 80 GB PCIe, so 153–161).
| Width d | MLP up/down | qkv | proj | LM head (m = 3,780) | Against the ridge |
|---|---|---|---|---|---|
| 128 (16 layers) | 102 | 96 | 64 | 123 | all below: memory-bound |
| 192 (8 layers) | 153 | 143 | 96 | 182 | at or just below |
| 256 (4 layers) | 204 | 191 | 128 | 238 | MLP and qkv just above; proj below |
| 384 (2 layers) | 304 | 285 | 191 | 345 | above |
| 512 (1 layer) | 405 | 380 | 254 | 445 | comfortably above |
Reading it: at d = 128, even a perfect kernel could reach at most ~100/155 ≈ 65% of peak on these matmuls; at d = 256 they sit near the ridge, where in practice kernels reach well under peak. And they are small: the MLP-up matmul for one step is 2 × 32,768 × 256 × 1,024 ≈ 17 GFLOP, about 55 µs at peak, which is the same order as the time to launch and schedule a few kernels.
The element-wise operations (LayerNorm, GELU, the residual adds, the fp16↔fp32 casts, the softmax over the logits) do a few FLOPs per number read: an intensity around 1 or below, far left on the roofline, so their time is set by bytes alone. One pass over a 32,768 × 256 fp32 activation is 33.5 MB, about 17 µs at 2 TB/s; one pass over the fp32 logits is 0.5 GB, about 0.25 ms, and the loss and its gradient make several such passes estimate.
Measured speed and MFU
| Model | Steps/s | ms per step | Wall time, 100k steps |
|---|---|---|---|
| 1 × 512 | 37.8 | 26.5 | 48 min |
| 2 × 384 | 35.1 | 28.5 | 51 min |
| 4 × 256 | 30.9 | 32.4 | 57 min |
| 8 × 192 | 22.7 | 44.1 | 77 min |
| 16 × 128 | 17.4 | 57.5 | 1.7 h |
Over the whole 4 × 256 run, evaluations and start-up included, the rate was 29.2 steps/s. On one Kaggle T4 the same model ran at 5.3 steps/s: the A100 is about 5.7× faster measured.
A straight line through the five step times gives about 24.7 ms + 2.1 ms per layer estimate. The fit is rough (width changes along the line), but its message is strong: about 25 ms of every step does not depend on the transformer's depth at all. That fixed part is everything outside the blocks: building the batch on the CPU, the copies, the LM head and its loss over 3,780 tokens, the belief heads, the optimiser, the synchronisations.
Model FLOPs utilisation (MFU) is the useful FLOPs per second divided by the hardware peak estimate:
4 × 256 : 38.3M FLOP/token × 32,768 tokens × 30.9 steps/s = 38.8 TFLOP/s → 38.8 / 312 = 12%
PaLM convention (50.9M FLOP/token) = 51.6 TFLOP/s → 17%
16 × 128: 47.9M FLOP/token × 32,768 tokens × 17.4 steps/s = 27.3 TFLOP/s → 9%
PaLM convention (73.1M FLOP/token) = 41.7 TFLOP/s → 13%
the crude 6 × (all 7.28M / 6.28M parameters), no attention term: 14% / 7%
So about 12–17% for 4 × 256 and 9–13% for 16 × 128, depending on how attention is counted. Another way to see the same thing: at peak, 4 × 256's 1.26 TFLOP per step would take 4 ms; it takes 32 ms. The crude count makes the 16-layer model look worse than it is, because at d = 128 attention is most of its work.
During the runs nvidia-smi showed about 77% GPU utilization measured. That number is the fraction of the sampling period during which at least one kernel was running on the GPU. It says nothing about how many of the 108 SMs that kernel used, or whether its tensor cores were busy or waiting on memory. A single tiny kernel on one SM counts as “utilized”. Read it the other way round: for about a quarter of the time no kernel was running at all, which is a strong hint that the GPU is waiting for the CPU.
What probably limits speed
These were the hypotheses before the benchmark (section 06 has what it found: the first was wrong, the second right). In the order we guessed their size:
- The CPU builds every batch while the GPU waits. The batch is assembled in numpy on the main thread (16 windows, truth lookups, Python loops). Several things in each step force the CPU to wait for the GPU: the blocking copies from pageable memory, and the GradScaler reading back whether any gradient overflowed. So CPU work and GPU work happen one after the other instead of overlapping, and step time is their sum, not their maximum. The ~25 ms of depth-independent time and the ~23% of time with no kernel running both point here.
- Many small kernels, each launched by Python. A step is several hundred kernel launches: per layer, LayerNorm, matmuls, attention, transposes, GELU, adds, casts, and twice as many in the backward; per window, small indexing operations for the heads; the optimiser over every parameter tensor. When kernels take tens of microseconds, the few microseconds of launch overhead each (chapter 2, the execution model) are no longer negligible. Nothing is compiled: no
torch.compileto fuse the element-wise operations, no CUDA graphs to launch the whole step at once. - Small, skinny matmuls near or below the ridge. At d = 256 the MLP matmuls are just above the ridge and proj below; at d = 128 everything is below. Even with no overhead these kernels cannot run at peak.
- Memory-bound element-wise work, especially around the 124M-number logits tensor: the fp32 conversion, the log-softmax, the gradient. Several passes of half a gigabyte each per step.
- Smaller things: the optimiser is PyTorch's default multi-tensor AdamW, not the single fused kernel; fp16 needs the scaler (and its read-back) where bf16 would not.
06Using the GPU better: the benchmark
Section 05 guessed at what limits speed. We then measured it: on one Colab A100, the real training step (real batches, the joint loss, AdamW, clipping) timed for 60 steps per configuration, one change at a time, then bigger models with all the changes, then several copies at once. Code: models/stream_bench.py. MFU here counts causal attention as half of full attention, against the 312 TFLOP/s peak measured.
| Configuration | Params | Steps/s | Tokens/s | MFU | GPU memory |
|---|---|---|---|---|---|
| 4 × 256, as trained so far (fp16 + scaler) | 7.3M | 30.6 | 1.00M | 12% | 3.2 GB |
| + background batch loader, pinned memory | 7.3M | 29.6 | 0.97M | 12% | 3.2 GB |
| + bf16, fused AdamW | 7.3M | 32.9 | 1.08M | 13% | 3.2 GB |
| + torch.compile | 7.3M | 42.1 | 1.38M | 17% | 3.2 GB |
| 6 × 384, everything on | 15.8M | 24.4 | 0.80M | 26% | 4.9 GB |
| 6 × 512 | 25.0M | 18.9 | 0.62M | 32% | 6.0 GB |
| 8 × 512 | 31.4M | 15.3 | 0.50M | 34% | 7.3 GB |
| 8 × 768 | 64.9M | 9.3 | 0.31M | 42% | 10.3 GB |
| 6 × 512 at batch 32 | 25.0M | 9.7 | 0.63M | 33% | 11.6 GB |
| 2 copies of 4 × 256, separate processes | 2 × 7.3M | 32.4 total | 1.06M | 13% | – |
| 4 copies | 4 × 7.3M | 32.6 total | 1.07M | 13% | – |
What each line teaches, in terms of the course's chapters:
- The CPU was not the bottleneck. Building batches on a background thread cut the time the training loop waited for its batch from 7% to 1% of the step, and the step did not get faster. Section 05's first guess was wrong: the batch was already mostly built while the GPU was still busy with the previous step's queued kernels.
- Kernel overhead was.
torch.compiletraces the transformer once and generates fused kernels: LayerNorm, GELU, the residual adds and the dtype casts become a few kernels instead of dozens, each reading and writing memory once instead of many times. Result: +37% (30.6 → 42.1 steps/s), with the same maths. The profiler trace of the uncompiled step showed why: the casts and copies took 13% of GPU time, LayerNorm's backward 11%, the matmuls (the useful part) only 17%. These are memory-bound kernels, far below the ridge (chapter 4): they move bytes and do almost no arithmetic. - bf16 and a fused optimiser: +7%. bf16 drops the GradScaler and its per-step synchronisation; fused AdamW updates every parameter in one kernel instead of a loop of small ones.
- Wider is nearly free, up to a point. 8 × 768 has 9× the parameters of 4 × 256 and takes 3.3× the time per step (107 ms vs 33 ms; 24 ms with compile). MFU climbs from 12–17% to 42%. This is the roofline (chapter 4) in action: a matmul of a 2,048 × d activation with a d × 4d weight does 2 × 2,048 × d × 4d FLOPs and, in bf16, moves 2 bytes × (2,048·d + 4d² + 2,048·4d) for its input, weight and output; its arithmetic intensity grows with d: about 190 FLOP/byte at d = 256, just above the A100's ridge (~155), and about 470 at d = 768, well above it derived, so the tensor cores, not the memory, set the pace, and the fixed per-step costs are spread over much more useful work.
- A bigger batch does not help at 6 × 512: twice the tokens per step, twice the time per step. The GPU is already saturated at batch 16 for that width; a bigger batch only helps when each step is too small to fill the GPU.
- Several models at once do not help either: two or four separate processes together reach 32.5 steps/s, about what one process does (+6%). Without NVIDIA's MPS, kernels from different processes do not run on the GPU at the same time; the GPU switches between their contexts in time slices. A process's short idle gaps between kernels cannot be filled by another's kernels. The ways that would work are MPS (one shared context), or putting the models into one process as one wider computation (stacked weights,
torch.func.vmap). The simplest way to use the spare GPU is the one above: train one wider model.
What we adopted: --fast in the trainer (bf16, fused AdamW, torch.compile of the transformer). Not adopted: the background loader, batch 32, concurrent processes. Memory stays a non-issue: 10 GB of 80 at 65M parameters.
Caveats: 60 timed steps per configuration after 15–25 warm-up steps (compile's warm-up includes the compilation); one run each; the two profiled configurations were re-run without the profiler, whose trace-writing had slowed them (11 and 16 steps/s); the MFU formula counts the transformer and LM head, not the belief heads.
07Changelog
Architecture and training changes to the D-67 model, newest first. Each future change gets an entry here and an update to the sections above.
- 15 Oct · The worst misses, read. Of the belief's errors on recently seen enemies, 61% come from heroes simply walking off in a direction the model could not know; teleports, Blinks and respawns are most of the very worst cases but only 6-8% of the error. The extra facts help in no case type. Browse them on Fog of War, "Worst misses".
- 15 Oct · E4 closed: the extra facts stay out. Training with the per-hero extras (visible creeps and more) neither improved the belief (0.016 nats worse) nor what the model knows about coming fights and deaths (probes within 0.002 AUC; 0.02 was needed). The next stream (v4) is v3 with small fixes.
- 2026-10-15Trainer: the profile's fixes (training profile page): the batch arrives as one prefetched copy instead of ~21 blocking ones, the vocabulary is padded to a multiple of 64 with the extra entries masked out (the loss is unchanged), the output layer and loss are compiled. Same results on CPU to the last digit. Timed on an A100: 33.2 → 60.5 steps per second (1.8×) with CUDA graphs on top; the one packed copy alone gave 1.4×.
- 2026-10-15E2: a live coach is viable (D-79): the model sees only what Dota's game-state feed sends and loses 0.04 nats against the full team view, well inside the 0.10 the plan allowed. E4: training with cooldowns, items and waves did not improve the model's guesses (+0.016, slightly worse); its second test, on fights and deaths, still has to run.
- 2026-10-14E3b (D-78; section 04): the world model tracks seen enemy cooldowns and wave fronts the way the game's rules say; the facts the stream drops add at most 0.002 AUC. Whether E4 (training with these tokens) still runs is Baro's call: proposed as a small free pair on Kaggle.
- 2026-10-14E3 inconclusive (D-77; section 04): a first reading, "the stream misses nothing", was withdrawn: wrong targets, merged features, no positive control, and LightGBM is not the world model. E4 is back on the plan.
- 2026-10-14Fights, deaths, safe spots (D-75, E1; section 04): read-outs on the frozen model beat the hand-feature yardstick on all three, by small margins; "this spot is safe" is usable now.
- 2026-10-14Long context pays (D-73; sections 02 and 04): 16,384 tokens beat 2,048 by 0.05–0.14, growing with time unseen. Long context becomes the direction.
- 2026-10-14Modern block adopted (D-72; sections 02 and 04): +0.06 to +0.11 over R1 at the same data and steps. Muon batched and compiled (section 03): the 56 matrices grouped into 3 stacks, one compiled Newton–Schulz call each; same updates. On an A100 this cuts the step by 27%: the bundle costs 14% over R1, not 55%.
- 2026-10-14Data lever (section 04): 1.6× the data and 2× the steps at 31M gain ~0.04 everywhere; repeat seed pending.
- 2026-10-14Modern block and Muon (
--arch modern --opt muon; sections 02 and 03): RMSNorm, RoPE, QK-norm, SwiGLU, no biases, scaled residual init; Muon on the block matrices. Long context (--init,--match-eval): continuing a model at 16,384 tokens, scored on the same moments as at 2,048. Both under test on Colab; results here when they land. - 2026-10-14Width ladder (7M, 31M, 65M; section 04): 31M becomes the reference model; 65M gains only about one seed's spread, so no wider rung.
- 2026-10-13
--fast(bf16, fused AdamW,torch.compile) after the GPU benchmark (section 06); weight decay no longer on biases and LayerNorm gains; the +30 s head masked by “alive 30 s later” instead of “alive now”; the query tokens get their own class in the loss report (they were counted with “recap”, where their near-zero loss made that class look easier). - 2026-10-13GPU benchmark on the A100: compile +37%, the batch loader nothing, wider models up to 42% MFU, concurrent processes +6%.
- 2026-10-13This page, describing the 4 × 256 joint model at belief weight 0.2.
- 2026-10-13Depth sweep on Colab A100 at fixed layer parameters: 1 × 512, 2 × 384, 4 × 256, 8 × 192, 16 × 128. At least two layers needed; little beyond four; 16 thin layers no better than 8. Next: wider, not deeper.
- 2026-10-13
--read-nextin training and evaluation: step s's belief read at step s + 1's query tokens, after all of step s. New metric: belief mass inside our heroes' vision. Comparison run pending. - 2026-10-13Joint heads at belief weight 0.2 become the default, after the control showed the stream helps the map and the cost to the stream was the weighting.
- 2026-10-13Stream v2 with query tokens: five
?foe:0–4tokens after every clock token; one belief map per query token instead of all five from the clock token; three fog leaks closed (enemy items as last seen, no enemy last hits, no jungle counts). Evaluation on fixed held-out windows, the stronger Table2 baseline, and the LM as its own probe. - 2026-10-12First model: stream v1, a 4 × 256 GPT with context 2,048, belief heads at each step's clock token, first as detached linear and MLP probes, then trained jointly.