A plain residual stream adds every layer's output with weight 1, so at layer 50 the embedding is 1 part in 50. Attention Residuals let each layer learn its own mix of earlier outputs, and matched a baseline trained with 1.25× more compute.
Switch between Plain sum and Learned mix. Then drag Reading block and watch how that block splits its attention over the blocks below it. Then we build it piece by piece: the sum, the growth problem, the softmax over depth, the block version, the cost, and the loops of Inkling 2 Mini.
You need a rough idea of a transformer layer (see the Transformer lesson) and a little Python. We build the rest from zero.
Based on Attention Residuals by the Kimi Team (2026) and on Thinking Machines' Inkling 2 Mini post and model card (2026-11-20). The explanations, toys and devices are our own.
Illustrative toy: 7 blocks plus the embedding, and an output row. We made up the learned weights to show the shapes of the paper's Figure 8: most weight on the block just below, steady weight on the embedding, a few long skips. They are not measured values.
Chapter 0
See why a deep layer cannot find a feature that an early layer wrote
Layer 2 of a 48-layer model spots that the word "bank" sits next to "river". Layer 40 needs that fact to answer a question. How does layer 40 get it?
In a standard transformer, each layer adds its output to one shared vector, the residual stream. Layer 40 does not see layer 2's output on its own. It sees one running total of the embedding and 39 layer outputs, all added with weight 1.
The bar is the input to the next layer, split by who wrote it. Warm is the embedding. Drag the depth and watch the early parts thin out.
Illustrative: every output has the same size here, so each part is 1 over the number of parts. In a real PreNorm model later layers write larger outputs, which shrinks early parts further (Chapter 2).
At depth 8, the embedding is 1 part in 9 of the total. At depth 48 it is 1 part in 49, about 2%. The paper calls this dilution: each layer's share of the stream falls as the stack grows. No layer can turn up one earlier output and turn down the rest.
The paper notes a strange fact that fits this picture. Earlier work found that a large fraction of layers can be pruned from trained models with little loss.
Attention Residuals (AttnRes), from the Kimi Team, replace the fixed sum. Each layer learns weights over all earlier outputs, with a softmax, so the weights add up to 1. A layer can give 60% to one early output and nearly 0 to others.
Chapter 1
Unroll the residual update and find a weight of 1 on every earlier output
A residual connection adds a layer's output to its input instead of replacing it. In this lesson a layer is one attention step or one MLP step, as in the paper. So a transformer block holds two layers.
Call the vector that enters layer l hl. It has d numbers for each token. Call what layer l computes fl. The embedding is h1. Each layer does one thing: take h, compute f(h), add it back.
h-l equals h-1 plus the sum, over i from 1 to l minus 1, of f-i of h-i.
Start with the embedding h-1. Add the output f-i of every layer below l, each with weight 1. The total is h-l.
With made-up 2-number vectors: h-1 = (1, 0), f-1 = (0.5, 0.5), f-2 = (−0.2, 0.8). Then h-3 = (1 + 0.5 − 0.2, 0 + 0.5 + 0.8) = (1.3, 1.3). Neither output got more weight than the other.
The equation comes from the one-step update hl = hl−1 + fl−1(hl−1), applied again and again. Step through it below with arrows in two dimensions.
Warm is the embedding. Each grey arrow is one layer's output. Blue is the stream: the sum. Press Add a layer, or drag the layer.
Illustrative 2-number vectors. A real stream has d numbers per token (for example d = 1,264 in the paper's largest scaling run, Table 2), but the sum works the same way.
Why keep the sum at all? It gives a clean path for gradients. The gradient of the loss reaches every layer through the identity term, so deep stacks train. AttnRes keeps that path. It changes only how the inputs are mixed.
The failure: a layer needs one specific earlier output and gets the whole total. To measure it, compare how much each output contributes to h-l. With weight 1 on everything, the share is fixed by size alone. The fix is to let the weights change, which is Chapter 3.
The shapes: a batch of B sequences of T tokens gives h of shape B × T × d. Each layer reads one such tensor and writes one. The sum costs one addition per layer.
Chapter 2
Find out why the stream grows with depth, and why late layers must shout to be heard
Most modern models use PreNorm: each layer normalizes its input before it computes, f(norm(h)). The layer always sees an input of the same size. Its own weights set its output size, not the size of the stream.
The stream itself is never normalized. So it grows. How fast? Say every layer writes an output with typical size u. Call that size the RMS, the root of the mean of the squared numbers.
The RMS of h-l is about the square root of l, times u.
If the l outputs point in unrelated directions, their sizes add like the sides of a right triangle. The total grows with root l. If they point the same way, the total grows with l itself, the O(L) growth the paper names.
With u = 1 and l = 49: unrelated outputs give rms about 7; aligned outputs give 49. A new output of size 1 moves the stream by about 1 in 7, or 1 in 49.
Now a late layer wants to change the stream as much as an early layer did. It must write a bigger output. The paper finds exactly that: in its baseline, later layers learn larger and larger outputs. The paper says this "can destabilize training".
Blue is the stream size. Warm is the output a layer must write to move the stream by 10%. Pick how the outputs line up, then drag the layer.
Illustrative model with unit outputs. The real growth sits between the two cases. The paper's Figure 5b shows the baseline's block outputs rising with depth.
The failure has two symptoms in the paper. Output size climbs with depth (Figure 5b). Gradients pile up in the earliest layers, because every weight is fixed at 1 and nothing balances them (Figure 5c). Measure both by logging the RMS of each layer's output and gradient. The fix is a mix whose weights add to 1, so the input stays bounded.
Older fixes kept the sum. Highway networks add a learned gate between the input and the new output. They still read one compressed state, hl−1. A layer cannot reach back to one output that the sum already blended.
Chapter 3
Replace the fixed sum with weights that add to 1, chosen by each layer
The paper starts from a likeness. A recurrent network squeezes all earlier tokens into one state. Attention fixed that over time: each token reads every earlier token with its own weights. The residual stream squeezes all earlier layers into one state. So use attention over depth.
Give each earlier output a name. The sources for layer l are v0 = h1 (the embedding) and vi = fi(hi) for every layer i below l. Give each source a weight α.
h-l equals the sum over i from 0 to l minus 1 of alpha i-to-l times v-i, and the alphas add up to 1.
Layer l gives each source v-i a weight alpha. The weights add to 1. It multiplies each source by its weight and adds them up to get h-l.
With the vectors from Chapter 1 and weights 0.6, 0.1, 0.3 on h-1, f-1, f-2: h-3 = 0.6 × (1, 0) + 0.1 × (0.5, 0.5) + 0.3 × (−0.2, 0.8) = (0.59, 0.29). The embedding now carries 60%, not one equal third.
Two things change. The weights depend on the input, so each token can pick a different mix. And the weights add to 1, so the input stays the size of a typical source. It no longer grows with depth.
Each source is an arrow. The teal arrow is the mix the layer reads. Turn the query to favour a direction. Set strength 0 to see the starting point.
Illustrative 2-number sources. The scoring rule is the paper's (Chapter 4): a learned query dotted with each RMS-normalized source, then a softmax.
At strength 0 every weight is 1 over 5: the mix is the average of the sources. The paper starts every layer there. The failure to watch: a mix that collapses to one source on every token. Measure it by plotting the mean weights per layer, as the paper's Figure 8 does. Its trained models keep most weight on the layer just below, plus steady weight on the embedding.
Chapter 4
Compute the weights from one learned vector per layer, a norm and a softmax
Attention needs a query and keys. Over tokens, both come from the data. AttnRes picks something cheaper. The pseudo-query wl is a learned vector of d numbers, one per layer. It does not depend on the token. The keys are the sources themselves, after an RMSNorm.
Alpha i-to-l equals e to the power w-l dot RMSNorm of v-i, divided by the sum over j of the same thing for every source j.
Normalize each source v-i. Dot it with the layer's query w-l to get a score. Raise e to each score. Divide each by the total. That gives alpha.
With made-up scores 2, 1 and 0 for three sources: e to those is 7.39, 2.72 and 1.00, total 11.11. So alpha = 0.665, 0.245 and 0.090. One point of score gave 2.7 times the weight.
The values are the sources without the norm: hl = Σ αi→l vi. Only the score sees the normalized copy. Why the norm? Without it, a source with a big output gets a big dot product and takes the softmax, whatever the query says.
Bars are the weights of four sources for one fixed query. Turn up the size of the last source. Switch the norm off and watch it take the softmax.
Illustrative scores. In the paper's ablation, removing RMSNorm raised the loss of Full AttnRes from 1.737 to 1.743, and of Block AttnRes from 1.746 to 1.750 (Table 4).
The failure is a dominated softmax: one big source wins every layer. Measure the RMS of each source next to its weight. If the weight tracks size, the keys need a norm. The paper adds one RMSNorm and one query vector per layer. That is a few thousand numbers per layer in a model with billions.
Chapter 5
Read the ablation table and see what each part of AttnRes buys
Every part of the scoring rule is a choice. The paper tests each one on the same 16-layer model with the same budget (Table 4). Lower validation loss is better. The baseline, a PreNorm residual stream, scores 1.766.
Each bar is one variant's loss. Shorter is better. Tap a variant to read what it changed.
All numbers are from the paper's Table 4 (16-layer model, identical hyperparameters and compute). The bar axis starts at 1.72 to make the gaps visible.
Four lessons come out of the table.
An input-dependent query scores best, 1.731. The paper still uses the fixed query. A projected query costs a d × d matrix per layer, and it must wait for the layer's input. A fixed query is known in advance, so a whole block of layers can score its sources in one batch (Chapter 7).
One more choice is not in the table: zero initialization. Every pseudo-query starts at zero. Then every score is 0 and every weight is equal, so training starts from a plain average. The paper says this "prevents training volatility".
The failure: a random start for w-l. Some layers then begin with sharp, arbitrary mixes, and the paper reports unstable training. Measure it by logging the entropy of the weights in the first steps. The fix is zeros.
Chapter 6
Group layers into blocks, sum inside a block, and attend across blocks
Full AttnRes must keep every layer's output alive until the last layer. That is L vectors of d numbers per token. At scale, with pipeline parallelism, each of them must also travel between GPUs. Block AttnRes keeps N summaries instead of L outputs.
Split the L layers into N blocks of S = L / N layers. Inside a block, use the plain sum. Across blocks, use attention.
b-n equals the sum, over the layers j in block n, of f-j of h-j.
Add up the outputs of the S layers in block n. That one vector b-n stands for the whole block. Later layers attend over the summaries, not the layers.
The paper's 48B model has L = 54 layers and S = 6 layers per block. That gives N = 54 ÷ 6 = 9 blocks. With the embedding b-0, every layer chooses among at most 10 sources, not 54.
What does the third layer of block 4 read? The summaries b0 to b3, plus the partial sum of block 4 so far: the outputs of its first two layers. The first layer of a block reads only the finished summaries. Try it.
Each cell is a layer. Purple bands are blocks. Pick a block size and a layer; the lit cells are the sources that layer reads.
L = 54 and S = 6 are the paper's 48B model (Section 5.2). Block sizes are the divisors of 54. The paper also allows a short last block when L is not divisible by N.
The block size is a dial between two known designs. S = 1 is Full AttnRes. S = L leaves one block, which is the standard residual with the embedding kept apart. On the 16-layer ablation model, S = 1 scores 1.737 and S = 4 scores 1.746. Block sizes 2, 4 and 8 all land near 1.746; sizes 16 and 32 drift back toward the 1.766 baseline (Figure 6). The paper fixes N at about 8.
The failure: blocks so large that each summary blends too much, the same problem as the plain sum. Measure it by sweeping S and plotting loss, as Figure 6 does. RMSNorm matters more here, since a summary of 6 layers is bigger than a partial sum of 1.
Chapter 7
Count the stored vectors, the reads per layer and the measured overheads
Depth is small next to sequence length. A sequence can hold a million tokens; a model rarely has more than a few hundred layers. So attention over depth costs little arithmetic: O(L²d) per token for the full version. Memory and data movement are the real costs.
In plain training the layer outputs already sit in memory for the backward pass, so Full AttnRes adds no memory. Large runs recompute activations and split layers over GPUs. Then every output must be kept, and sent across stages: O(Ld). Blocks cut both to O(Nd).
| Scheme | Reads and writes per layer | What it does |
|---|---|---|
| Standard residual | 3d | Read h and f(h), write the sum |
| mHC, 4 streams | 34d | Mix four parallel streams with learned matrices |
| Full AttnRes | 24d | Attend over all 128 layers, in batches of 16 |
| Block AttnRes | 5.5d | Attend over 8 block summaries |
The table is the paper's Table 1 with L = 128, N = 8, S = 16. The trick behind the low numbers is the two-phase computation. The queries are fixed vectors, so all S layers of a block can score the finished summaries in one batched pass (phase 1). Each layer then adds its own partial sum and merges the two with an online softmax (phase 2).
Inference has one more cost. While the model reads a long prompt, it must store N summaries for every token.
M equals N times T times d times the bytes per number, divided by P.
Each of the T tokens keeps N summaries of d numbers. Multiply by the bytes per number. Split the tokens over P devices.
N = 8, T = 131,072 (128K), d = 7,168, 2 bytes: 8 × 131,072 × 7,168 × 2 = 15.0 GB. Over P = 8 devices it is 1.9 GB each. The paper gives 15 GB and 1.9 GB; d = 7,168 is our assumption that reproduces them.
Bars show the memory for the summaries, on a log scale. Grow the prompt, add devices, and switch chunked prefill on.
N = 8 and the anchors (15 GB at 128K, about 1.9 GB per device, under 0.3 GB with 16K chunks) are the paper's (Section 4.2). The paper does not state d; we use 7,168 at 2 bytes because it reproduces those figures. Other lengths are our extrapolation.
The measured overheads: negligible training time without pipeline parallelism, under 4% with it, and under 2% inference latency on typical workloads. A cache on each GPU sends only new block summaries between pipeline stages, not the full history. The failure: a naive pipeline that resends every summary at every stage, cost growing with the square of the chunk count. Measure the bytes per stage transition.
Chapter 8
Read the scaling laws, the 48B benchmark table and the training dynamics
The paper trains five model sizes, each three ways: the PreNorm baseline, Full AttnRes, and Block AttnRes with about 8 blocks. All three share the baseline's hyperparameters, which favours the baseline. The paper fits loss against compute C, in PFLOP/s-days.
| Active params | Baseline | Block AttnRes | Full AttnRes |
|---|---|---|---|
| 194M | 1.931 | 1.909 | 1.899 |
| 296M | 1.829 | 1.809 | 1.804 |
| 528M | 1.719 | 1.693 | 1.692 |
The fits are 1.891 × C−0.057 for the baseline and 1.870 × C−0.058 for Block AttnRes. At 5.6 PFLOP/s-days, Block reaches 1.692 and the baseline 1.714. The baseline would need 1.25× the compute to match. At the largest size, Block trails Full by only 0.001.
Then the big run. The paper adds Block AttnRes to Kimi Linear, a mixture-of-experts model with 48B total and 3B active parameters. Nothing else changes. Both versions train on the same 1.4T-token recipe.
Blue is the baseline, teal is AttnRes. Pick a group of benchmarks.
All scores are from the paper's Table 3, after the same pre-training recipe. Single runs: the paper does not report error bars.
AttnRes matches or beats the baseline on every benchmark. The biggest gains are on multi-step reasoning: GPQA-Diamond rises from 36.9 to 44.4 (+7.5), Math from 53.5 to 57.1 (+3.6), HumanEval from 59.1 to 62.2 (+3.1). The paper reads this as later layers reusing earlier ones.
The training dynamics match Chapter 2. In the baseline, block output size climbs with depth. With Block AttnRes it stays bounded, in a repeating pattern that resets at each block boundary. The gradients spread more evenly across depth (Figure 5).
One more finding changes design. Under a fixed budget, the best baseline shape has dmodel / Lb = 60 (loss 1.847). With AttnRes the best moves to 45 (loss 1.802): a deeper, narrower model. AttnRes was better in all 25 shapes tried, by 0.019 to 0.063.
The failure to guard against when you read this: a single run per benchmark, with no error bars. A gain of 0.2 on HellaSwag may be noise. Trust the pattern across many tasks and the scaling fit more than any one row.
Chapter 9
Follow what each looped pass reads, and why a gate starts closed
Inkling 2 Mini, from Thinking Machines, is a looped transformer: it runs some layers more than once for each token, with the same weights. It has 24 layers in four blocks of six. The first block, the prelude, runs once. Blocks 2 and 3 run three times. Block 4 runs once.
That gives 6 + 3 × 12 + 6 = 48 layer applications per token from 24 stored layers. The model has 26.4B total and 3.4B active parameters. Each extra pass adds about 1.0B effective active parameters, so three passes give 5.4B per token. The looped transformers lesson covers loops in general.
Thinking Machines says, "Our model uses attention residuals." Each layer reads the outputs of the earlier blocks and learns its own mix of them. With a loop, "earlier blocks" includes the previous pass. Two rules shape what each pass reads:
Warm arrows carry the prelude's output. Pink arrows carry the message from the previous pass, scaled by the gate. Pick a pass, then move the gate as training goes on.
The block layout, pass count, message and gate behaviour are from the Inkling 2 Mini post. The gate here is a toy scalar: the exact gate formula is not disclosed.
A learned gate merges the message with the prelude's output. It also scales the outputs of the earlier layers in the block. At the start of training the gate blocks the entire message. So each pass first behaves like a model without loops, and the gain on the message grows during training. This is the same idea as the zero-initialized query: start from a safe, known model, then let training open the new path.
Why loop the middle? Thinking Machines reasons that middle layers carry the abstract work. Looping layers 7 to 18 gave a 1.51 to 1.91× compute-equivalent gain at step 2,000; looping layers 13 to 24 gave 1.24 to 1.36×. A non-looped model cost 7.5% less to train but needed 140% more inference compute to match the looped model's loss on 512k-token agentic traces.
The failure: open the message gate at full strength from step 0. The pass then starts from an untrained mix of its own outputs. Thinking Machines does not report that run. Its gate starts closed "to introduce looping during training in a stable manner".
Chapter 10
Keep the terms, the numbers, a checklist and the core code on one page
A plain residual stream adds every output with weight 1, so it grows and each layer's share shrinks. AttnRes gives each layer a softmax over earlier outputs, scored by one zero-initialized query and an RMSNorm on the keys. Block AttnRes sums inside blocks of about 8 and attends across them, for a few percent of overhead. Inkling 2 Mini uses attention residuals across loops, with a gated message between passes.
| Term | Meaning |
|---|---|
| Residual stream | The running sum of the embedding and every layer's output. |
| PreNorm | Normalize the input of each layer, not the stream. |
| Dilution | Each layer's share of the stream falls as depth grows. |
| Source | An earlier output a layer can attend to; the embedding is source 0. |
| Pseudo-query | One learned d-vector per layer that scores the sources; starts at zero. |
| Block summary | The sum of a block's layer outputs, b-n. |
| Partial sum | The sum of the outputs so far inside the current block. |
| Two-phase computation | Batch the scores against finished blocks, then merge each layer's partial sum by online softmax. |
| Message | In Inkling 2 Mini, the middle blocks' outputs from the previous pass. |
| What | Number | Source |
|---|---|---|
| Compute advantage | 1.25× (1.692 vs 1.714 at 5.6 PFLOP/s-days) | Paper, Section 5.1 |
| Ablation losses | Baseline 1.766, Full 1.737, Block 1.746 | Paper, Table 4 |
| 48B model blocks | 54 layers, 6 per block, 10 sources | Paper, Section 5.2 |
| GPQA-Diamond | 36.9 to 44.4 | Paper, Table 3 |
| Reads per layer | 3d standard, 5.5d Block, 24d Full, 34d mHC | Paper, Table 1 |
| Overhead | Under 4% training with pipelines; under 2% inference latency | Paper, Section 4 |
| Prefill memory, 128K | 15 GB; 1.9 GB per device; under 0.3 GB chunked | Paper, Section 4.2 |
| Inkling 2 Mini loops | 24 layers, 48 applications, 3 passes | Inkling 2 Mini post |
| Inkling 2 Mini size | 26.4B total, 3.4B active, 5.4B per token; 1M context | Post and model card |
pythonimport torch import torch.nn as nn class DepthAttn(nn.Module): # one per layer (attention or MLP) def __init__(self, d): super().__init__() self.w = nn.Parameter(torch.zeros(d)) # pseudo-query, zero init: uniform weights self.norm = nn.RMSNorm(d) # normalizes keys only def forward(self, sources): # list of [B, T, d]: b_0..b_{n-1}, partial sum V = torch.stack(sources) # [n, B, T, d] scores = torch.einsum('d,nbtd->nbt', self.w, self.norm(V)) alpha = scores.softmax(dim=0) # weights over depth sum to 1 return torch.einsum('nbt,nbtd->btd', alpha, V) # [B, T, d] def block_forward(layers, mixers, emb, S): # layers: callables f_l, S: layers per block blocks, partial = [emb], None for l, (f, mix) in enumerate(zip(layers, mixers)): h = mix(blocks + ([partial] if partial is not None else [])) out = f(h) # f applies its own PreNorm inside partial = out if partial is None else partial + out if (l + 1) % S == 0: # block boundary: freeze the summary blocks.append(partial); partial = None return blocks # the output layer attends over these
This follows the paper's Figure 2 pseudocode, simplified: one mixer per layer, no two-phase batching.
Now press Present or Teach and explain from memory why the plain sum dilutes, how the softmax over depth fixes it, and what blocks and loops add. Then go back to the hero and say why the learned mix keeps its input one unit in size.
This lesson re-teaches Attention Residuals by the Kimi Team (Guangyu Chen and 35 co-authors, 2026), with code at MoonshotAI/Attention-Residuals. The Inkling 2 Mini facts come from the Thinking Machines release post and model card. Toys and devices are our own.