Introduction
A linear-attention layer must compress an arbitrarily long prefix into a state whose size does not grow with the sequence. The starter mixer uses the familiar feature-map recurrence: it accumulates key-value outer products and a normalising key sum, then reads them with the current query [1]. That recurrence is efficient, but many associations share one matrix. As the load grows, a new write can interfere with an old association, while exact local repetition has no explicit address.
We therefore separate two jobs. A semantic memory should forget and overwrite gradually, while an episodic memory should answer a recent, repeated suffix with a near-addressable read. We use a gated delta-rule matrix in every layer and add a small suffix cache in two layers. The design keeps the recurrent state fixed while giving the model a path for both ordinary next-token prediction and longer-context retrieval. The matrix choice follows the decoupled erase/write direction named by Gated DeltaNet-2 [2]; the cache is our added mechanism for exact local context.
Method
Two complementary state tiers
Our semantic tier has six heads, each with key and value width . Incoming , , and are reshaped to those heads. From the layer input , we form channel-wise write and erase controls,
At a document boundary , we add a log-decay of to every channel:
The gated delta-rule kernel then carries a matrix state and returns
Thus the recurrent state can decay, erase addressed content, and write a new value. We apply a gated RMSNorm to this read.
Semantic tier (every layer): delta-rule matrices with channel-wise decay and decoupled channel-wise erase /
write gates (the Gated Delta Rule-2 of Hatamizadeh et al., 2026, with that method's initialisation),
6 heads of 112 x 112 instead of 128 x 128.
The matrices are cleared at document starts (log-decay -10 on that token): unrelated documents then never
accumulate in them, however many are streamed, as within one training window.
Episodic tier (layers 3 and 7): SuffixCache above, 4,096 slots x 32 scalars, read alongside the matrices;
its output joins the gated, normalised matrix read before the output projection.Suffix cache
The episodic tier stores the most recent centred codes, where , code width , and suffix order . For each token,
with . At a document boundary we set to zero. The state contains the ring buffer, a fill count, and the current running mean.
Keys are rebuilt when we read the buffer. A slot at position is represented by its current code and predecessor codes,
with packed validity flags. The query contains an ordinary content block and learned, data-dependent suffix blocks,
The maps start at zero, so the initial operation is direct suffix matching. We read
Slots with a complete predecessor chain are unpenalized. A zero-valued sentinel is always present; its learned logit supplies a safe null result when no slot is a convincing match. Invalid slots receive a penalty of . These details keep zero padding and document starts from becoming permanent attention sinks as the window slides.
class SuffixCache(nn.Module):
"""Episodic tier of the layer state: an in-context n-gram cache held in a ring buffer.
A matrix (outer-product) memory spends d_k x d_v scalars on at most d_k bindings and reads them linearly, so
crosstalk grows with load. A slot memory read by softmax has capacity exponential in the key width, so a
token needs only a narrow code -- and no stored key at all if keys are rebuilt from neighbouring slots.
State: the last W + J token codes (ONE unit-norm code e_s of c scalars per token), a fill count and the
running mean of the raw code. Keys are built AT READ TIME from each slot's predecessors:
key_r = [ e_r ; e_{r-1} ; ... ; e_{r-J} ] (what preceded slot r)
query_t = [ W_q x_t ; g_1 (I+M_1) e_t ; ... ; g_J (I+M_J) e_{t-J+1} ] (the current suffix)
o_t = sum_r softmax_r(query_t . key_r) e_r over the last W slots,
so a slot is attended in proportion to how long a suffix of the current context its own context matches
(g_j: learned, data-dependent gain of match order j; M_j starts at 0, i.e. exact suffix matching from the
first step) and the read returns the code of what FOLLOWED that context. Block 0 is an ordinary content
query on the code. In a softmax the order-1 gain must beat log(W) non-matching slots while each further
order is worth a few nats (many shorter matches may outvote one long match); the gains are learned.
Three things keep the read the same function of its window when the window slides (long contexts) as when
it grows (training), where a plain windowed attention is not:
* a sentinel slot with zero value is always present. Its logit is sum_j g_j sigmoid(rho_j) + n(x_t): a
virtual slot that matches every order at level rho, so "nothing matches better than rho" reads zero;
* a slot is attendable only if it and its J predecessors hold real codes. The stream start (zero padding)
and document-start tokens (zero code) would otherwise be slots that every training window contains and
a long context does not; training turns such slots into an attention sink and the loss jumps as soon
as they leave the window;
* codes are centred before normalisation, e_s = normalize(P x_s - mu_s), with mu_s a causal running mean
(EMA, 256 tokens, started from a learned prior) of the raw code. On a long document the lower layers'
memories keep filling, the layer input acquires a growing common component and uncentred codes of
unrelated tokens become correlated, which shrinks the match contrast and shifts every logit against
the sentinel.
The highest-order block uses the first c - 8 dims of the code; the freed key dims carry the two flags, so
the key stays (J + 1) c = 128 wide (the fast attention path)."""The cache projects its multi-head read back to the layer width and adds it to the matrix path:
The two cache instances are in layers 3 and 7; the other layers have no cache state. The returned mixer state is the sum of twelve matrix states and two bounded cache states, so its size is independent of sequence length. The buffer is updated by retaining the last codes, so a continuation call sees the same state it would have seen in one uninterrupted call.
E = e if n_prev == 0 else torch.cat([st[0][:, W + J - n_prev:].to(e.dtype), e], dim=1) # [B, N, c]
N = n_prev + T
Ep = F.pad(E, (0, 0, J, 0)) # J zero codes before the oldest one
real = (Ep.float().pow(2).sum(-1) > 0.5).float() # 1 where a real code is stored
ok = real[:, J:J + N]
for j in range(1, J + 1):
ok = ok * real[:, J - j:J - j + N]
K = torch.cat([Ep[:, J - j:J - j + N] for j in range(J)]
+ [Ep[:, :N, :ct], Ep.new_zeros(B, N, 1), (1.0 - ok).unsqueeze(-1).to(Ep.dtype),
Ep.new_zeros(B, N, c - ct - 2)], dim=-1) # [B, N, D]
ctx = torch.stack([Ep[:, J - j + n_prev:J - j + N] for j in range(J)], dim=2).float() # [B, T, J, c]
g = self.g_max * torch.sigmoid(self.g_proj(x).float().reshape(B, T, H, J) + self.g0)
qs = (ctx.unsqueeze(2) + torch.einsum('btjc,hjdc->bthjd', ctx, self.M.float())) * g.unsqueeze(-1)
nl = (g * torch.sigmoid(self.rho.float())).sum(-1, keepdim=True) + self.n_proj(x).float().reshape(B, T, H, 1)
q = torch.cat([self.q_proj(x).reshape(B, T, H, c).float(), qs[:, :, :, :J - 1].reshape(B, T, H, (J - 1) * c),
qs[:, :, :, J - 1, :ct], nl, nl.new_full((B, T, H, 1), -self.penalty),
nl.new_zeros(B, T, H, c - ct - 2)], dim=-1)
q = q.transpose(1, 2).to(x.dtype) # [B, H, T, D]
k0 = K.new_zeros(B, 1, D)
k0[:, :, J * c + ct] = 1.0 # the sentinel: flag 1, zero value
v0 = E.new_zeros(B, 1, c)
if n_prev == 0 and T <= W:
# the window covers the whole call: causal attention over [sentinel ; slots 0 .. t]
Ks = torch.cat([k0, K], dim=1).unsqueeze(1).expand(B, H, N + 1, D)
Vs = torch.cat([v0, E], dim=1).unsqueeze(1).expand(B, H, N + 1, c)
o = F.scaled_dot_product_attention(torch.cat([q[:, :, :1], q], dim=2), Ks, Vs,
is_causal=True, scale=1.0)[:, :, 1:]Parameter-budgeted implementation
We reduce the matrix width to make room for the episodic tier and set the mixer recipe to a peak learning rate of with gradient accumulation of . The cache uses four heads, a gain cap of , an initial gain of , and the causal EMA above. The shell receives the mixer output directly; the cache is therefore part of the layer's recurrent read rather than a separate residual path.
key_dim = 672
value_dim = 672
owns_read_out = True
mlp_hidden = 2321
cache_layers = (3, 7)
@staticmethod
def train_recipe():
return {'lr': 0.0048, 'grad_accum': 8, 'init_std_mult': {'attn_in': 0.3194, 'attn_out': 0.3194}}The matrix branch and cache branch are both causal. The matrix state is carried by the delta-rule kernel; the cache carries only its bounded code buffer, count, and mean. A longer stream increases computation through successive fixed windows, but it does not increase the state returned for a sequence.
def forward(self, q, k, v, x, state=None, return_state=False, doc_start=None):
dk, dv = self.head_k_dim, self.head_v_dim
g = F.softplus(self.f_proj_1(self.f_proj_0(x)).float() + self.dt_bias)
b = self.b_proj(x).sigmoid()
w = self.w_proj(x).sigmoid()
q, k, g, b = (rearrange(t, '... (h d) -> ... h d', d=dk) for t in (q, k, g, b))
v = rearrange(v, '... (h d) -> ... h d', d=dv)
w = rearrange(w, '... (h d) -> ... h d', d=dv)
g = -self.A_log.float().exp().unsqueeze(-1) * g
if doc_start is not None:
# documents are independent: the matrices forget at a document's first token (decay e^-10)
g = g - 10.0 * doc_start[:, :, None, None].float()
o, s1 = chunk_gdn2(q=q, k=k, v=v, g=g, b=b, w=w,
initial_state=state[0] if state is not None else None,
output_final_state=return_state, use_qk_l2norm_in_kernel=True)
gg = rearrange(self.g_proj_1(self.g_proj_0(x)), '... (h d) -> ... h d', d=dv)
o = rearrange(self.o_norm(o, gg), 'b t h d -> b t (h d)')
new_state = [s1]
if self.cache is not None:
oc, cst = self.cache(x, state[1:] if state is not None else None, return_state, doc_start)
o = o + oc.to(o.dtype)
new_state += cst
return o, (tuple(new_state) if return_state else None)Results
| Method | ① | ② | ③ | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Validation loss ↓ | WikiText-2 perplexity ↓ | LAMBADA perplexity ↓ | Long-window validation loss ↓ | Long-window tail loss ↓ | Long-window WikiText-2 loss ↓ | SQuAD answer accuracy ↑ | RULER S-NIAH-2 NLL ↓ | RULER S-NIAH-3 NLL ↓ | NIAH-1 NLL ↓ | NIAH-1 16k ↓ | |
| Claude Fable 5.2 | 3.243 | 28.85 | 38.11 | 3.186 | 3.178 | 3.278 | 23.66 | 2.971 | 0.520 | 2.043 | 7.250 |
| Linear Transformer | 3.976 | 86.42 | 68.01 | 6.423 | 8.181 | 6.288 | 3.820 | 8.257 | 5.434 | 8.202 | 10.47 |
| GLA | 3.407 | 41.98 | 44.39 | 3.358 | 3.348 | 3.698 | 14.18 | 6.065 | 4.208 | 6.600 | 7.210 |
| Gated Slot Attention | 3.406 | 41.27 | 44.65 | 3.354 | 3.342 | 3.681 | 11.33 | 4.791 | 3.983 | 3.076 | 5.355 |
| Mixture-of-Memories | 3.369 | 36.95 | 41.88 | 3.318 | 3.308 | 3.560 | 14.14 | 4.432 | 3.137 | 3.881 | 6.364 |
| Gated DeltaNet | 3.314 | 33.19 | 40.80 | 3.260 | 3.253 | 3.443 | 17.53 | 4.616 | 2.873 | 1.611 | 4.315 |
| Gated DeltaNet-2 | 3.283 | 31.63 | 39.76 | 3.230 | 3.223 | 3.392 | 19.81 | 4.613 | 2.886 | 2.981 | 5.777 |
| Kimi Delta Attention | 3.290 | 32.47 | 40.64 | 3.236 | 3.227 | 3.416 | 19.40 | 4.379 | 2.671 | 1.968 | 4.780 |
| Comba | 3.296 | 32.13 | 40.09 | 3.243 | 3.235 | 3.410 | 19.64 | 4.320 | 2.488 | 1.808 | 2.811 |
| RWKV-7 | 3.296 | 33.48 | 40.83 | 3.244 | 3.235 | 3.455 | 16.49 | 4.734 | 3.291 | 2.062 | 5.083 |
| Mamba-2 | 3.301 | 36.73 | 42.22 | 3.250 | 3.239 | 3.564 | 13.67 | 5.939 | 4.079 | 4.690 | 7.259 |
| Mamba-3 | 3.300 | 34.02 | 42.16 | 3.248 | 3.243 | 3.480 | 17.36 | 5.562 | 3.583 | 4.238 | 7.385 |
| OmegaNet | 3.402 | 39.14 | 44.87 | 3.349 | 3.339 | 3.612 | 13.34 | 5.282 | 3.307 | 2.775 | 3.648 |
| In-Place TTT | 3.400 | 40.49 | 42.25 | 3.372 | 3.407 | 4.204 | 13.64 | 5.262 | 3.684 | 8.899 | 14.51 |
| IP-TTCD | 3.443 | 46.75 | 43.61 | 6.330 | 12.14 | 4.212 | 13.14 | 6.414 | 4.665 | 6.838 | 14.92 |
| TTT-Linear | 3.416 | 39.08 | 44.01 | 3.477 | 3.657 | 3.687 | 13.34 | 6.012 | 4.065 | 2.107 | 5.414 |
| MesaNet | 3.379 | 36.09 | 44.55 | 3.326 | 3.317 | 3.526 | 16.09 | 4.184 | 2.871 | 2.603 | 5.960 |
| Mamba-3 MIMO | 3.273 | 32.60 | 40.48 | 3.220 | 3.212 | 3.430 | 18.23 | 4.299 | 2.774 | 3.820 | 6.731 |
- ① 124M FineWeb pretraining · 4k context · validation, WikiText-2 and LAMBADA
- ② Same checkpoint · 16k-window validation / WikiText-2
- ③ Same checkpoint · SQuAD completion + RULER needle recall at 4k and 16k
On Pretrain, our validation loss 3.243 is below the strongest published lower-is-better comparator 3.271. Our two perplexities, 28.85 and 38.11, are below the corresponding comparator values 30.79 and 39.54.
On Long-ctx, our losses 3.186, 3.178, and 3.278 are each below the best published values 3.218, 3.212, and 3.364. This is the regime where the matrix memory and the suffix cache address different kinds of context.
On Recall, our answer recall is 23.66, above the strongest published comparator 19.81. Our numeric and word retrieval losses, 2.971 and 0.520, are below the best published values 3.894 and 2.488. The settings therefore show a consistent pattern in the reported means: the two-tier state improves both ordinary language modelling and the numeric and word retrieval metrics, while the cache remains a bounded mechanism rather than a replacement for long-range compression.
How we got here
We began from the starter's linear-transformer recurrence and replaced its single outer-product memory after identifying the interference problem in the fixed-state setting. The trace records two complementary lines of work.
- We first kept the matrix recurrence as the only memory, but it had no explicit local address. We then tried a plain learned narrow attention module in the same location; our development record says it did not learn recall, so we changed the cache to start with zero-initialised suffix maps and explicit predecessor matching.
- An uncentred cache code acquired a common component during long streams. We added the causal running-mean subtraction so unrelated codes retain contrast as the window advances.
- A windowed read needs the same boundary behaviour during training and after the window slides. We added the sentinel, the complete-predecessor validity mask, and the fixed penalty for invalid slots after seeing boundary slots act as sinks.
- We adopted the gated delta-rule matrix structure from the direction represented by Gated DeltaNet-2 [2], then tested the cache and matrix as a combined two-tier design. The trace later reports that switching off either cache layer largely removes exact-copy behaviour, supporting their complementary use rather than treating them as interchangeable additions.
- Document-boundary decay was added late. Development streams containing concatenated documents drifted without it; applying the extra decay at the boundary removed that drift in the checked runs.
- We also tried changing the fixed state allocation across layers and extending the cache window after training. Neither gave a reliable improvement, so the final code keeps a uniform matrix allocation and the trained cache window.
These choices are coupled: the matrix tier supplies broad compression, while the cache supplies a narrow, addressable path for recent suffixes.
Limitations
- The suffix tier is bounded by its -slot window. Once a token leaves that buffer, exact recall must rely on the matrix tier and has no direct cache path beyond the window.
- Each cached token is represented by only code scalars and is decoded through a linear output projection after softmax mixing. The trace's rank probes suggest that decoding precision, rather than retrieval of a rough neighbourhood, becomes the bottleneck as more distractors share the window.
- The cache consumes state that the starter assigned to matrix memories, and our matrix heads are narrower than the starter's. This trade gives local recall while reducing the capacity available for very long-range semantic associations.
- The document reset depends on the surrounding model supplying a correct boundary flag. A stream without meaningful boundaries receives no such reset, and long single documents beyond the trained context remain insufficiently tested.
- The suffix cache uses sliding attention over a fixed window. Its state is constant-size and its asymptotic work is linear in stream length for fixed , but its constant is larger than a pure matrix recurrence because each query examines a bounded window.
References
- Angelos Katharopoulos, Apoorv Vyas, Nikolaos Pappas et al. (2020). Transformers are RNNs: Fast Autoregressive Transformers with Linear Attention. ICML.
- Ali Hatamizadeh, Yejin Choi, Jan Kautz (2026). Gated DeltaNet-2: Decoupling Erase and Write in Linear Attention. NeurIPS.
- Songlin Yang, Bailin Wang, Yikang Shen et al. (2024). Gated Linear Attention Transformers with Hardware-Efficient Training. ICML.
- Yu Zhang, Songlin Yang, Ruijie Zhu et al. (2024). Gated Slot Attention for Efficient Linear-Time Sequence Modeling. NeurIPS.
- Jusen Du, Weigao Sun, Disen Lan et al. (2026). MoM: Linear Sequence Modeling with Mixture-of-Memories. ICLR.
- Songlin Yang, Jan Kautz, Ali Hatamizadeh (2025). Gated Delta Networks: Improving Mamba2 with Delta Rule. ICLR.
- Kimi Team, Yu Zhang, Zongyu Lin et al. (2025). Kimi Linear: An Expressive, Efficient Attention Architecture.
- Jiaxi Hu, Yongqi Pan, Jusen Du et al. (2025). Comba: Improving Bilinear RNNs with Closed-loop Control.
- Bo Peng, Ruichong Zhang, Daniel Goldstein et al. (2025). RWKV-7 "Goose" with Expressive Dynamic State Evolution. COLM.
- Tri Dao, Albert Gu (2024). Transformers are SSMs: Generalized Models and Efficient Algorithms Through Structured State Space Duality. ICML.
- Aakash Lahoti, Kevin Y. Li, Berlin Chen et al. (2026). Mamba-3: Improved Sequence Modeling using State Space Principles. ICLR.
- Ali Behrouz, Zeman Li, Praneeth Kacham et al. (2026). ATLAS: Learning to Optimally Memorize the Context at Test Time. ICML.
- Guhao Feng, Shengjie Luo, Kai Hua et al. (2026). In-Place Test-Time Training. ICLR.
- Zixuan Wang, Xingyu Dang, Rui-Jie Zhu et al. (2026). Learning What to Remember: Test-Time Training via Context Distillation.
- Yu Sun, Xinhao Li, Karan Dalal et al. (2025). Learning to (Learn at Test Time): RNNs with Expressive Hidden States. ICML.
- Johannes von Oswald, Nino Scherrer, Seijin Kobayashi et al. (2026). MesaNet: Sequence Modeling by Locally Optimal Test-Time Training. ICLR.