Paper: arxiv.org/abs/2603.15031
Repo: MoonshotAI/Attention-Residuals
Standard transformers with PreNorm do this at every layer:
x = x + block(LN(x))
The residual stream is the sum of every block’s output, with every layer contributing at a fixed weight of one. That single design choice causes two well-known problems:
AttnRes replaces this fixed accumulation with a learned, input-dependent softmax over previous layer outputs.
Figure from the paper: (a) standard residuals add everything with weight 1.
(b) Full AttnRes lets each layer attend over all previous outputs.
(c) Block AttnRes groups layers into blocks to cut memory from \(O(Ld)\) to \(O(Nd)\).
Each layer \(l\) aggregates earlier layer outputs \(\mathbf{v}_i\) with weights \(\alpha_{i \to l}\) computed via a single learned pseudo-query \(\mathbf{w}_l \in \mathbb{R}^d\) per layer. Same shape as standard residuals, but the unit weights become a learned softmax.
Full AttnRes needs to keep every layer’s output around, which is \(O(Ld)\) memory. Block AttnRes splits the \(L\) layers into \(N\) blocks (~8 in the paper), accumulates inside each block with normal residuals, and only does the softmax over block-level reps. Most of the gain, a fraction of the memory.
This is the PyTorch-style pseudocode straight from the repo:
def block_attn_res(
blocks: list[Tensor],
partial_block: Tensor,
proj: Linear,
norm: RMSNorm,
) -> Tensor:
"""Inter-block attention: attend over completed block reps + partial sum."""
V = torch.stack(blocks + [partial_block]) # [N+1, B, T, D]
K = norm(V)
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
Three things to notice:
proj is a Linear(d, 1) whose weight vector is the per-layer pseudo-query.K = norm(V) normalizes the keys (the previous outputs) so the attention
scores aren’t dominated by whichever block happens to have the biggest norm.And here is how it slots into the transformer forward pass:
def forward(self, blocks, hidden_states):
partial_block = hidden_states
# Read: aggregate previous block reps before attention
h = block_attn_res(blocks, partial_block, self.attn_res_proj, self.attn_res_norm)
# Block boundary bookkeeping
if self.layer_number % (self.block_size // 2) == 0:
blocks.append(partial_block)
partial_block = None
attn_out = self.attn(self.attn_norm(h))
partial_block = partial_block + attn_out if partial_block is not None else attn_out
# Read again before the MLP
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 attention and MLP still operate on a single tensor h. What changes is
how h is constructed. Instead of x = x + block_out, the layer first
queries the list of previous blocks for the mixture it wants, then runs the
block.
Scaling laws. AttnRes beats the baseline across every compute budget the authors test. Block AttnRes matches the baseline trained with 1.25x more compute.

Downstream benchmarks (Kimi Linear 48B / 3B-activated, 1.4T tokens):
| Category | Benchmark | Baseline | AttnRes |
|---|---|---|---|
| General | MMLU | 73.5 | 74.6 |
| GPQA-Diamond | 36.9 | 44.4 | |
| BBH | 76.3 | 78.0 | |
| Math & Code | Math | 53.5 | 57.1 |
| HumanEval | 59.1 | 62.2 | |
| MBPP | 72.0 | 73.9 | |
| Chinese | C-Eval | 79.6 | 82.5 |
The biggest gains show up on multi-step reasoning (+7.5 on GPQA-Diamond) and code generation (+3.1 on HumanEval), which is what you’d expect if the win is “later layers can selectively re-read earlier representations”.
Training dynamics. The growth and gradient-norm pathology of PreNorm gets visibly tamer:

Output magnitudes stay bounded across depth, and gradient norms distribute much more uniformly across layers.
It is the same move as going from RNNs to attention, just applied along the depth axis instead of the sequence axis. The original residual was a hard-coded uniform recurrence over layers. AttnRes turns it into learned, content-dependent attention over layers. The residual stream stops being a single accumulating vector and becomes something more like a short history that each layer can query.
Anywhere a transformer hard-codes a uniform combination, there is probably a learned attention waiting to replace it.