Introduction
The decoder in this task is a shallow mixture-of-experts transformer: most of its layers use sliding-window softmax attention [1], a few use full attention, and every layer ends in a routed feed-forward sublayer with a shared expert. Its weights, its training data, the optimizer and the learning-rate schedule are all fixed. What we may change is how the blocks are called and what they share, and the question is which way of reusing computation across layers reaches a given held-out loss with the least measured training compute, without giving up long-range recall or growing the state kept for decoding.
The field offers several answers, each reusing one kind of computation. Cross-layer attention shares keys and values between adjacent layers [2], and fused variants rebuild the top layers' keys and values from a bottom and a middle layer [3]; these shrink the decoding cache but not the attention arithmetic of every layer. YOCO computes one global key-value cache and lets later layers cross-attend to it [4], which still runs a full attention core at every cross layer. Mixture-of-Depths lets most tokens skip alternate blocks [5], which saves compute but drops whole sublayers for those tokens. Residual-mixing methods such as hyper-connections and attention residuals [6, 7] re-route the residual stream across depth but keep every sublayer's compute.
Two properties of this decoder shaped our approach. Every training token passes through every block, so compute saved per block is saved on every token; and by our own estimate from the decoder's FLOP accounting the attention core and the feed-forward sublayer each accounted for a large share of the forward FLOPs, so a method that only removes attention work, or only feed-forward work, leaves much of the cost in place. We therefore reuse both, and we reuse them at different depths.
Method
Our method, staggered dual-memory reuse (SDMR), keeps two memories while it walks down the stack. Write for the residual stream, for block 's normalised attention input, and for block 's own fixed projections.
- The attention memory. When a block computes attention afresh, it keeps the per-head attention output , taken before the exclusive self-attention subtraction, the headwise gate and the output projection. Sliding layers write the local memory ; the first full-attention layer writes the global memory .
- The feed-forward memory. When a block runs its feed-forward sublayer (through
routing.mlp_delta), it keeps the update it added to the residual stream.
Blocks refresh the two memories on staggered schedules and read the stored memory in between.
Staggered refresh schedules
Attention is computed afresh in block 0, in every even-indexed sliding block and in the first full-attention block; every other full-attention block reads the global memory instead. The feed-forward sublayer runs in block 0 and in blocks with , where the period is for stacks of at least 8 blocks and otherwise; every other block re-adds the stored update. The two schedules have different periods, so where one sublayer is read from memory the other is often computed afresh. Fresh sliding layers use a window of 256 tokens instead of the decoder's own.
def _fresh_attn(self, i, is_long):
if i == 0:
return True
if is_long:
return i == self.first_long
return i % 2 == 0
def _fresh_mlp(self, i):
period = 4 if self.L >= 8 else 3
return i == 0 or i % period == 1
def _win(self, blk):
return "layer" if blk.attn.window is None else WINFresh attention with a value residual
Apart from the shorter window of sliding layers, a fresh attention block is the decoder's own attention, with one change: its values are mixed with the first layer's values ,
with one learned scalar per layer. The queries and keys keep the decoder's normalisation,
positional encoding and scale, and the output passes through the decoder's own attn_out, so the
exclusive self-attention and headwise gate are unchanged.
def _mix_v(self, i, v, v1):
if v1 is None:
return v
lam = torch.sigmoid(R.cdt(self.vlam[i]).float()).to(v.dtype)
return lam * v1 + (1.0 - lam) * v
def _attn_fresh(self, blk, x, seq, v1, i):
attn = blk.attn
a = R.attn_in(blk, x)
q, k, v = R.qkv(attn, a)
v = self._mix_v(i, v, v1)
q, k = R.qk_finish(attn, q, k)
y = R.attend(attn, q, k, v, seq, window=self._win(blk))
return R.attn_out(attn, y, v, a), y, vReading the attention memory
A block that does not refresh attention reads the stored memory ( in a sliding block, in a full-attention block) through a gate computed from its own query projection, , and adds a fresh attention correction over the last 64 tokens only. The correction keeps the decoder's query and key normalisation, positional encoding, exclusive self-attention and headwise gate, written out as below. All terms are summed before the output projection, which is then applied once:
where the term is present only in sliding blocks after the first full-attention layer, and is a learned per-layer scalar initialised at 0.1. The same serves as the gate and, after normalisation, as the correction's query, so a read block computes one query projection, one key and one value projection over a short window, and one output projection. Fresh sliding blocks after the first full-attention layer also add a gated read of the global memory, , where is the normalised residual stream after the fresh attention update, so long-range information computed once by exact full attention reaches every later layer.
The gated read follows the gated memory unit of SambaY, one of this task's reference methods; our contribution is to use it for both the local and the global memory, at every non-refreshing block, and to pair it with an exact short-window correction through a single output projection.
@staticmethod
def _pre_wo(attn, y, v, a):
"""attn_out's computation before the output projection: exclusive
self-attention subtraction and headwise gate, flattened."""
B, S = y.shape[:2]
av = v.repeat_interleave(attn.n // attn.m, dim=2)
dot = (y * av).sum(-1, keepdim=True)
vn = (av * av).sum(-1, keepdim=True)
y = y - (dot / (vn + 1e-6)) * av
gate = 2 * torch.sigmoid(a @ R.cdt(attn.attn_gate))[..., None]
return (gate * y).reshape(B, S, attn.n * attn.h)
def _attn_read(self, blk, x, mem, memG, seq, i):
attn = blk.attn
a = R.attn_in(blk, x)
B, S, D = x.shape
g = a @ R.cdt(attn.w_q)
sg = F.silu(g)
pre = mem.reshape(B, S, attn.n * attn.h) * sg
if memG is not None:
pre = pre + R.cdt(self.gscale[i]).to(x.dtype) * (memG.reshape(B, S, attn.n * attn.h) * sg)
q = g.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)
q, k = R.qk_finish(attn, q, k)
y = R.attend(attn, q, k, v, seq, window=CORR)
return (pre + self._pre_wo(attn, y, v, a)) @ R.cdt(attn.w_o)Reading the feed-forward memory
A block that does not run its feed-forward sublayer adds the stored update scaled per channel,
so no feed-forward norm, router or expert is evaluated outside routing.mlp_delta. The three
learned parameter sets , and are vectors tagged as mechanism parameters,
numbers per layer.
def hidden(self, tokens, seq):
bb = self.backbone
x = R.embed(bb, tokens)
memL = memG = memM = v1 = None
for i, blk in enumerate(bb.blocks):
is_long = blk.attn.window is None
if self._fresh_attn(i, is_long):
d, y, v = self._attn_fresh(blk, x, seq, v1, i)
if i == 0:
v1 = v
if is_long:
memG = y
else:
memL = y
x = x + d
if not is_long and memG is not None and i > self.first_long:
x = x + R.cdt(self.gscale[i]).to(x.dtype) * self._gmu(blk, x, memG)
else:
mg = memG if (not is_long and memG is not None and i > self.first_long) else None
x = x + self._attn_read(blk, x, memG if is_long else memL, mg, seq, i)
if self._fresh_mlp(i):
d, _ = R.mlp_delta(blk, x)
memM = d
x = x + d
else:
x = x + memM * R.cdt(self.mscale[i])
return xDecoding and the learning rate
Decoding follows the same schedule token by token. Each fresh sliding block keeps a 256-token ring cache, each read block a 64-token cache for its correction, and only the first full-attention block keeps a cache over the whole context; the memories themselves are recomputed at the current position within the step and need no storage.
def decode_init(self, batch, max_len, device):
bb = self.backbone
caches = []
for i, blk in enumerate(bb.blocks):
is_long = blk.attn.window is None
if self._fresh_attn(i, is_long):
slots = None if is_long else WIN
else:
slots = CORR
caches.append(R.KVCache(blk.attn, batch, max_len, device, slots=slots))
return cachesFinally, lr_config returns {"scale": 1.5}, raising both default peak learning rates by half;
the schedule itself is unchanged.
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 ↓ | |
| Muse Wonder Full | 4.004 | 3.671 | 3.376 | 0.773 | 25.85 | 134.5 | 965.5 |
| 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
Training compute. SDMR trains with far less compute than the starter on every model size, and on the large model with the least compute of any method in the table, below Mixture-of-Depths. On the small and medium models its compute is about equal to Mixture-of-Depths', slightly above it, and well below every other method.
Held-out loss. The saving is not free. On every model size our held-out loss is above the starter's: 4.004 against 3.893 on the small model, 3.671 against 3.569 on the medium model and 3.376 against 3.230 on the large one. The best baseline on the medium model, mHC [6], reaches 3.533. On the small and medium models our loss is higher than every baseline's except Mixture-of-Depths', which uses about the same compute and is worse than ours by a clear margin (4.099 and 3.749). On the large model our loss is the highest in the table, above Mixture-of-Depths' 3.344 and SVFormer's 3.337, while our compute there is the lowest. Against the method closest to us in compute, then, SDMR is better on two model sizes and trades loss for compute on the third.
Long-range copying. Our far-copy loss on the medium model is 0.773, below the starter's 1.001 and below every baseline except Hyper-Connections (0.759). We attribute this to reading a single exact global memory at every later layer, instead of recomputing or sharing caches; the methods that share or fuse keys and values, or attend only within a window, are far behind on this measure.
How we got here
We began from the cost structure. Reading the decoder's FLOP accounting, we found the models shallow, wide and trained on few tokens per parameter, and we estimated that the feed-forward sublayer and the attention core each took a large share of the forward FLOPs. Our first hypothesis, written down before any run, was already the final idea: keep an attention memory and a feed-forward memory, refresh one per block, and gate-read the other, with the attention read in the form of SambaY's gated memory unit using the block's own query and output projections.
- Short runs could not separate the candidates. Our first screen trained every variant for 5% of the schedule, and the losses were indistinguishable; we moved to 25% runs and to held-out loss. In the 25% screen, staggered reuse reached about the same loss as Mixture-of-Depths at the same counted compute, which told us the idea was competitive but not yet better.
- Adding a short exact correction to the read. Adding a fresh short-window attention to each read block and a gated read of the global memory in later sliding blocks, together with a 512-token window on fresh sliding layers, gave our second version. In our development runs this version reached a lower training loss than the starter on one mid-sized model while using 19% fewer counted FLOPs, and a later ablation put the correction's worth at about 0.07 in development loss.
- Token-selective feed-forward lost. Running the feed-forward sublayer afresh only on the top half of tokens per layer, in the manner of Mixture-of-Depths, gave a worse loss-for-compute trade than staggered reuse and was dropped.
- The learning rate. A peak-learning-rate scale of 2.0 looked like a large gain at 25% of the schedule, which we suspected was a short-run artefact. At full length on the smallest width the gain was real but small and peaked near 1.5; later anchor runs found it flat between 1.25 and 1.75, so we kept 1.5. No reference method sets the learning rate.
- Noise. One repeated run with a different seed moved the held-out loss of the starter by far more than the differences we were trying to measure, so from then on we relied on held-out loss, anchored the main comparison with longer runs, and confirmed it on two seeds.
- Value residual and a shorter window both helped, and a correction window of 64 tokens was as good as 128 at lower cost; these became the submitted configuration. A feed-forward period of 4 instead of 3 helped on a stack of 8 blocks, which is why the period depends on depth.
- Exact decoding needed two numerical fixes. Our token-by-token decoder at first did not reproduce the parallel pass exactly. The causes were a gate matmul done in fp32 rather than the compute dtype, and a different order of two bf16 additions; after aligning both, our development check found a signed mean loss difference of about on real text.
- Merging the output projections. Late in the run we noticed that each read block applied its output projection twice, once to the gated memory and once to the correction. Summing in pre-projection space and projecting once is exact by linearity; together with a static feed-forward read scale it lowered counted compute by about 5% at unchanged development loss.
- What did not help. A dense-to-reuse curriculum, a fresh last block, block looping, all-fresh attention, all-fresh feed-forward, sparser attention refresh, per-head and low-rank read gates, value mixing in the correction, a second exact global layer, other initialisations and other window sizes were each measured and rejected. All-fresh attention gave no gain, while all-fresh feed-forward gave a gain too small for its cost.
- Why reuse works here. In the trained starter, the updates of adjacent sublayers were nearly orthogonal, so SDMR does not exploit redundancy that is already there; training reorganises the fresh layers to write memories that serve several blocks. The learned read scales support this: the global-read scale grew from 0.1 to about 0.57 during training, and late layers leaned heavily on the first layer's values.
In our development runs, at one mid-sized width trained to 23% of its schedule, SDMR reached a held-out loss of 3.522 and 3.531 on two seeds at 95M counted FLOPs per token, against the starter's 3.510 and 3.506 at 165M. We also measured a decoding state of about 2.33M stored numbers against the starter's 6.30M at the same width, and, on long-book training data, a lower loss than the starter's at about half the compute. These are our own development measurements, on data we prepared ourselves.
Limitations
- The loss penalty is larger than we measured. In development, at fractions of the schedule, our loss was within a few hundredths of the starter's and sometimes below it. In the evaluated runs the gap to the starter is considerably larger on every model size. Our decisions rested mostly on truncated schedules (a quarter of the schedule or much less on the larger widths), and the evaluation suggests that memory reuse costs more quality as training gets longer.
- The compute saving is bought, not free. At the scored compute SDMR's loss is worse than every baseline's except Mixture-of-Depths' on the small and medium models, and worse than every baseline's on the large one. Whether its loss-for-compute exchange beats running the starter with less compute depends on the slope of the loss against compute, which we estimated only from our own short runs.
- The learning rate is changed too. The peak-learning-rate scale of 1.5 also improves the unchanged starter in our development runs, so the evaluated comparison mixes the wiring with a learning-rate change that the reference methods did not make.
- Decoding state is not in the published results. Our claims about a small decoding cache rest on our own measurements; the table reports only loss, compute and far-copy loss.
- Fixed schedules. The refresh periods are fixed per depth and do not adapt to the input; a block that reads a memory reads it for every token, whether or not the stored update suits that token.
References
- Iz Beltagy, Matthew E. Peters, Arman Cohan (2020). Longformer: The Long-Document Transformer.
- 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.
- Zhenda Xie, Yixuan Wei, Huanqi Cao et al. (2026). mHC: Manifold-Constrained Hyper-Connections. ICML.
- Kimi Team, Guangyu Chen, Yu Zhang et al. (2026). Attention Residuals.