Attention Residuals

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.

Compare a sum with a learned mix

6

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

One Running Total for Every Layer

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.

Add layers to the running total

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.

8

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.

The road

  1. The residual stream is a plain sum: unroll it and see every weight is 1.
  2. PreNorm growth: why the total grows and drowns each layer.
  3. Attention over depth: replace the sum with a weighted mix.
  4. How a layer scores its sources: the learned query, RMSNorm and softmax.
  5. The design choices: what the ablations say about each part.
  6. Block AttnRes: attend over block summaries to save memory.
  7. The cost: memory, reads per layer and latency.
  8. The gains: scaling laws and benchmarks.
  9. Inkling 2 Mini: attention residuals inside a looped model.
  10. The field guide: terms, numbers, code, links.
In a plain 48-layer residual stream where every output has the same size, what share of layer 49's input comes from the embedding?

Chapter 1

The Residual Stream Is a Plain Sum

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.

Say it aloud

h-l equals h-1 plus the sum, over i from 1 to l minus 1, of f-i of h-i.

hl
h-l the input to layer l: one vector of d numbers per token.
h1
h-1 the token embedding, the input to the first layer.
Σi=1l−1
the sum over i from 1 to l minus 1 add one term for each layer below l.
fi(hi)
f-i of h-i the output of layer i, computed from that layer's own input.
In plain words

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 numbers

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.

Unroll the stream, one layer at a time

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.

3

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.

With h-1 = (1, 0), f-1 = (0.5, 0.5) and f-2 = (−0.2, 0.8), what is h-3?

Chapter 2

PreNorm Growth Dilutes Each Layer

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.

Say it aloud

The RMS of h-l is about the square root of l, times u.

rms(hl)
rms of h-l the typical size of the stream entering layer l.
√l
root l the square root of the number of terms in the sum.
u
u the typical size of one layer's output, the same for every layer here.
In plain words

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 numbers

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".

Find how loud a late layer must be

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.

40

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.

Under PreNorm, why do later layers in a deep baseline learn larger outputs?

Chapter 3

Attention Over Depth

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 α.

Say it aloud

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.

hl
h-l the input to layer l, now a weighted mix.
Σi=0l−1
the sum over i from 0 to l minus 1 one term for the embedding and one for each earlier layer.
αi→l
alpha i-to-l how much layer l takes from source i, between 0 and 1.
vi
v-i source i: the embedding for i = 0, else the output of layer i.
Σ α = 1
the alphas sum to one the weights share one unit, so raising one lowers the others.
In plain words

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 numbers

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.

Steer the mix with a query

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.

20°
1.6

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.

Why does the input to a layer stop growing with depth under AttnRes?

Chapter 4

How a Layer Scores Its Sources

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.

Say it aloud

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.

αi→l
alpha i-to-l the weight layer l puts on source i.
exp( )
e to the turns any score into a positive number; a score 1 higher means about 2.7 times the weight.
wl⊤
w-l transpose the pseudo-query of layer l: d learned numbers, the same for every token.
RMSNorm(vi)
RMS-norm of v-i source i scaled to typical size 1, so its size cannot buy weight. This is the key.
Σj exp(…)
the sum over j the same score for every source, added up, so the weights sum to 1.
In plain words

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 numbers

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.

Make one source loud

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.

4×

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.

Three sources score 2, 1 and 0. About what weight does the first source get?

Chapter 5

The Design Choices, Tested One by One

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.

Compare the variants

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.

  1. The weights must depend on the input. DenseFormer reads all earlier outputs with fixed learned scalars. It scores 1.767, no better than the baseline. Fixed scalars inside AttnRes score 1.749.
  2. Softmax beats sigmoid, 1.737 against 1.741. Softmax makes sources compete for one unit of weight, which the paper says forces sharper choices.
  3. Far sources matter. A window over the last 8 outputs plus the embedding scores 1.764. Reaching any earlier layer scores 1.737.
  4. One mix per layer is enough. Splitting the mix into 16 heads hurts, 1.752 against 1.746 for the block version. When an output is useful, it is useful as a whole.

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.

DenseFormer lets every layer read every earlier output, yet scores no better than the baseline. What does that suggest?

Chapter 6

Block AttnRes: Attend Over Block Summaries

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.

Say it aloud

b-n equals the sum, over the layers j in block n, of f-j of h-j.

bn
b-n the summary of block n: one vector of d numbers per token. b-0 is the embedding.
Σj ∈ Bn
the sum over j in B-n add one term for each of the S layers in block n.
fj(hj)
f-j of h-j the output of layer j.
In plain words

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.

With numbers

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.

Group 54 layers into blocks

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.

6
21

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.

A 54-layer model uses blocks of 6 layers. How many sources can a layer choose among at most?

Chapter 7

What It Costs in Memory and Time

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).

SchemeReads and writes per layerWhat it does
Standard residual3dRead h and f(h), write the sum
mHC, 4 streams34dMix four parallel streams with learned matrices
Full AttnRes24dAttend over all 128 layers, in batches of 16
Block AttnRes5.5dAttend 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.

Say it aloud

M equals N times T times d times the bytes per number, divided by P.

M
M memory for the block summaries on one device, in bytes.
N
N the number of blocks; 8 in the paper's example.
T
T the number of tokens held at once.
d
d the hidden size: numbers per token per summary.
bytes
bytes the size of one number; 2 for 16-bit.
P
P the number of devices that share the tokens.
In plain words

Each of the T tokens keeps N summaries of d numbers. Multiply by the bytes per number. Split the tokens over P devices.

With numbers

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.

Fit the summaries of a long prompt

Bars show the memory for the summaries, on a log scale. Grow the prompt, add devices, and switch chunked prefill on.

128K
8

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.

Why can all layers of a block score the finished block summaries in one batch?

Chapter 8

What the Paper Measured

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 paramsBaselineBlock AttnResFull AttnRes
194M1.9311.9091.899
296M1.8291.8091.804
528M1.7191.6931.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.

Read the 48B benchmark table

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.

What does "Block AttnRes matches a baseline trained with 1.25× more compute" mean?

Chapter 9

Inkling 2 Mini: Attention Residuals With Loops

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:

  1. Every pass starts with the prelude's output.
  2. Passes 2 and 3 also read the middle blocks' outputs from the previous pass. Thinking Machines calls that the message.

Step through the passes

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.

0.60

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".

Why does Inkling 2 Mini's message gate block the whole message at the start of training?

Chapter 10

The Field Guide

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.

The terms

TermMeaning
Residual streamThe running sum of the embedding and every layer's output.
PreNormNormalize the input of each layer, not the stream.
DilutionEach layer's share of the stream falls as depth grows.
SourceAn earlier output a layer can attend to; the embedding is source 0.
Pseudo-queryOne learned d-vector per layer that scores the sources; starts at zero.
Block summaryThe sum of a block's layer outputs, b-n.
Partial sumThe sum of the outputs so far inside the current block.
Two-phase computationBatch the scores against finished blocks, then merge each layer's partial sum by online softmax.
MessageIn Inkling 2 Mini, the middle blocks' outputs from the previous pass.

The numbers

WhatNumberSource
Compute advantage1.25× (1.692 vs 1.714 at 5.6 PFLOP/s-days)Paper, Section 5.1
Ablation lossesBaseline 1.766, Full 1.737, Block 1.746Paper, Table 4
48B model blocks54 layers, 6 per block, 10 sourcesPaper, Section 5.2
GPQA-Diamond36.9 to 44.4Paper, Table 3
Reads per layer3d standard, 5.5d Block, 24d Full, 34d mHCPaper, Table 1
OverheadUnder 4% training with pipelines; under 2% inference latencyPaper, Section 4
Prefill memory, 128K15 GB; 1.9 GB per device; under 0.3 GB chunkedPaper, Section 4.2
Inkling 2 Mini loops24 layers, 48 applications, 3 passesInkling 2 Mini post
Inkling 2 Mini size26.4B total, 3.4B active, 5.4B per token; 1M contextPost and model card

The checklist

  1. Initialize every pseudo-query to zero.
  2. Put an RMSNorm on the keys, never on the values.
  3. Keep the embedding as source 0 for every layer.
  4. Start with about 8 blocks; sweep the block size if memory allows.
  5. Log the mean weights per layer and the RMS of each block's output.
  6. Under pipeline parallelism, cache block summaries on each stage.

The core as code

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.

Keep going

The takeaway. The residual stream is a fixed vote with weight 1 for every layer. Attention Residuals turn it into a learned vote over depth that sums to 1. Start the vote even, normalize the keys, and vote over block summaries to keep it cheap.
Which two settings make AttnRes start training as a plain average of its sources?

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.

Credit and source

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.

Attention Residuals
Read the paper · Inkling 2 Mini · Back to Gleams