Introduction
The decoder of this task is a fixed mixture-of-experts transformer whose layers are of two kinds. Most layers attend over a sliding window with rotary positions; a few layers, spread through the depth, attend over the whole causal context without positional encoding. The few full-attention layers are what lets the model use text beyond the window, and they are also where the training compute of attention and the decoding state grow with the context: every one of them keeps keys and values for every past token and compares each query with all of them.
The question asks which way of reusing computation across layers reaches a given held-out loss with the least training compute, or keeps the smallest decoding state, without losing held-out and long-document quality. The weights, data, optimizer and feed-forward sublayers are fixed; only how the blocks are called and what they share may change. The field offers several answers. Keys and values can be shared between adjacent layers [1] or fused for the top layers from a bottom and a middle layer [2]; a single global cache can serve a whole cross-decoder [3]; tokens can skip blocks [4]; the residual stream can be re-mixed across depth [5, 6]; or every layer can keep only a window [7]. Most of these either remove long-range attention from layers that needed it, which costs long-document quality, or change how much is computed only a little; block skipping saves much compute but costs held-out loss.
Our observation is that a full-attention read does two things at once. It retrieves from far away, and it mixes in the nearby context. The far retrieval is the expensive part, and we expected it to be largely redundant from one full-attention layer to the next; the near mixing is cheap and depends on the layer. The method below separates the two.
Method
Depth-factored attention
Let the decoder have layers, and let be the indices of its full-attention layers. We call the first of them, , the producer, and the later ones, , the reused layers. Every other layer, and the producer itself, runs exactly as in the decoder.
At the producer we compute the decoder's own full attention, with its query and key normalisation, scale and exclusive self-attention, and keep its per-head output, flattened over heads, as a global memory
where is the number of query heads and the head dimension. is taken before the producer's output step, so it is the attention read itself rather than the producer's update to the residual stream.
At a reused layer , with the normalised input to attention, we replace the full attention by the sum of two terms,
and then apply the layer's feed-forward sublayer unchanged. The first term is a fresh local read: softmax attention over the last positions only, with the layer's own keys and values and rotary positions, as the decoder's windowed layers compute it. Its window is a quarter of the decoder's sliding window,
The second term is a gated read of the shared memory: the layer's own query projection , passed through a SiLU, gates each coordinate of , and the layer's own output projection maps the result back to the residual stream. Both projections are weights the decoder already has, so the method adds no parameters. Keys and values stay per layer.
def __init__(self, cfg, backbone):
super().__init__()
self.backbone = backbone
self.L = cfg.num_layers
self.window = cfg.sliding_window
self.lw = max(64, cfg.sliding_window // 4)
self.full = [i for i in range(self.L) if cfg.is_long_layer(i)]
self.producer = self.full[0]
self.gmu = set(self.full[1:]) def hidden(self, tokens, seq):
bb = self.backbone
x = R.embed(bb, tokens)
mem = None
for i, blk in enumerate(bb.blocks):
attn = blk.attn
a = R.attn_in(blk, x)
B, S, _ = a.shape
q = (a @ R.cdt(attn.w_q)).view(B, S, attn.n, attn.h)
k = (a @ R.cdt(attn.w_k)).view(B, S, attn.m, attn.h)
v = (a @ R.cdt(attn.w_v)).view(B, S, attn.m, attn.h)
if i in self.gmu:
q, k = R.qk_finish(attn, q, k, rope=True)
yloc = R.attend(attn, q, k, v, seq, window=self.lw)
x = x + R.attn_out(attn, yloc, v, a)
x = x + (mem * F.silu(a @ R.cdt(attn.w_q))) @ R.cdt(attn.w_o)
else:
q, k = R.qk_finish(attn, q, k)
y = R.attend(attn, q, k, v, seq)
if i == self.producer:
mem = y.reshape(B, S, attn.n * attn.h)
x = x + R.attn_out(attn, y, v, a)
x, _ = R.mlp_half(blk, x)
return xThe shape of the gated read follows the gated memory units of a hybrid decoder in this task's baselines, which read a memory computed earlier in place of recomputing attention. What we add is the fresh local read beside it, and that addition is what made the reuse work for us (Section 4).
What is saved, and where
The reused layers no longer compare each query with the whole context: their attention cost becomes that of a window of size , and the producer's long-range read is paid once. During decoding a reused layer keeps keys and values for positions only, while the producer keeps its full cache and the windowed layers their windows, as before. Everything else is unchanged: the number of feed-forward calls, the token count and the learning rate, for which we keep the default (the file defines no learning-rate hook).
def decode_init(self, batch, max_len, device):
bb = self.backbone
st = {}
for i in range(self.L):
slots = self.lw if i in self.gmu else bb.blocks[i].attn.window
st[i] = R.KVCache(bb.blocks[i].attn, batch, max_len, device, slots=slots)
return st def decode_step(self, tok, pos, seg_start, state):
bb = self.backbone
x = R.embed(bb, tok[:, None])
mem = None
for i, blk in enumerate(bb.blocks):
attn = blk.attn
a = R.attn_in(blk, x)
B = a.shape[0]
q = (a @ R.cdt(attn.w_q)).view(B, 1, attn.n, attn.h)
k = (a @ R.cdt(attn.w_k)).view(B, 1, attn.m, attn.h)
v = (a @ R.cdt(attn.w_v)).view(B, 1, attn.m, attn.h)
q, k = R.rms_norm_np(q), R.rms_norm_np(k)
rope = (not attn.nope) if i not in self.gmu else True
if rope:
q, k = R.rope_at(q, pos, attn.theta), R.rope_at(k, pos, attn.theta)
q = q * attn.qk_mult
kc = state[i]
kc.write(pos, k[:, 0], v[:, 0])
win = self.lw if i in self.gmu else "layer"
y = R.attend_step(attn, q, kc, pos, seg_start, window=win)
if i == self.producer:
mem = y.reshape(B, 1, attn.n * attn.h)
x = x + R.attn_out(attn, y, v, a)
if i in self.gmu:
x = x + (mem * F.silu(a @ R.cdt(attn.w_q))) @ R.cdt(attn.w_o)
x, _ = R.mlp_half(blk, x)
return x[:, 0], stateA decoder with a single full-attention layer has no reused layers, and there the method computes exactly what the starter computes.
Results
| Method | ① | ||||||
|---|---|---|---|---|---|---|---|
| Paloma loss, small model ↓ | Paloma loss, medium model ↓ | Paloma loss, large model ↓ | far-copy loss, medium model ↓ | training PFLOPs, small model ↓ | training PFLOPs, medium model ↓ | training PFLOPs, large model ↓ | |
| Qwen4-Max | 3.891 | 3.564 | 3.225 | 0.804 | 43.86 | 223.2 | 1,845 |
| Attention Residuals | 3.861 | 3.538 | 3.195 | 0.890 | 43.63 | 231.4 | 1,853 |
| Cross-Layer Attention | 3.943 | 3.595 | 3.255 | 2.697 | 41.84 | 222.0 | 1,821 |
| FusedKV | 3.938 | 3.578 | 3.237 | 1.684 | 43.22 | 220.4 | 1,824 |
| Hyper-Connections | 3.853 | 3.551 | 3.205 | 0.759 | 43.47 | 229.3 | 1,850 |
| mHC | 3.866 | 3.533 | 3.200 | 0.950 | 45.07 | 234.4 | 1,852 |
| Mixture-of-Depths | 4.099 | 3.749 | 3.344 | 0.988 | 25.17 | 134.1 | 1,062 |
| Standard MoE decoder | 3.893 | 3.569 | 3.230 | 1.001 | 43.11 | 225.6 | 1,830 |
| ResFormer | 3.890 | 3.562 | 3.222 | 0.843 | 43.34 | 225.5 | 1,841 |
| SambaY | 3.934 | 3.598 | 3.257 | 1.257 | 44.01 | 225.0 | 1,902 |
| SVFormer | 3.976 | 3.663 | 3.337 | 0.940 | 43.33 | 222.7 | 1,806 |
| Sliding-window attention | 3.878 | 3.572 | 3.238 | 3.314 | 42.75 | 221.9 | 1,819 |
| YOCO | 3.937 | 3.597 | 3.256 | 1.195 | 43.68 | 232.1 | 1,952 |
| YOCO, SWA self-decoder | 3.921 | 3.587 | 3.235 | 1.267 | 45.19 | 226.6 | 1,867 |
- ① Grug MoE scaling ladder of three sizes, 330M / 747M / 2.04B parameters trained on 0.66B / 1.44B / 4.42B tokens · the curve of held-out loss against measured training compute over the ladder, and, at the 747M size, the decoding state kept after an 8,192-token context, credited only while long-document quality holds
The held-out loss is slightly below the starter's for all three model sizes: 3.891 against 3.893 for the small model, 3.564 against 3.569 for the medium model and 3.225 against 3.230 for the large one. These are small differences. The methods that re-mix the residual stream across depth reach lower loss on every model size, and the strongest baseline on each is clearly ahead of us, for example Attn. residuals [5] at 3.195 for the large model; ResFormer is also slightly ahead of us on all three.
The clearest effect is on the medium model's far-copy loss: 0.804 against the starter's 1.001. Only Hyper-Connections is lower, at 0.759. The methods that drop or share long-range keys and values pay heavily on this measure (sliding windows everywhere reach 3.314, cross-layer key and value sharing 2.697), while replacing all but one full-attention read by a local read and a gated memory read did not cost far-copy quality here and improved it.
Training compute is where the method did not deliver what it was designed for. Relative to the starter it is lower only for the medium model, and higher for the small and the large model (see the table). The method was meant to reduce compute, and on the published setting it leaves compute roughly where the starter has it. The reduction it does make is small compared with the share of compute in the parts we do not touch: the feed-forward sublayers, the projections and the windowed layers. Mixture-of-Depths, which skips blocks for most tokens, is the only baseline far below the starter on compute, and it pays for that in loss.
How we got here
We began by running the published baselines through our own short training harness at one width (the two hyper-connection variants did not fit in our development memory there), measuring held-out loss, a loss on tokens beyond the sliding window in long documents as a proxy for long-range recall, counted training compute and decoding-state bytes. In those development runs value reuse across depth (SVFormer, ResFormer) lowered early loss, sliding windows everywhere matched the starter's loss but not its long-range loss, block skipping saved much compute at a large loss cost, and the gated memory units of the hybrid decoder baseline lost quality. Key and value projections are a small share of compute in this decoder, so sharing them saves mostly decoding state.
- Reusing the memory without a local read lost quality. Our first candidate shared the first layer's values across all layers and let the later full-attention layers read only the producer's memory through the gate. Adding the fresh local read beside the gated read improved our development held-out loss by about 0.05, and that variant beat both the starter and the strongest baseline in our short runs, SVFormer, on all four of our development measures at that point. A later probe in the trained model explains why the local read matters: the reused layer's update was dominated by the local read (update norm 177.5 against 21.4 for the gated memory read, by the agent's measurement).
- Pairing every layer with its predecessor removed full attention altogether and was discarded before evaluation; sharing keys between layer pairs on top of shared values was worse than not sharing them.
- Sharing the first layer's values helped early and hurt later. This was the decisive finding. At 500 development steps the shared-value variant was well ahead of the starter, but the gap reversed with training: our development held-out loss was 0.027 above the starter's after 1900 steps and 0.071 above it after 5000. The same method with per-layer values was level with the starter early and slightly ahead after 5000 steps (3.0370 against 3.0406 in the agent's development run), with a lower long-range loss. We dropped value sharing and kept per-layer keys and values; the decoding-state saving then comes from the reused layers' short caches alone.
- Shrinking the decoder's own windowed layers looked free and was not. Reducing their window improved every development measure monotonically at 500 steps, but after 1900 steps it raised the long-range loss above the starter's, so we left those layers as the decoder has them.
- Reusing the feed-forward output at the reused layers, instead of computing it, saved compute and lost both loss and long-range quality. A probe of a trained starter model agreed: feed-forward updates of adjacent layers were nearly orthogonal (cosine 0.12 to 0.25 in the agent's measurement), and so were the raw attention outputs of two full-attention layers (cosine 0.078), which is consistent with reading the memory through a gate rather than copying it.
- The local window. A sweep at 500 steps put at or near the best; at 5000 steps a window of 64 positions raised our development long-range loss by 0.535 for a compute saving of a few percent, and a window of 128 fell steadily behind during training.
- Which layer produces the memory. In a deeper decoder with more full-attention layers, taking the second-to-last full-attention layer as the producer gave about the same development quality as the first, with a larger cache, so we kept the first.
A second seed at our main development width moved the held-out and long-range differences to within noise of the starter, while the compute saving of six to seven percent on the decoder layers and the roughly thirty percent decoding-state saving held. We took from this that the robust gains are in compute and state, with quality preserved rather than improved. We noted local and global attention schemes in the literature as related, but they are not in this task's references, and we do not cite them.
Limitations
- The compute saving did not reach the published setting. Training compute is higher than the starter's for the small and the large model, and only slightly lower for the medium one. The saving the design targets, full attention over the whole context in the reused layers, is a small part of the total compute of this decoder; most of it is in the feed-forward sublayers, which we run on every token.
- The reused layers compute their query projection twice. In
hiddenand indecode_step, the product is computed once for the local attention and again for the gate, which is avoidable compute in exactly the layers the method is meant to make cheaper. - Where there is nothing to reuse, nothing changes. In a decoder with one full-attention layer the method is the starter. Its effect therefore depends on how many full-attention layers a width has.
- Loss gains are small. On held-out loss we are slightly ahead of the starter and behind the methods that re-mix the residual stream across depth on every model size. Our own second seed showed differences of this size to be within noise in development.
- Decoding state is a design property here, not a published measurement. The published means do not include decoding-state bytes or long-document loss for this run; the state saving we report comes from our development measurements and from the cache sizes in the code.
- The local read changes a full-attention layer into a windowed one. It uses rotary positions, as the decoder's windowed layers do, where the full-attention layer it replaces used none. That is within the decoder's conventions, but the layer's weights now serve a different read than in the starter.
- The widest decoder was validated only for correctness. Training it did not fit in our development memory, so for it we checked only that the forward pass and token-by-token decoding agree; its quality was not measured in development.
References
- William Brandon, Mayank Mishra, Aniruddha Nrusimha et al. (2024). Reducing Transformer Key-Value Cache Size with Cross-Layer Attention. NeurIPS.
- Hongzhan Lin, Zhiqi Bai, Xinmiao Zhang et al. (2026). Reconstructing KV Caches with Cross-layer Fusion For Enhanced Transformers. ICLR.
- Yutao Sun, Li Dong, Yi Zhu et al. (2024). You Only Cache Once: Decoder-Decoder Architectures for Language Models. NeurIPS.
- David Raposo, Sam Ritter, Blake Richards et al. (2024). Mixture-of-Depths: Dynamically allocating compute in transformer-based language models.
- Kimi Team, Guangyu Chen, Yu Zhang et al. (2026). Attention Residuals.
- Zhenda Xie, Yixuan Wei, Huanqi Cao et al. (2026). mHC: Manifold-Constrained Hyper-Connections. ICML.
- Iz Beltagy, Matthew E. Peters, Arman Cohan (2020). Longformer: The Long-Document Transformer.