Almost every component of a modern transformer has, over the past few years, traded fixed behavior for learned, input-dependent behavior. Sequence mixing went from fixed convolutions to attention. Feed-forward capacity went from one dense MLP to input-routed experts. Even normalization has acquired learned scales and placements. One component sat untouched through all of it: the residual connection. The update
has been copied verbatim from ResNet into essentially every LLM, and it still aggregates layer outputs with fixed unit weights.
The Kimi team’s Attention Residuals (AttnRes, arXiv:2603.15031) is the argument that this last fixed component should be made learned and content-dependent too — and that the right way to do it is softmax attention over the depth axis. The framing is a duality: residual connections are to depth what RNNs were to sequence, and AttnRes is the same RNN→Transformer move applied to depth instead of time. This post walks the math, the structured-matrix theory that unifies it with prior residual variants, the infrastructure that makes it survive pipeline parallelism, and the experiments — including a 48B-parameter MoE pretrained on 1.4T tokens.
Table of contents
Open Table of contents
- Why touch the residual connection at all?
- The duality of time and depth
- Full Attention Residuals
- Block Attention Residuals
- The structured-matrix view: linear vs. softmax attention over depth
- Infrastructure: making it survive pipeline parallelism
- Experiments
- Training dynamics: what actually changes
- When to use which
- Takeaways
Why touch the residual connection at all?
Two roles of the residual connection are worth separating.
The famous one is the gradient highway. Backpropagating through the residual recurrence gives
and expanding the product always leaves a bare term — a direct path from the loss to any layer, regardless of depth. This is what lets us train deep networks at all, and AttnRes does not want to lose it.
The less-discussed role is as a depth-wise aggregation rule. Unroll the recurrence and the hidden state entering layer is
i.e. the token embedding plus a uniformly weighted sum of every preceding layer output. Every layer receives the same flat average of everything below it. There is no mechanism to emphasize one earlier layer over another, and no way for an attention layer and an MLP layer to ask for different mixtures of the past.
Under PreNorm — the dominant placement in modern LLMs — this flat accumulation has a concrete pathology. Because each layer’s output is added (not normalized) into the stream, grows as with depth. The normalization sits before each sublayer, so each sees a unit-scale input but writes into an ever-larger residual. The relative contribution of any single layer therefore shrinks with depth — later layers must learn ever-larger outputs just to stay audible. This is PreNorm dilution, and it shows up empirically as the well-known result that you can prune a large fraction of an LLM’s middle layers with little loss: their contributions were being drowned out anyway.
The paper names three concrete limitations of single-state residuals (fixed or gated):
- No selective access. Different layer types (attention vs. MLP) get the same aggregated state, even when they would benefit from different weightings.
- Irreversible loss. Information blurred together by summation cannot be selectively recovered later.
- Output growth. Later layers inflate their outputs to gain influence over the accumulated residual, which destabilizes training.
These are exactly the symptoms RNNs had on the sequence axis before attention. Which is the whole idea.
The duality of time and depth
Lay the two recurrences side by side:
| Sequence axis (RNN) | Depth axis (Residual) | |
|---|---|---|
| State | ||
| Update | ||
| Bottleneck | one state compresses all past tokens | one state compresses all past layers |
| Fix | attention: selectively read all positions | AttnRes: selectively read all layers |
On the sequence side, the Transformer’s answer to RNN compression was to let each position attend over all previous positions with data-dependent weights. AttnRes proposes the identical move over depth:
where are learned, input-dependent attention weights. The crucial observation that makes this affordable: while sequence length reaches millions of tokens, network depth is modest — in any real model. So attention over depth, which would be unthinkable over a long sequence, is essentially free.
Full Attention Residuals
Write the weights as a normalized kernel . The choice of determines which residual variant you get (more on this in the structured-matrix section); AttnRes picks the exponential kernel with a normalized key, giving plain softmax attention over depth:
The queries, keys, and values are deliberately minimal:
so the input to layer is just .
Three design decisions deserve attention:
- The query is a bare learned vector , one per layer — a “pseudo-query.” There is no query projection of the current hidden state. This is the entire parameter cost of AttnRes: one -vector per layer plus one RMSNorm. It looks like a limitation but is the key to the infrastructure story below: because doesn’t depend on layer ‘s forward computation, the attention weights for a whole group of layers can be computed in parallel, without waiting for each layer’s output in sequence.
- Keys and values are the same thing — the raw layer outputs. No separate key/value projections.
- RMSNorm sits inside the kernel, on the keys. Without it, a layer that naturally produces large-magnitude outputs would dominate the softmax purely on scale. Normalizing the keys forces the selection to be about direction/content, not magnitude. The ablation confirms this matters (removing it costs ~0.006 loss in Full AttnRes, more in Block).
One more practical detail that the paper flags as essential: all pseudo-queries must be initialized to zero. Zero queries make every , so the initial attention is uniform — AttnRes starts life as exactly the equal-weight average, i.e. as a standard residual, and learns to deviate. Without this, early training is volatile.
What it costs
Per token, Full AttnRes needs arithmetic and memory to hold the layer outputs. The arithmetic is genuinely negligible because . The memory is the catch — but in vanilla training it’s free, because those layer outputs are already retained for backprop. So on a single device, Full AttnRes is nearly a free lunch.
The problem is scale. At scale you use activation recomputation (which would otherwise free and recompute those outputs) and pipeline parallelism (which splits layers across devices). Now every layer output must be (a) kept alive instead of recomputed, and (b) transmitted across stage boundaries. Both blow up to — and the cross-stage communication, not the arithmetic, is the real wall. This is what Block AttnRes is for.
Block Attention Residuals
The idea: don’t attend over all individual layer outputs. Partition the layers into blocks of layers, sum within a block to get one representation per block, and attend over only the block summaries (plus the embedding). Memory and communication drop from to .
Intra-block accumulation. Within block , layer outputs accumulate by ordinary summation:
So inside a block, you’re back to a standard residual; the learned attention only kicks in across block boundaries.
Inter-block attention. Set (the embedding is always an available source). For the -th layer in block , the value set is:
with the same kernel and normalization as Full AttnRes. So the first layer of a block sees the completed earlier blocks; subsequent layers additionally attend to the partial sum building up within the current block. The final output layer aggregates all block representations.
The block count is a clean interpolation knob:
- (one layer per block) recovers Full AttnRes exactly.
- reduces to a standard residual, with the embedding isolated as .
Empirically recovers most of the Full AttnRes benefit while storing only eight hidden states per token.
Here is the paper’s PyTorch-style sketch — note how block_attn_res is just a softmax over stacked block reps using the learned projection weight as the query, and how forward threads partial_block () and blocks () through one transformer layer:
def block_attn_res(blocks, partial_block, proj, norm):
# blocks: N tensors [B, T, D] (completed block reps, incl. token embedding)
# partial_block: [B, T, D] (intra-block partial sum b_n^i)
V = torch.stack(blocks + [partial_block]) # [N+1, B, T, D]
K = norm(V) # RMSNorm on keys
logits = torch.einsum('d, n b t d -> n b t', proj.weight.squeeze(), K)
h = torch.einsum('n b t, n b t d -> b t d', logits.softmax(0), V)
return h
def forward(self, blocks, hidden_states):
partial_block = hidden_states
# --- attention sublayer ---
h = block_attn_res(blocks, partial_block, self.attn_res_proj, self.attn_res_norm)
if self.layer_number % (self.block_size // 2) == 0: # block boundary
blocks.append(partial_block)
partial_block = None
attn_out = self.attn(self.attn_norm(h))
partial_block = attn_out if partial_block is None else partial_block + attn_out
# --- MLP sublayer ---
h = block_attn_res(blocks, partial_block, self.mlp_res_proj, self.mlp_res_norm)
mlp_out = self.mlp(self.mlp_norm(h))
partial_block = partial_block + mlp_out
return blocks, partial_block
The structured-matrix view: linear vs. softmax attention over depth
This is the theoretical heart of the paper, and the part that elevates AttnRes from “a trick” to “a unifying lens.” Define a depth mixing matrix where is the weight layer assigns to source , so that . Every residual variant ever proposed is some choice of , and they differ in how the entries arise (fixed / learned-static / input-dependent) and in the semiseparable rank of .
Standard residual. Unrolling gives for all : the all-ones lower-triangular matrix.
This is 1-semiseparable — the lowest-rank structure possible.
Highway. With (scalar) carry gates, defining the carry product , the weights are . Because everything factors through scalar gates, is still 1-semiseparable — same rank as the plain residual, just input-dependent. (The weights also sum to one, making Highway a softmax-free, depth-wise instance of stick-breaking attention.)
(m)HC / Hyper-Connections. Maintain parallel streams updated by a learned transition matrix . Unrolling yields
which is -semiseparable. The streams are exactly state expansion along the depth axis — the same trick that takes a recurrent state from to on the sequence side.
Full AttnRes. from a softmax over input-dependent keys, giving a dense, rank- .
Block AttnRes. Sources in a completed block share that block’s key/value, so they share a weight; the current block contributes one extra distinct source via its partial sum. The effective rank lands between and — exactly interpolating standard residual () and Full AttnRes ().
| Method | Mixing matrix | Weights | Rank |
|---|---|---|---|
| Standard residual | all-ones lower-triangular | fixed | 1-semiseparable |
| Highway | cumulative gate products | input-dependent | 1-semiseparable |
| (m)HC | streams, transition matrices | input-dependent | -semiseparable |
| Full AttnRes | dense softmax weights | input-dependent | rank- (full) |
| Block AttnRes | block-structured | input-dependent | between and |
The punchline is a clean reframing. Look at the (m)HC weight : is a query, is a key, and the cumulative transition is a depth-relative positional operator. That is precisely the linear attention form (a separable query–key product, accumulated by a recurrence). So:
Prior residual generalizations — Highway, Hyper-Connections, (m)HC — are all depth-wise linear attention. AttnRes is depth-wise softmax attention. The progression over depth (residual → gated recurrence → softmax attention) is the same progression that played out over sequence (RNN → linear attention → Transformer).
The structured-matrix view also pays off diagnostically: the input-dependent exposes depth-wise attention sinks — specific layers that consistently attract weight regardless of input, mirroring the token-level attention-sink phenomenon. And whenever the kernel factorizes as , depth-wise attention collapses back into a recurrence — which is exactly why the linear-attention residual variants exist as special cases.
Infrastructure: making it survive pipeline parallelism
A clever residual that can’t be trained at scale is a footnote. The infra section is where Block AttnRes earns “drop-in replacement.”
Training: cross-stage caching
Under an interleaved pipeline schedule with physical stages and virtual stages, Block AttnRes needs all accumulated block reps at each stage to do inter-block attention. The naive approach re-sends the entire block history at every stage transition. With chunks, chunk carries blocks, so the naive per-token communication is
The fix is cross-stage caching: each physical stage processes multiple virtual stages in succession, so blocks it received earlier are still in local memory and need not be re-transmitted. Only the incremental blocks since the receiver’s previous chunk cross the wire:
This cuts the peak per-transition cost from to — a improvement — which is enough to fully overlap with compute in steady-state 1F1B. The backward pass benefits identically. Because activation checkpointing erases all the inter-block attention intermediates and the checkpointed input matches the size of the hidden state it replaces, per-layer activation memory is unchanged from a standard architecture. Measured end-to-end training overhead under pipeline parallelism: < 4% (and negligible without pipeline parallelism).
Inference: the two-phase strategy
Layer-wise AttnRes at decode time looks just like autoregressive decoding, with block reps playing the role of a KV cache reused across layers. A naive implementation re-reads all preceding blocks at every layer: memory accesses. The two-phase strategy exploits the fact that the pseudo-queries are decoupled from the forward pass, so all queries in a block can be batched:
- Phase 1 — parallel inter-block attention. Batch all block-layer queries into a single matmul against the cached block reps, returning outputs and softmax statistics (max, log-sum-exp). This amortizes the read cost from passes to one.
- Phase 2 — sequential intra-block attention. For each layer, attend over the evolving partial sum, then merge with the Phase-1 result via online softmax. The merge is elementwise, so it fuses cleanly with surrounding ops (e.g. RMSNorm).
The merge is the standard streaming-softmax combination, exact (not an approximation):
The per-layer memory-access accounting (the metric that actually governs decode latency, which is bandwidth-bound) is where the design pays off:
| Mechanism | Per-layer total I/O (symbolic) | Typical () |
|---|---|---|
| Standard residual | ||
| mHC ( streams) | ||
| Full AttnRes (two-phase) | ||
| Block AttnRes (two-phase) |
Block AttnRes lands at — within a small constant of the standard residual’s , and 6× cheaper than mHC’s despite delivering comparable quality. End-to-end inference latency overhead: < 2%.
Memory-efficient prefilling
Storing block reps during prefill costs — about 15 GB for a 128K-token sequence with 8 blocks. Sharding the reps along the sequence dimension across tensor-parallel devices lets Phase 1 run on local shards, with the Phase-2 online-softmax merge folded into the existing TP all-reduce path (reduce-scatter → local merge → all-gather). That drops per-device footprint to — ~1.9 GB per device, and < 0.3 GB with 16K chunked prefill.
Experiments
The architecture is Kimi Linear unchanged — a MoE transformer interleaving Kimi Delta Attention (KDA) and MLA layers 3:1, each followed by an MoE FFN — with AttnRes added to the residual connections and nothing else touched.
Scaling laws
Five model sizes (194M–528M activated params), three variants each (PreNorm baseline, Full AttnRes, Block AttnRes with ), identical hyperparameters chosen under the baseline (a deliberately conservative setup that favors the baseline).
| Activated params | Baseline | Block AttnRes () | Full AttnRes | mHC(-lite) |
|---|---|---|---|---|
| 194M | 1.931 | 1.909 | 1.899 | 1.906 |
| 241M | 1.895 | 1.875 | 1.874 | 1.869 |
| 296M | 1.829 | 1.809 | 1.804 | 1.807 |
| 436M | 1.766 | 1.746 | 1.737 | 1.747 |
| 528M | 1.719 | 1.693 | 1.692 | 1.694 |
Fitted power laws (C in PFLOP/s-days):
- Baseline:
- Block AttnRes:
- Full AttnRes:
The slopes are nearly identical; AttnRes just sits on a lower intercept across the whole compute range. At 5.6 PFLOP/s-days, Block AttnRes reaches 1.692 vs. the baseline’s 1.714 — equivalent to a compute advantage. The Full-vs-Block gap narrows with scale, down to 0.001 at 528M. And Block AttnRes matches mHC’s quality at a fraction of the per-layer I/O ( vs. ).
Downstream: a 48B MoE on 1.4T tokens
The headline model is the full Kimi Linear 48B config — 27 transformer blocks (54 layers), 8-of-256 routed experts plus 1 shared, 48B total / 3B activated — with Block AttnRes at 6 layers/block (9 blocks + embedding = 10 depth sources). Trained on 1.4T tokens (1T WSD pretraining + ~400B mid-training anneal), then extended to 32K context. Because MLA layers here run NoPE, context extension needed no YaRN or temperature rescaling.
Block AttnRes matches or beats the baseline on all 15 benchmarks:
| Baseline | AttnRes | Δ | |
|---|---|---|---|
| MMLU | 73.5 | 74.6 | +1.1 |
| MMLU-Pro | 52.2 | 52.2 | — |
| GPQA-Diamond | 36.9 | 44.4 | +7.5 |
| BBH | 76.3 | 78.0 | +1.7 |
| ARC-Challenge | 64.6 | 65.7 | +1.1 |
| HellaSwag | 83.2 | 83.4 | +0.2 |
| TriviaQA | 69.9 | 71.8 | +1.9 |
| GSM8K | 81.7 | 82.4 | +0.7 |
| MGSM | 64.9 | 66.1 | +1.2 |
| Math | 53.5 | 57.1 | +3.6 |
| CMath | 84.7 | 85.1 | +0.4 |
| HumanEval | 59.1 | 62.2 | +3.1 |
| MBPP | 72.0 | 73.9 | +1.9 |
| CMMLU | 82.0 | 82.9 | +0.9 |
| C-Eval | 79.6 | 82.5 | +2.9 |
The gains concentrate on multi-step reasoning and code (GPQA +7.5, Math +3.6, HumanEval +3.1) — consistent with the hypothesis that better depth-wise information flow most helps compositional tasks, where deep layers want to selectively retrieve and build on specific earlier representations rather than a blurred average.
Ablations (436M model)
| Variant | Val loss |
|---|---|
| Baseline (PreNorm) | 1.766 |
| DenseFormer (fixed, input-independent scalars) | 1.767 |
| Sliding-window over depth ( recent layers + embedding) | 1.764 |
| mHC ( streams, learned mixing) | 1.747 |
| Block AttnRes () | 1.746 |
| Full AttnRes | 1.737 |
| Full AttnRes + input-dependent query | 1.731 (adds a projection) |
Several of these are pointed:
- DenseFormer ≈ baseline (1.767). Giving every layer access to all earlier outputs but with fixed, input-independent weights buys nothing. The input-dependence is the active ingredient, not the cross-layer access alone.
- Sliding-window over depth (1.764) ≫ Full AttnRes (1.737). Restricting attention to the 8 nearest layers beats the baseline only slightly. So selectively reaching distant layers matters far more than attending to many nearby ones — the opposite of a locality prior.
- Block size sweep. all cluster near 1.746; degrade toward baseline. Hence the default. As hardware loosens memory limits, finer blocks (toward Full AttnRes) are the natural upgrade path.
- Softmax > sigmoid (1.741). The competitive normalization of softmax forces sharper selection. Depth-wise multihead hurts (1.752 vs 1.746) — the optimal mixture is largely uniform across channels: when a layer’s output is relevant, it’s relevant as a whole. Input-independent mixing hurts (1.749), removing RMSNorm hurts (1.743/1.750).
Where AttnRes wants to spend capacity
A 25-config sweep at fixed compute and active params (varying and ) finds AttnRes beats the baseline in all 25 cells (by 0.019–0.063), and — more interesting — shifts the optimum toward deeper, narrower models: the baseline’s best is at , AttnRes’s at . AttnRes can exploit additional depth more effectively, which is exactly what you’d predict from a mechanism that improves depth-wise information flow. (The paper is careful: this is a diagnostic, not a deployment recommendation, since deeper models cost more sequential latency at inference.)
Training dynamics: what actually changes
Comparing baseline vs. Block AttnRes on the 48B run over 1T tokens makes the mechanism legible:
- Validation loss is consistently lower, and the gap widens during the LR decay phase — AttnRes converts the annealing into more gain.
- Output magnitude. The baseline shows textbook PreNorm dilution: hidden-state magnitude grows monotonically with depth, forcing deep layers to emit ever-larger outputs. Block AttnRes confines that growth within a block — selective re-aggregation at each block boundary resets the accumulation, producing a bounded, periodic magnitude profile instead of a monotone ramp.
- Gradient magnitude. With all residual weights pinned to 1, the baseline has no way to regulate gradient flow and dumps disproportionately large gradients into the earliest layers. AttnRes’s learned softmax weights make sources compete for probability mass, which spreads gradients far more uniformly across depth.
And the learned weight patterns are interpretable: strong diagonal (locality is preserved — each layer still leans on its immediate predecessor), but with clear off-diagonal concentrations (learned skip connections to specific distant layers), persistent non-trivial weight on the embedding throughout, and a layer-type split — pre-attention layers keep broad receptive fields while pre-MLP layers rely more sharply on recent representations. All of this structure transfers intact from Full to Block AttnRes, which is why block compression behaves like a regularizer rather than a lobotomy.
When to use which
| Full AttnRes | Block AttnRes | |
|---|---|---|
| Best for | maximum quality; smaller models; future fast interconnects | practical large-scale training and serving today |
| Quality | slightly better (gap → 0.001 at 528M) | recovers most of Full’s gains at |
| Training overhead | cross-stage comm — impractical at scale now | < 4% under pipeline parallelism |
| Inference I/O | /layer | /layer (vs. standard, for mHC) |
| Inference latency | practical but higher | < 2% |
The honest summary: Block AttnRes with ~8 blocks is the recommended production variant, and Full AttnRes is the theoretical ceiling that better interconnect hardware will eventually make practical. The two are the same mechanism at different points on the interpolation.
Takeaways
- The residual connection was the last fixed-weight aggregator in the transformer, and it didn’t have to be. AttnRes makes depth-wise mixing learned and input-dependent with astonishingly little machinery — one -vector and one RMSNorm per layer.
- The time–depth duality is more than an analogy; it’s a generative principle. It predicts the whole family: prior residual variants are depth-wise linear attention, AttnRes is depth-wise softmax attention, and the structured-matrix rank () tracks the move exactly. It also predicts new designs — linear-complexity depth attention is the obvious next step the paper flags.
- The contribution is as much systems as it is modeling. Cross-stage caching, the two-phase online-softmax inference schedule, and sequence-sharded prefilling are what turn a idea into a / drop-in. Without them, Full AttnRes is a single-GPU curiosity.
- The wins are exactly where you’d hope. Multi-step reasoning and code — the compositional tasks where a deep layer genuinely wants to retrieve a specific earlier representation rather than a flat average — improve most. PreNorm dilution is mitigated visibly in the magnitude and gradient profiles, not just in the loss number.
If you’ve been reading the recent attention literature, the satisfying thing about this paper is that it closes a symmetry. We spent a decade making the sequence axis learned and content-aware while leaving the depth axis on the fixed recurrence it inherited from 2015. AttnRes is the argument that depth deserves the same treatment — and that, because depth is small, it’s nearly free to give.
References
- Kimi Team (Moonshot AI). Attention Residuals. arXiv:2603.15031, 2026. (code)
- Zhang, Y. et al. Kimi Linear: An Expressive, Efficient Attention Architecture. arXiv:2510.xxxxx, 2025.
- He, K. et al. Deep Residual Learning for Image Recognition. arXiv:1512.03385, 2015.
- Xiong, R. et al. On Layer Normalization in the Transformer Architecture. arXiv:2002.04745, 2020.
- Srivastava, R., Greff, K., Schmidhuber, J. Highway Networks. arXiv:1505.00387, 2015.
- Zhu, D. et al. Hyper-Connections. arXiv:2409.19606, 2024.
- Pagliardini, M. et al. DenseFormer: Enhancing Information Flow in Transformers via Depth-Weighted Averaging. arXiv:2402.02622, 2024.
- Sun, Y. et al. Learning to (Learn at Test Time): RNNs with Expressive Hidden States. arXiv:2407.04620, 2024.
- Dao, T., Gu, A. Transformers are SSMs: Generalized Models and Efficient Algorithms Through Structured State Space Duality (Mamba-2). arXiv:2405.21060, 2024.
- Milakov, M., Gimelshein, N. Online normalizer calculation for softmax. arXiv:1805.02867, 2018.