Introduction
A language model can hold what it has read in two forms. Softmax attention holds it exactly: every past key and value stays in a cache that grows with the sequence. A recurrence such as Gated DeltaNet [1] or Mamba, or a local attention layer, holds it compressed, in a state of fixed size. Exact memory is the expensive kind at inference. The question this task asks is where, under a fixed inference-state budget, a stack should keep each kind: across depth, within a layer, and with which attention options.
The field's answers are mostly layout rules: interleave a recurrence with sliding-window attention [2]; place one attention layer per block of Mamba layers [3, 4]; mix linear and full attention at a fixed ratio [5, 6]; alternate local and global attention [7, 8, 9]; or run attention and a state-space model side by side in the same layer [10, 11]. Gating the attention output is a further option [12]. The layout rules take the attention layer itself as given and varies how many of them there are and where they sit.
Our starting observation was that, in a recurrent stack, the attention layer is the hard part to train rather than the scarce part. For a softmax layer to recall what followed an earlier occurrence of the current context, it has to learn two things together: a step that writes the previous token's identity into each position, and a match-and-copy step that uses it. The keys and the values at position come from the same hidden state. In our first calibration runs, global attention without a positional code inside a Gated DeltaNet stack had not learned that circuit by the end of a short proxy run, and rotary global attention learned it only partly, at short distances inside the training context, and not beyond it. That pointed us to a different question from "how many attention layers": can the exact memory be built so that recall is available from the first optimisation step, and so that it reads the same way at any distance?
Method
Our stack has three kinds of sequence memory, each placed where we found it cheapest to learn and to keep. Gated DeltaNet is the compressed memory in every layer except two. Those two hold a context-keyed store, an exact memory addressed by content. Five layers above the first store add sliding-window attention, an exact memory addressed by position, summed in parallel with the recurrence.
The context-keyed store
At a store layer, let be the layer input at position , and for each head let
The key under which token is filed is the normalised address of the position before it, which in a recurrent stack carries the recurrence's summary of everything up to . Its value is a projection of the token itself. The query at is computed by the same map as the keys, since both describe a context. A read therefore asks "where did a context like mine occur?" and returns "what came next there". Recall, copying and in-context -gram statistics become a single content-addressed read. Because identical contexts already have cosine 1 before anything is learned, the read is usable from the first optimisation step. The centring bias removes the component common to all hidden states. In our development runs, without it the cosine between a query and the stored keys averaged about 0.28 rather than 0, which blurred every read.
The read is a softmax over all entries and one null entry of value zero:
with a gain that grows with the size of the store,
where counts positions from zero, so entries are visible. There is no positional code: a match far back is scored exactly like a match one step back. The logarithmic gain addresses a known weakness of softmax as the number of candidates grows. With a fixed gain, the share of probability mass that an exact match keeps against distractors falls as grows. A gain with keeps it near one, as long as the key dimension is large relative to . The submission's docstring derives this, and it is why 64 key dimensions per head are enough.
The null entry lets a query with no good match return close to nothing, so that the size of the read reflects how much evidence the store held. Its logit is a learned level in cosine units, initialised at 0.5, but capped:
An exact match (cosine 1) therefore always scores at least nats above the null and keeps at least of the mass the two share. Section 4 explains why the cap is needed.
def forward(self, x, state=None, return_state=False):
B, T, _ = x.shape
H, dk, dv = self.heads, self.key_dim, self.val_dim
p0 = 0 if state is None else state["pos"]
v = self.v_proj(x).view(B, T, H, dv).transpose(1, 2)
with torch.autocast(device_type=x.device.type, enabled=False):
# addresses are computed in float32: the same token gets the same
# key whatever the length of the call it is part of
xf = x.float()
q = unit_rows(self.address(self.q_proj, xf).view(B, T, H, dk).transpose(1, 2), self.eps)
kn = q.to(v.dtype)
# entry s is addressed by the context that preceded it
if state is None:
pend = kn.new_zeros(B, H, 1, dk)
else:
pend = state["pend"].to(kn.dtype)
k = torch.cat([pend, kn[:, :, :T - 1]], dim=2)
if state is None:
kk, vv = k, v
else:
kk = torch.cat([state["k"].to(k.dtype), k], dim=2)
vv = torch.cat([state["v"].to(v.dtype), v], dim=2)
L = kk.shape[2] - T
# gain: slope_h * ln(number of visible entries + 1)
n = torch.arange(T, device=x.device, dtype=torch.float32) + float(p0 + 2)
gain = self.log_slope.float().exp().view(1, H, 1, 1) * torch.log(n).view(1, 1, T, 1)
nul_logit = None
if self.use_sink:
# the null entry: at level_h in cosine units, but never closer than
# `floor` nats to an exact match (cosine 1), which therefore always
# keeps at least sigmoid(floor) of the mass against it
nul_logit = torch.minimum(gain * self.sink.float().view(1, H, 1, 1), gain - self.floor)The null entry is implemented without a separate code path. The query carries its null logit in an extra coordinate, stored keys have 0 there and the null key has 1, and the width is padded to a multiple of eight so that the fused attention kernels still apply:
S = ka.shape[2]
dv = va.shape[3]
off = 0
if nul_logit is not None:
# eight more coordinates (one used; the width stays a multiple of 8 for
# the fused kernels): a query carries its null logit there, stored keys
# have 0 and the null key has 1, so the null entry scores exactly that
qs = torch.cat([qs, nul_logit.expand(B, h, T, 1), qs.new_zeros(B, h, T, 7)], dim=-1)
ka = torch.cat([ka, ka.new_zeros(B, h, S, 8)], dim=-1)
nul = torch.cat([ka.new_zeros(B, h, 1, dk), ka.new_ones(B, h, 1, 1),
ka.new_zeros(B, h, 1, 7)], dim=-1)
ka = torch.cat([nul, ka], dim=2)
va = torch.cat([va.new_zeros(B, h, 1, dv), va], dim=2)
off = 1Each store keeps heads of dimensions per token, a small fraction of a full attention layer's twelve heads of keys and values. Addresses and the read are computed in float32 on the stored, rounded entries, so a one-shot forward, a forward continued from carried state and a one-token decode step all see the same numbers.
Where the memories sit
The layout is a rule in n_layer and hidden_size, not a fixed table. With stores, store sits at layer
. The lower bound of 2 applies
for and keeps at least two recurrent layers below the first store, because a
key is only as good as the summary under it. Every other layer is Gated DeltaNet with head dimension
128. Every second layer above the first store also gets a sliding-window attention branch with
rotary positions, window 2048, and three key/value heads shared by its query heads, added to the
recurrence's output (fuse: "sum").
STORE_EVERY = 6 # one context-keyed store per this many layers
HEADS = 2
KEY_DIM = 64
VAL_DIM = 64
WINDOW = 2048 # the local attention's window (0: no local attention)
WINDOW_KV_HEADS = 3 # K/V heads of the window attention (0: one per query head)
def __init__(self, n_layer, hidden_size):
self.n_layer = n_layer
self.hidden_size = hidden_size
m = max(1, int(round(n_layer / float(self.STORE_EVERY))))
lo = 2 if n_layer >= 5 else 1 # recurrent layers below the first store
slots = [max(lo, (n_layer * (2 * j + 1)) // (2 * (m + 1))) for j in range(m)]
self.slots = tuple(sorted(set(s for s in slots if s < n_layer))) def layer_spec(self, layer_idx):
if layer_idx in self.slots:
return {"mixer": "custom",
"options": {"heads": self.HEADS, "key_dim": self.KEY_DIM,
"val_dim": self.VAL_DIM, "slope": 2.0, "sink": 0.5,
"floor": 2.0}}
rec = self.recurrent()
local = (self.WINDOW > 0 and len(self.slots) > 0 and rec["mixer"] == "gdn"
and layer_idx > self.slots[0] and (layer_idx - self.slots[0]) % 2 == 1)
if local:
return {"mixer": "parallel", "branches": [rec, self.window(self.WINDOW)],
"fuse": "sum"}
return recFor the twelve-layer stack of this task the rule gives stores at layers 2 and 6, Gated DeltaNet alone at layers 0, 1, 4, 8 and 10, and Gated DeltaNet plus a parallel window at layers 3, 5, 7, 9 and 11. By our own meter, this stack keeps about 43 MiB of inference state against a cap of 316.6 MiB.
The learning rate
The only open recipe knob is the peak learning rate. We set it to instead of the default and scale it down for deeper stacks:
def __init__(self, n_layer, hidden_size):
self.n_layer = n_layer
self.hidden_size = hidden_size
def recipe(self):
# measured at 12 layers; deeper stacks get a proportionally gentler rate
return {"lr": 1e-3 * min(1.0, (12.0 / max(1, self.n_layer)) ** 0.5)}The BranchCombine module is left as a learned per-branch weight. No parallel layer in our
composition uses it.
Results
| Method | ① | ② | ③ | ④ | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Validation loss ↓ | LAMBADA perplexity ↓ | WikiText-2 perplexity ↓ | Validation loss, 16k window ↓ | Tail loss, 16k window ↓ | WikiText-2 loss, 16k window ↓ | SQuAD answer score ↑ | S-NIAH-1 answer NLL ↓ | S-NIAH-2 answer NLL ↓ | S-NIAH-1 answer NLL, 16k ↓ | S-NIAH-2 answer NLL, 16k ↓ | Relative prefill time ↓ | |
| Claude Fable 5.2 | 3.314 | 41.04 | 32.04 | 3.256 | 3.251 | 3.367 | 23.69 | 3.113 | 2.777 | 3.698 | 3.041 | 0.941 |
| All attention | 3.492 | 47.65 | 40.93 | 5.331 | 6.657 | 5.889 | 19.67 | 4.814 | 5.039 | 11.00 | 11.35 | 0.999 |
| Samba | 3.401 | 44.61 | 36.35 | 3.345 | 3.340 | 3.535 | 22.45 | 4.404 | 5.129 | 7.062 | 7.598 | 0.566 |
| Jamba | 3.418 | 42.68 | 38.59 | 3.364 | 3.357 | 3.580 | 17.73 | 3.367 | 3.639 | 5.085 | 5.288 | 0.666 |
| All Gated DeltaNet | 3.434 | 44.73 | 40.82 | 3.382 | 3.372 | 3.659 | 12.67 | 3.153 | 5.105 | 4.668 | 7.407 | 0.640 |
| Qwen3-Next | 3.393 | 43.07 | 36.92 | 3.608 | 4.133 | 3.916 | 22.69 | 2.143 | 2.585 | 7.114 | 4.624 | 0.735 |
| Gemma 3 | 3.433 | 45.27 | 38.52 | 3.407 | 3.430 | 3.624 | 19.77 | 3.415 | 3.054 | 6.550 | 7.671 | 0.496 |
| SWAN-GPT | 3.503 | 48.49 | 45.62 | 3.451 | 3.444 | 3.784 | 17.79 | 6.593 | 6.114 | 7.126 | 7.121 | 0.561 |
| iRoPE, without QK norm | 3.473 | 46.92 | 39.75 | 3.566 | 3.763 | 3.624 | 22.99 | 2.505 | 2.476 | 3.130 | 3.220 | 0.527 |
| All sliding-window attention | 3.486 | 47.47 | 40.86 | 3.429 | 3.421 | 3.655 | 19.14 | 4.931 | 5.137 | 7.227 | 7.902 | 0.514 |
| Nemotron-H | 3.373 | 43.04 | 35.35 | 3.446 | 3.648 | 3.515 | 22.39 | 2.005 | 2.562 | 6.151 | 6.200 | 0.703 |
| Falcon-H1 | 3.380 | 43.75 | 35.72 | 3.630 | 3.868 | 3.852 | 23.46 | 1.294 | 2.340 | 4.706 | 5.744 | 1.021 |
| Samba, Mamba-1 | 3.350 | 42.50 | 34.49 | 3.293 | 3.285 | 3.479 | 25.23 | 4.313 | 4.628 | 7.169 | 7.426 | 0.594 |
| Jamba, Mamba-1 | 3.394 | 43.81 | 37.20 | 3.514 | 3.718 | 3.663 | 21.85 | 2.740 | 2.665 | 7.356 | 7.275 | 0.656 |
| Qwen3-Next, gated attention | 3.334 | 41.75 | 32.96 | 3.349 | 3.419 | 3.526 | 26.51 | 3.803 | 2.042 | 4.495 | 2.836 | 1.083 |
| iRoPE | 3.514 | 48.52 | 41.58 | 3.549 | 3.670 | 3.686 | 22.22 | 1.501 | 1.670 | 2.523 | 2.345 | 0.563 |
| gpt-oss | 3.465 | 47.32 | 40.08 | 3.853 | 4.213 | 4.137 | 21.78 | 3.374 | 3.692 | 7.751 | 8.232 | 0.678 |
| Hymba | 3.335 | 40.83 | 34.44 | 3.293 | 3.303 | 3.500 | 22.86 | 4.803 | 5.220 | 7.800 | 8.092 | 2.191 |
- ① 124M FineWeb pretraining · 4k training context · validation, WikiText-2 and LAMBADA
- ② Same checkpoint · 16k-window validation / WikiText-2
- ③ SQuAD completion + four near/far RULER needle-recall measures, far needles at 16k
- ④ Measured inference cost · 16k prefill vs an all-attention stack, fused kernels, quality guard
Pretrain and Long-ctx. Our stack has the lowest validation loss of every published baseline on Pretrain: 3.314, against 3.334 for Qwen3 gated [12]. On the LAMBADA held-out perplexity of Pretrain it is second, at 41.04, behind Hymba [10] (40.83). On Long-ctx it has the lowest value on the long-context and tail losses: 3.256 against 3.293 (Samba-M1 [2]), and 3.251 against 3.285 (Samba-M1 [2]). The table also shows two further held-out-text measures of Pretrain and Long-ctx, and our stack is lowest on both of those as well. On Long-ctx the largest losses belong to stacks with full or global attention layers: the all-attention reference reaches 5.331 and 6.657, and the gpt-oss layout 3.853. Our stack's two Long-ctx losses are within a few thousandths of each other. This is consistent with what we designed for: no layer in our stack is ever asked for a relative position it was not trained on.
Recall. The recall metrics are where the store was meant to make the difference, and the picture there is mixed. On recall accuracy we reach 23.69, third behind Qwen3 gated [12] (26.51) and the Mamba-1 Samba (25.23), and above the starter (19.14). On recall NLL 3 and recall NLL 4 we are third, at 3.698 and 3.041, behind Llama 4 qk (2.523 and 2.345). On recall NLL 3 the plain iRoPE layout (3.130) is second, and on recall NLL 4 the gated Qwen3-Next layout (2.836) is second. Every other baseline is behind us on these two metrics. On recall NLL 1 and recall NLL 2, however, we are only mid-table, at 3.113 and 2.777. Six baselines are ahead on recall NLL 1 and seven on recall NLL 2, led by Falcon-H1 [11] (1.294) and Llama 4 qk (1.670). Several of the layouts ahead of us there keep full attention layers.
Prefill. Our relative prefill time is 0.941. That is slower than thirteen of the seventeen baselines and faster than only the all-attention reference (0.999), Falcon-H1 (1.021), the gated Qwen3-Next layout (1.083) and Hymba (2.191). The starter's all-window stack measures 0.514. The cost follows from the design. Each store's read is a causal softmax over all entries, computed in float32 so that every call path sees the same numbers, and five layers run two mixers side by side.
How we got here
The trace records a sequence of proxy experiments: short runs, and longer runs with a smaller batch, all at a small fraction of the full training budget. We never trained the full recipe. Every number below is a development measurement from those proxies, compared against the Qwen3-Next 3:1 layout baseline trained at its default rate as the yardstick.
- The diagnosis came from failed baselines. We surveyed the hybrid literature: how attention layers are placed and in what ratio [5, 2, 3, 10], and the work on keeping softmax sharp as the candidate set grows. That work suggested a gain growing like . Our first calibration runs then showed that global attention without a positional code inside a Gated DeltaNet stack learned essentially no recall of a repeated random passage in a short proxy (accuracy at most 0.002, in both a Jamba-style and a two-layer layout). Rotary global attention reached 0.44 at the shortest distance tested, fell to 0.03 at the longest distance inside the training context, and its loss rose sharply beyond the training length. We concluded that the bottleneck was finding the recall circuit, not the amount of exact memory.
- The shifted key is the mechanism. Our first store, at layers 5 and 9, reached a proxy validation loss of 4.162 against 4.221 for the yardstick, and random-passage recall of about 0.8 at every distance tested. The identical module with ordinary, unshifted keys learned no recall and gave no gain in loss (4.295). Removing the store's output from a trained model cost 0.48 nats. The idea is a continuous cache over past hidden states, or a nearest-neighbour language model, made into a trained layer.
- Fixing the read's statistics. The trained store's loss crept up as the context grew. We diagnosed the drift and tried alternatives to the gain law. Clipping the gain at its training-length value cost recall. An additive recency penalty on far entries reduced the drift but cut recall sharply. A forgetting rate proportional to the mismatch would keep exact far matches, but it needs an explicit, much slower read, so we deferred it. What we did adopt was the centring bias and a log-domain parametrisation of the gain. On a longer proxy we re-checked the plain logarithmic gain law against its alternatives, and it had the lowest loss and a recall within 0.001 of the best.
- Depth. Earlier stores were better on every measure: layers 3 and 7 beat 5 and 9, and 2 and 6 were best. A store at layer 1 had the best recall of random key–value pairs, because its keys are close to the previous token itself, but cost about 0.03 nats of loss. That is why the rule keeps two recurrent layers below the first store. Putting the store in parallel with the recurrence gave a slightly better loss and slightly worse recall, so we did not adopt it.
- The store alone only tied the yardstick. On a longer proxy, the stack of stores and Gated DeltaNet won decisively on recall and length robustness, but tied on validation loss (3.645 against 3.642). Splitting the loss by token class showed where the yardstick earned its nats: the store wins when the preceding context repeats, and loses when a token recurs in a new context. That case needs addressing by the token itself, which ordinary attention provides. Sliding-window attention replacing recurrent layers gave no gain (3.645). The same windows in parallel with the recurrence gave 3.617, better in every token class. Token-keyed heads inside the store went unused once windows were present. A lexical store at layer 0, tried to recover random key–value recall, did not improve it. Both were dropped. Nine parallel window layers were still behind five in training loss when we stopped that run.
- Grouped key/value heads. Three key/value heads for the window's query heads matched the full-head windows within noise (3.621 against 3.617) at two-thirds of the state, so we adopted them.
- The learning rate, and the null floor it forced. In a short run at the full batch, reached a validation loss of 4.17 against 4.27 at the default rate. On a long small-batch proxy it ended about 0.047 nats ahead. However, long-distance recall slipped by two to three points. Inspecting the trained stores showed why. The null level of one of the lower store's heads had climbed to 0.985 in cosine units, so it was progressively shutting its own head: training raised the level to reject imprecise matches faster than the slowly moving gain could sharpen. We added the floor . Applied at evaluation time alone to the un-floored model, it restored long-distance recall from 0.89 to 0.95. Trained in, it kept recall at 0.92 for 0.002 nats of loss, and the learned gain rose instead of the level: selectivity moved from "shut the head" to "sharpen the kernel". A floor of 3 trained to the same result as a floor of 2. At with the floor, loss improved by a further 0.018 nats but long-distance recall fell by four to six points. Under the rule we had fixed beforehand, which required at least equal loss and recall, the rate stayed at . A repeat training run of the final configuration from a different initialisation reproduced the loss to within 0.004.
- The weakest regime, found last. A final probe asked why recall of random key–value pairs stays weak. In the lower store the correct entry is the nearest key 95–98% of the time, but it often fails to clear the null level, which training had set for natural text, where a cosine of 0.84 is usually noise. Lowering that level at evaluation time raised key–value recall substantially for about 0.007 nats of loss. We did not ship this, because a trained looser threshold (the floor of 3) had been absorbed by training. The untested remedy we record is a relative acceptance rule, like the ratio test of descriptor matching: accept the best match when it stands out from the runner-up.
Limitations
- Recall is not uniformly better. On recall NLL 1 and recall NLL 2 of Recall, six and seven published baselines are ahead of us, and two are ahead on recall accuracy. Our best recall results are on recall NLL 3 and recall NLL 4, but even there, on each, two layouts with full attention layers do better.
- The null threshold is absolute. Our own probes show that the lower store finds the correct entry but rejects weak matches, because its acceptance level is learned on natural text. Recall of arbitrary key–value associations is the clearest weakness of the method as delivered. A relative acceptance rule is the obvious next step, and we did not test it.
- Prefill is expensive. Each store's read is quadratic in the sequence length and runs in float32, and five layers carry two mixers. On Prefill the stack is slower than most baselines, despite a small inference state. A small state does not make a fast prefill.
- Every design choice rests on proxies. Placement, the parallel window, the grouped heads, the floor and the learning rate were all chosen on runs at a small fraction of the full training budget, mostly as single runs. The learning-rate choice in particular trades loss against recall, and the proxies settled that trade by a rule we fixed beforehand, not by evidence at full scale.
- Some drift remains. The forgetting rule we derived to remove the residual growth of loss with context length needs an explicit read that we judged too slow, and we did not implement it.
- The depth rule is lightly tested off twelve layers. Builds at other depths trained in short sanity runs. The square-root learning-rate scaling for deeper stacks is an assumption, not a measurement.
References
- Songlin Yang, Jan Kautz, Ali Hatamizadeh (2025). Gated Delta Networks: Improving Mamba2 with Delta Rule. ICLR.
- Liliang Ren, Yang Liu, Yadong Lu et al. (2025). Samba: Simple Hybrid State Space Models for Efficient Unlimited Context Language Modeling. ICLR.
- Opher Lieber, Barak Lenz, Hofit Bata et al. (2024). Jamba: A Hybrid Transformer-Mamba Language Model.
- NVIDIA, Aaron Blakeman, Aarti Basant et al. (2025). Nemotron-H: A Family of Accurate and Efficient Hybrid Mamba-Transformer Models.
- Dustin Wang, Rui-Jie Zhu, Steven Abreu et al. (2025). A Systematic Analysis of Hybrid Linear Attention.
- Kimi Team, Yu Zhang, Zongyu Lin et al. (2025). Kimi Linear: An Expressive, Efficient Attention Architecture.
- Gemma Team, Aishwarya Kamath, Johan Ferret et al. (2025). Gemma 3 Technical Report.
- Krishna C. Puvvada, Faisal Ladhak, Santiago Akle Serrano et al. (2025). SWAN-GPT: An Efficient and Scalable Approach for Long-Context Language Modeling.
- OpenAI, Sandhini Agarwal, Lama Ahmad et al. (2025). gpt-oss-120b & gpt-oss-20b Model Card.
- Xin Dong, Yonggan Fu, Shizhe Diao et al. (2025). Hymba: A Hybrid-head Architecture for Small Language Models. ICLR.
- Jingwei Zuo, Maksim Velikanov, Ilyas Chahed et al. (2025). Falcon-H1: A Family of Hybrid-Head Language Models Redefining Efficiency and Performance.
- Zihan Qiu, Zekun Wang, Bo Zheng et al. (2025). Gated Attention for Large Language Models: Non-linearity, Sparsity, and Attention-Sink-Free. NeurIPS.