Introduction
The decoder of this task is a fixed mixture-of-experts transformer whose attention layers come in two kinds: windowed layers with rotary positions, which see only a recent window, and whole-document layers without positional encoding, which attend over the entire context. Its parameters, its data, its optimizer and its learning-rate schedule are fixed. What may change is how the blocks are called and what they share, and the question is which form of reuse across layers reaches a given held-out loss with the least training compute, while keeping long-range recall and a small decoding state.
The field offers two families of answers. One shares memory across depth: Cross-Layer Attention lets pairs of layers use one set of keys and values [1], FusedKV rebuilds the top layers' keys and values from a bottom and a middle layer [2], YOCO caches keys and values once in a decoder-decoder architecture [3], and sliding windows bound the memory each layer keeps [4]. The other re-routes the residual stream across depth: Attention Residuals re-route the residual stream across depth [5], and hyper-connections widen the residual stream into several streams with learned read and write weights, of which mHC is a constrained variant [6]. Mixture-of-Depths, finally, lets tokens skip blocks [7].
The two families pull in different directions. Memory sharing aims to save compute and state but, in the published numbers on this task, most variants raise the loss and damage far-copy recall. Depth routing lowers the loss but adds compute. Our method combines one of each, chosen so that the sharing removes work the decoder does not use and the routing recovers quality.
Method
Our method has two parts: a one-write retrieval hub that decides which layers keep their own
keys and values, and dynamic hyper-connections that route the residual stream across depth. The
feed-forward sublayer is untouched and, in the submitted configuration, is called only through R.mlp_delta; every softmax attention
uses the decoder's own query and key normalisation, scale and exclusive self-attention.
Which layers share memory
The submitted file opens with the observation that motivated the design, stated as the outcome of our development runs on trained starter decoders: windowing the later whole-document layers left the loss unchanged, so only the first whole-document layer uses text beyond the window, while every whole-document layer still wrote and cached its own whole-document memory. The windowed layers, by contrast, carried the positional and previous-token features that retrieval depends on, and sharing any of their keys or values damaged long-range recall. Memory is therefore shared only among layers with the same, content-addressed access pattern.
# ---------------------------------------------------------------------------------------------------------------
# One-write retrieval hub + hyper-connected depth routing.
#
# Diagnosis (trained starters): only the FIRST full-attention (NoPE) layer uses text beyond the window -- windowing
# the later full-attention layers leaves the loss unchanged -- yet every full-attention layer writes and caches its
# own whole-document key / value memory. The windowed (RoPE) layers, in contrast, are all indispensable and build
# the positional / previous-token features retrieval depends on: sharing ANY of their keys or values (with each other
# or with the hub) damaged long-range recall in our runs. So memory is shared only among layers with the same,
# content-addressed access pattern:
# * the first full-attention layer is the HUB, the only writer of a long-range key / value memory;
# * every later full-attention layer READS the hub's normalised keys and values with its own query, gate,
# exclusive self-attention and output projection (one softmax, the decoder's NoPE attention) and never computes
# or caches keys / values of its own;
# * windowed layers keep their own keys / values (each keeps the memory of the positions its attention mass lies
# on); above the first one they attend only the most recent window / LOCAL_FRACTION positions -- what lies
# further back is reachable through the hub, and their attention mass beyond half the window is 1-5% in trained
# starters. The first windowed layer (token-level keys, the most diffuse attention: ~11% of its mass beyond half
# the window) keeps the decoder's window: halving it too lost long-range recall in our runs.
# Decoding state: the first windowed cache, the half-windowed caches and ONE whole-document key / value cache.
# Depth routing: the residual stream is RATE dynamic hyper-connection streams; each sublayer reads a learned,
# input-dependent mixture of the streams and writes its output back with learned weights.
# ---------------------------------------------------------------------------------------------------------------Let be the indices of the whole-document layers. Layer is the hub and computes keys and values as the decoder does, and with the normalised attention input. Every later whole-document layer is a reader: it computes only its own query,
and attends over the hub's and with the decoder's softmax, followed by its own gate,
exclusive self-attention and output projection. Readers never compute or cache keys and values of
their own. The windowed layers keep their own keys and values; the first of them, which reads
token-level keys, keeps the decoder's window , and every windowed layer above it attends over the
most recent positions (LOCAL_FRACTION = 2), on the argument that what lies further back is
reachable through the hub.
class Routed(nn.Module):
def __init__(self, cfg, backbone):
super().__init__()
self.backbone = backbone
L = cfg.num_layers
longs = [i for i in range(L) if cfg.is_long_layer(i)]
self.hub = longs[0]
self.readers = set(longs[1:])
self.lwin = max(1, cfg.sliding_window // LOCAL_FRACTION)
if USE_HC:
self.hc = nn.ModuleList([_HC(cfg.hidden_dim, RATE, k, cfg.layer_norm_eps) for k in range(2 * L)])
def _win(self, i):
"""Attention window of layer i: full-attention layers none; the first (token-level) windowed layer the decoder's
window; later windowed layers window / LOCAL_FRACTION."""
w = self.backbone.blocks[i].attn.window
return None if w is None else (w if i == 0 else self.lwin)
# ---------------------------------------------------------------- parallel path
def _attn(self, i, x, seq, st):
blk = self.backbone.blocks[i]
attn = blk.attn
a = R.attn_in(blk, x)
if i in self.readers:
k, v = st["kv"]
q = R.rms_norm_np(_q_only(attn, a)) * attn.qk_mult # NoPE, as the hub
else:
q, k, v = R.qkv(attn, a)
q, k = R.qk_finish(attn, q, k)
if i == self.hub:
st["kv"] = (k, v)
return R.attn_out(attn, R.attend(attn, q, k, v, seq, window=self._win(i)), v, a)The decoding state that follows is one whole-document key and value cache, the full-window cache of the first windowed layer, and half-window caches for the other windowed layers; the readers store nothing. The token-by-token path mirrors the parallel one, with each reader taking the hub's cache and the hub's current value for its exclusive self-attention.
def decode_init(self, batch, max_len, device):
"""A cache per layer that computes its own keys / values (windowed layers keep only their window, the hub
the whole context); the later full-attention layers store nothing."""
bb = self.backbone
return {i: R.KVCache(bb.blocks[i].attn, batch, max_len, device, slots=self._win(i))
for i in range(R.n_blocks(bb)) if i not in self.readers}
def _attn_step(self, i, x, pos, seg_start, state, cur):
blk = self.backbone.blocks[i]
attn = blk.attn
a = R.attn_in(blk, x)
if i in self.readers:
q = R.rms_norm_np(_q_only(attn, a)) * attn.qk_mult
cache, v = state[self.hub], cur["v"]
else:
q, k, v = R.qkv(attn, a)
q, k = R.rms_norm_np(q), R.rms_norm_np(k)
if not attn.nope:
q, k = R.rope_at(q, pos, attn.theta), R.rope_at(k, pos, attn.theta)
q = q * attn.qk_mult
cache = state[i]
cache.write(pos, k[:, 0], v[:, 0])
if i == self.hub:
cur["v"] = v
return R.attn_out(attn, R.attend_step(attn, q, cache, pos, seg_start, window=self._win(i)), v, a)Depth routing with hyper-connections
The residual stream is widened to streams (RATE = 4). Each
of the sublayers, attention and feed-forward in each of the blocks, has its own
hyper-connection site. The site normalises each stream, , and
forms input-dependent read and write weights around static ones,
The width connection mixes the streams, ; the sublayer reads and returns , and the depth connection writes it back to every stream,
The final pre-readout state is . Initialisation reproduces the plain decoder: and start at zero with scales , has the identity for the carried streams and a one-hot read column selecting stream for site , and . All streams start as copies of the embedding and receive the same update, so the sublayers initially see the ordinary residual stream, and the final sum is that stream scaled by before the fixed final norm.
class _HC(nn.Module):
"""One dynamic hyper-connection site: width (read) and depth (write) connections over RATE streams."""
def __init__(self, dim, rate, layer_id, eps):
super().__init__()
a0 = torch.zeros(rate, 1)
a0[layer_id % rate, 0] = 1.0
self.eps = eps
self.static_alpha = nn.Parameter(torch.cat([a0, torch.eye(rate)], dim=1))
self.static_beta = nn.Parameter(torch.ones(rate))
self.dynamic_alpha_fn = nn.Parameter(torch.zeros(dim, rate + 1))
self.dynamic_alpha_scale = nn.Parameter(torch.full((1,), 0.01))
self.dynamic_beta_fn = nn.Parameter(torch.zeros(dim))
self.dynamic_beta_scale = nn.Parameter(torch.full((1,), 0.01))
self.norm_weight = nn.Parameter(torch.ones(dim))
def width(self, h):
hf = h.float()
nh = (hf * torch.rsqrt(hf.pow(2).mean(-1, keepdim=True) + self.eps) * self.norm_weight.float()).to(h.dtype)
alpha = torch.tanh(nh @ R.cdt(self.dynamic_alpha_fn)) * R.cdt(self.dynamic_alpha_scale) + R.cdt(self.static_alpha)
beta = torch.tanh(nh @ R.cdt(self.dynamic_beta_fn)) * R.cdt(self.dynamic_beta_scale) + R.cdt(self.static_beta)
return torch.einsum("bsmk,bsmd->bskd", alpha, h), beta
@staticmethod
def depth(mix, out, beta):
return out[..., None, :] * beta[..., None] + mix[..., 1:, :] def hidden(self, tokens, seq):
bb = self.backbone
x = R.embed(bb, tokens)
st = {}
if not USE_HC:
for i, blk in enumerate(bb.blocks):
if i != self.hub and i not in self.readers and self._win(i) == self.backbone.blocks[i].attn.window:
x, _ = R.block(bb, i, x, seq)
continue
x = x + self._attn(i, x, seq, st)
x, _ = R.mlp_half(blk, x)
return x
h = x[..., None, :].expand(*x.shape[:-1], RATE, x.shape[-1])
for i, blk in enumerate(bb.blocks):
mix, beta = self.hc[2 * i].width(h)
h = _HC.depth(mix, self._attn(i, mix[..., 0, :], seq, st), beta)
mix, beta = self.hc[2 * i + 1].width(h)
h = _HC.depth(mix, R.mlp_delta(blk, mix[..., 0, :])[0], beta)
return h.sum(-2)The learning-rate value is left at the default; the file defines no lr_config. The method has no
per-setting constants: the hub, readers and windows are derived from the decoder's own configuration.
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 ↓ | |
| Claude Opus 5.5 | 3.863 | 3.531 | 3.211 | 0.625 | 42.97 | 223.9 | 1,814 |
| 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
On the medium model our held-out loss is 3.531, the lowest in the table, against 3.569 for the starter decoder and 3.533 for mHC, the closest baseline. On the small model we reach 3.863, behind Hyper-Connections at 3.853 and, narrowly, Attention Residuals at 3.861. On the large model the order changes: our 3.211 still improves on the starter's 3.230, but Attention Residuals (3.195), mHC (3.200) and Hyper-Connections (3.205) are all lower.
Long-range recall improves rather than suffers. Our far-copy loss on the medium model is 0.625, the lowest in the table, against 1.001 for the starter and 0.759 for Hyper-Connections. The baselines that share keys and values across layers, Cross-Layer Attention (2.697) and FusedKV (1.684), are far behind on this measure, which is consistent with our choice to share memory only among the whole-document layers.
Training compute, shown in the table, is slightly below the starter's at every size. It is also below the compute of Hyper-Connections, mHC and Attention Residuals at every size, although our method also widens the residual stream into four streams. It is not the lowest in the table: Mixture-of-Depths [7] uses far less compute, at a much higher loss, and Cross-Layer Attention, sliding windows, FusedKV and SVFormer also train with less compute than we do on the medium model.
How we got here
The comments record the observations that shaped the design as outcomes of our development runs; we could not check them against any output and report them as claims.
- The hub came from a diagnosis of trained starters. Windowing the later whole-document layers of a trained starter left the loss unchanged, which identified the first whole-document layer as the only one that uses text beyond the window and the others as candidates to read its memory.
- Sharing windowed layers' keys or values was abandoned. Sharing any windowed layer's keys or values, with another windowed layer or with the hub, damaged long-range recall in our runs, which is why the windowed layers keep their own memory.
- Halving the first windowed layer's window was abandoned. The comments state that the upper windowed layers put 1 to 5% of their attention mass beyond half the window in trained starters, against about 11% for the first windowed layer, and that halving the first one's window too lost long-range recall. Only the upper windowed layers were narrowed.
- A variant without hyper-connections remains in the file. The switch
USE_HCselects a plain residual path that applies the same hub and windows; it is disabled in the submission, so the hyper-connections were kept as the configuration we submitted. The file contains no measurement of the variant without them.
The hyper-connection site follows the published dynamic form, which is also one of this task's baselines; what is new is pairing it with a single long-range memory that only one layer writes.
Limitations
- The lead is limited to the medium model. On the small model two and on the large model three published depth-routing baselines reach a lower loss than ours, so the advantage on the medium model does not carry over to the other sizes.
- No ablation separates the two parts. Our results measure the hub, the narrower windows and the hyper-connections together. How much of the loss gain comes from the streams and how much of the recall gain from the hub is not measured, and the diagnosis behind the hub is a development claim we could not check.
- The decoding-state saving is structural, not measured here. The readers keep no cache and the upper windowed layers keep half a window, but the table reports neither decoding state nor long-document loss for this run.
- Unused parameters. The readers' key and value projections are never used, yet they remain part of the fixed decoder and count toward its parameters.
- The window rule assumes a layout. The full window is kept for layer 0 by index; on a decoder whose first windowed layer is not layer 0, every windowed layer would be narrowed.
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.
- Iz Beltagy, Matthew E. Peters, Arman Cohan (2020). Longformer: The Long-Document Transformer.
- 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.
- David Raposo, Sam Ritter, Blake Richards et al. (2024). Mixture-of-Depths: Dynamically allocating compute in transformer-based language models.