Introduction
Linear attention replaces a growing key-value cache with a recurrent state. That state has constant size, so it scales to long sequences, but every write can overwrite information needed later. The central design problem is therefore to make the state selective, stable, and expressive while keeping a fixed state and parameter budget. Prior work explores gated linear attention, delta rules, mixtures of memories, and test-time learning [1, 2, 3, 4].
We propose SMDR, a symmetric metric delta rule with six heads spanning multiple retention horizons. The state update is surrounded by short causal convolutions, RMS-gated output normalization, and a SwiGLU block. A one-layer state carry is returned explicitly so the same mixer works for chunked training and continuation.
Method
Contractive metric update
The editable mixer projects a normalized input into queries, keys, and values. It also produces per-head erase, write, value-gate, and output-gate controls. Keys are L2-normalized and multiplied by the square root of a sigmoid metric. This turns the effective key outer product into a positive-semidefinite update. The erase gate is negative and clipped, while the write and value gates use sigmoid or affine transforms.
# ----- BEGIN EDITABLE REGION -----
class RecurrentMixer(nn.Module):
"""c40_c35_sym_metric_delta: Exact Symmetric Metric Delta Rule (k_tilde = sqrt(b_t) * L2Norm(k_t))
+ Uniform Full-Rank 1-Layer Gates (f_w, b_w, w_w, g_w) + Multi-Scale [0.64, 4096] Horizon + Pre-LN/SwiGLU.
Replaces upstream GDN-2's non-normal oblique operator I - k (b * k)^T (sigma_max > 1 -> state blowup)
with the symmetric PSD online gradient step I - k_tilde k_tilde^T on 0.5 ||S^T k_tilde - w * v||^2,
guaranteeing sigma_max <= 1.0 everywhere even at infinite decay horizon while truly freezing b_i -> 0 slots."""
owns_block = True
conv_state = (1, 2, 3)
key_dim = 768
value_dim = 768
@staticmethod
def train_recipe():
return {'lr': 0.0048}
@staticmethod
def prep(q_c, k_c, v_c, fbwg_raw, g_b, dt_bias, A_log, H: int, dk: int, dv: int, K: int, V: int):
B, T, _ = q_c.shape
f_out, b_raw, w_raw, gg_raw = fbwg_raw.split([K, K, V, V], dim=-1)
qf = q_c.float().view(B, T, H, dk)
kf = k_c.float().view(B, T, H, dk)
qh = (qf * torch.rsqrt(qf.pow(2).sum(dim=-1, keepdim=True) + 1e-6)).to(v_c.dtype)
kh_hat = kf * torch.rsqrt(kf.pow(2).sum(dim=-1, keepdim=True) + 1e-6)
b_sqrt = torch.sigmoid(b_raw.float()).view(B, T, H, dk).sqrt()
kh = (kh_hat * b_sqrt).to(v_c.dtype)
b_ones = torch.ones_like(qh)
vh = v_c.view(B, T, H, dv)
g_raw = -A_log.float().exp().view(1, 1, H, 1) * F.softplus(f_out.float() + dt_bias.float()).view(B, T, H, dk)
g = torch.clamp(g_raw, min=-5.0)
w = torch.sigmoid(w_raw.float()).view(B, T, H, dv).to(v_c.dtype)
gg = (gg_raw.float() + g_b.float()).to(v_c.dtype).view(B, T, H, dv)
return qh, kh, vh, g, b_ones, w, ggFor a head with state , normalized key , query , value , write gate , and erase gate , the update can be viewed as
The symmetric metric choice makes the erase direction align with the write key, so the state does not depend on an oblique key metric whose largest singular value can exceed one.
Multi-scale horizons and state budget
The mixer uses six heads of width 128. Their decay amplitudes are initialized across a geometric range, and each head's per-coordinate time constants are also placed on a grid. This gives short and long retention channels in the same fixed state. The state budget is declared once for each layer and multiplied by the fixed stack depth; convolution caches are accounted for separately by the harness contract.
def __init__(self, hidden_size, state_budget, layer_idx=0, n_layer=12):
super().__init__()
self.hidden_size = hidden_size
self.state_budget = state_budget
self.num_heads = 6
self.head_k_dim = 128
self.head_v_dim = 128
H, dk, dv = self.num_heads, self.head_k_dim, self.head_v_dim
K, V = self.key_dim, self.value_dim
self.norm_1 = nn.LayerNorm(hidden_size, bias=False, eps=1e-5)
self.norm_2 = nn.LayerNorm(hidden_size, bias=False, eps=1e-5)
in_std = 0.02 * 0.3194
self.qkv_w = nn.Parameter(torch.empty(K + K + V, hidden_size).normal_(0.0, in_std))
self.o_w = nn.Parameter(torch.empty(hidden_size, V).normal_(0.0, in_std))
self.q_conv1d = ShortConvolution(hidden_size=K, kernel_size=4, bias=False, activation='silu')
self.k_conv1d = ShortConvolution(hidden_size=K, kernel_size=4, bias=False, activation='silu')
self.v_conv1d = ShortConvolution(hidden_size=V, kernel_size=4, bias=False, activation='silu')
fbwg_init = torch.empty(K + K + V + V, hidden_size)
for chunk_w in fbwg_init.split([K, K, V, V], dim=0):
nn.init.xavier_uniform_(chunk_w, gain=2 ** -2.5)
self.fbwg_w = nn.Parameter(fbwg_init)
self.g_b = nn.Parameter(torch.zeros(V))
h_frac = torch.arange(H, dtype=torch.float32) / max(H - 1, 1)
A_init = 1.25 * ((16.0 / 1.25) ** h_frac)
self.A_log = nn.Parameter(torch.log(A_init))
tau_lo = torch.tensor([256.0, 64.0, 16.0, 4.0, 1.0, 0.64], dtype=torch.float32)
tau_hi = torch.tensor([4096.0, 1024.0, 256.0, 64.0, 16.0, 4.0], dtype=torch.float32)
c_frac = torch.arange(dk, dtype=torch.float32).unsqueeze(0) / max(dk - 1, 1)
tau_grid = tau_lo.unsqueeze(1) * ((tau_hi / tau_lo).unsqueeze(1) ** c_frac)
dt_grid = (1.0 / (A_init.unsqueeze(1) * tau_grid)).clamp(min=1e-5)
self.dt_bias = nn.Parameter((dt_grid + torch.log(-torch.expm1(-dt_grid))).reshape(K))
self.o_norm = FusedRMSNormGated(dv, activation='swish', eps=1e-5)The training recipe supplies a learning rate while leaving the surrounding model fixed. The mixer applies LayerNorm before its projections and a second norm before its feed-forward path. Its output is normalized with a gated RMS normalization and projected back to the residual width.
Recurrent execution and carry
The forward path caches the last convolution taps, computes the projected controls, and calls the fused gated delta kernel with the carried state. The returned state contains the recurrent tensor and the three convolution caches. The same state interface supports one-shot and split execution, while the fixed-size tensor shapes remain independent of sequence length.
def forward(self, q, k, v, x, state=None, return_state=False):
H, dk, dv = self.num_heads, self.head_k_dim, self.head_v_dim
K, V = self.key_dim, self.value_dim
s0 = state[0] if state is not None else None
u = self.norm_1(x)
q_in, k_in, v_in = F.linear(u, self.qkv_w).split([K, K, V], dim=-1)
cq0 = F.pad(state[1].to(q_in.dtype), (1, 0)) if state is not None else None
ck0 = F.pad(state[2].to(k_in.dtype), (1, 0)) if state is not None else None
cv0 = F.pad(state[3].to(v_in.dtype), (1, 0)) if state is not None else None
q_c, cq1 = self.q_conv1d(x=q_in, cache=cq0, output_final_state=return_state)
k_c, ck1 = self.k_conv1d(x=k_in, cache=ck0, output_final_state=return_state)
v_c, cv1 = self.v_conv1d(x=v_in, cache=cv0, output_final_state=return_state)
fbwg_raw = F.linear(u, self.fbwg_w)
qh, kh, vh, g, b_ones, w, gg = mixer_compile(RecurrentMixer.prep)(
q_c, k_c, v_c, fbwg_raw, self.g_b, self.dt_bias, self.A_log, H, dk, dv, K, V
)
o, s1 = chunk_gdn2(
q=qh, k=kh, v=vh, g=g, b=b_ones, w=w,
initial_state=s0, output_final_state=return_state, use_qk_l2norm_in_kernel=False,
)
o = rearrange(self.o_norm(o, gg), 'b t h d -> b t (h d)')
x_mid = x + F.linear(o, self.o_w)
gate_up = F.linear(self.norm_2(x_mid), self.mlp_gu_w)
x_out = x_mid + F.linear(mixer_compile(RecurrentMixer.swiglu)(gate_up), self.mlp_down_w)
new_state = (s1, cq1[..., 1:], ck1[..., 1:], cv1[..., 1:]) if return_state else None
return x_out, new_stateThe mixer then applies a residual output projection and a SwiGLU feed-forward block. For a sequence split into chunks, the next chunk receives the previous tuple of tensors, so only the state—not the prior token sequence—is required to continue.
Results
| Method | ① | ② | ③ | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Validation loss ↓ | WikiText-2 perplexity ↓ | LAMBADA perplexity ↓ | Long-window validation loss ↓ | Long-window tail loss ↓ | Long-window WikiText-2 loss ↓ | RULER S-NIAH-2 NLL ↓ | RULER S-NIAH-3 NLL ↓ | SQuAD answer accuracy ↑ | NIAH-1 NLL ↓ | NIAH-1 16k ↓ | |
| Gemini 4 Carbon | 3.296 | 32.38 | 41.24 | 3.242 | 3.232 | 3.415 | 3.969 | 2.905 | 18.60 | 2.586 | 6.293 |
| Linear Transformer | 3.976 | 86.42 | 68.01 | 6.423 | 8.181 | 6.288 | 8.257 | 5.434 | 3.820 | 8.202 | 10.47 |
| GLA | 3.407 | 41.98 | 44.39 | 3.358 | 3.348 | 3.698 | 6.065 | 4.208 | 14.18 | 6.600 | 7.210 |
| Gated Slot Attention | 3.406 | 41.27 | 44.65 | 3.354 | 3.342 | 3.681 | 4.791 | 3.983 | 11.33 | 3.076 | 5.355 |
| Mixture-of-Memories | 3.369 | 36.95 | 41.88 | 3.318 | 3.308 | 3.560 | 4.432 | 3.137 | 14.14 | 3.881 | 6.364 |
| Gated DeltaNet | 3.314 | 33.19 | 40.80 | 3.260 | 3.253 | 3.443 | 4.616 | 2.873 | 17.53 | 1.611 | 4.315 |
| Gated DeltaNet-2 | 3.283 | 31.63 | 39.76 | 3.230 | 3.223 | 3.392 | 4.613 | 2.886 | 19.81 | 2.981 | 5.777 |
| Kimi Delta Attention | 3.290 | 32.47 | 40.64 | 3.236 | 3.227 | 3.416 | 4.379 | 2.671 | 19.40 | 1.968 | 4.780 |
| Comba | 3.296 | 32.13 | 40.09 | 3.243 | 3.235 | 3.410 | 4.320 | 2.488 | 19.64 | 1.808 | 2.811 |
| RWKV-7 | 3.296 | 33.48 | 40.83 | 3.244 | 3.235 | 3.455 | 4.734 | 3.291 | 16.49 | 2.062 | 5.083 |
| Mamba-2 | 3.301 | 36.73 | 42.22 | 3.250 | 3.239 | 3.564 | 5.939 | 4.079 | 13.67 | 4.690 | 7.259 |
| Mamba-3 | 3.300 | 34.02 | 42.16 | 3.248 | 3.243 | 3.480 | 5.562 | 3.583 | 17.36 | 4.238 | 7.385 |
| OmegaNet | 3.402 | 39.14 | 44.87 | 3.349 | 3.339 | 3.612 | 5.282 | 3.307 | 13.34 | 2.775 | 3.648 |
| In-Place TTT | 3.400 | 40.49 | 42.25 | 3.372 | 3.407 | 4.204 | 5.262 | 3.684 | 13.64 | 8.899 | 14.51 |
| IP-TTCD | 3.443 | 46.75 | 43.61 | 6.330 | 12.14 | 4.212 | 6.414 | 4.665 | 13.14 | 6.838 | 14.92 |
| TTT-Linear | 3.416 | 39.08 | 44.01 | 3.477 | 3.657 | 3.687 | 6.012 | 4.065 | 13.34 | 2.107 | 5.414 |
| MesaNet | 3.379 | 36.09 | 44.55 | 3.326 | 3.317 | 3.526 | 4.184 | 2.871 | 16.09 | 2.603 | 5.960 |
| Mamba-3 MIMO | 3.273 | 32.60 | 40.48 | 3.220 | 3.212 | 3.430 | 4.299 | 2.774 | 18.23 | 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, SMDR improves the reported validation loss and both auxiliary perplexities relative to the linear-transformer reference: validation loss 3.296 versus 3.976, text perplexity 32.38 versus 86.42, and transfer perplexity 41.24 versus 68.01. The best published value is still lower on some columns, including text perplexity 30.79 from GDN-2, half batch.
On Long-ctx, SMDR lowers all three long-context losses against the linear-transformer reference: validation 3.242 versus 6.423, tail 3.232 versus 8.181, and auxiliary text loss 3.415 versus 6.288. The strongest recurrent baselines remain close, with the best tail loss at 3.212 from Mamba-3 MIMO [12].
Recall tests recall behavior. SMDR's NIAH-2 and NIAH-3 negative log-likelihoods are 3.969 and 2.905, compared with 8.257 and 5.434 for the linear-transformer reference. Its answer accuracy is 18.60 versus 3.820; another recurrent baseline attains the best answer accuracy 19.81 from Gated DeltaNet-2 [7].
How we got here
The submitted code comments describe the design as a replacement for an oblique delta update. The motivating failure mode is an update whose key and write metric make the state operator expand; normalizing the key and using a symmetric metric makes the erase step positive semidefinite. The code also states that the horizons are deliberately spread across heads instead of concentrating all state capacity at one timescale.
The implementation keeps short convolutions around the recurrence and uses a gated feed-forward block after the recurrent read. These choices preserve local feature mixing while the recurrent state handles longer dependencies. The forward path uses the fused delta kernel for multi-token chunks and its recurrent counterpart for a single-token continuation, so state carry is part of the design rather than a separate inference patch.
Limitations
The state is fixed and therefore cannot retain every token-level fact. The metric update can only preserve information that its six heads and 128-wide channels represent; increasing the horizon grid does not increase the state budget. A state carry also depends on the convolution caches being serialized correctly across chunk boundaries.
The symmetric update constrains the erase geometry, but it does not guarantee that the learned write and output gates select the facts needed by every task. The fixed normalization, clipping, and time-constant ranges are design choices that may be mismatched to another corpus or depth. The mixer also relies on fused kernels and their supported dtypes.
Finally, the results are mixed on recall: SMDR improves some negative log-likelihood comparisons but does not lead every answer-accuracy or recall column. Its quality gains therefore reflect a particular balance between short-context modeling, long-context loss, and fixed-state retention rather than a universal dominance over the published baselines.
References
- Songlin Yang, Bailin Wang, Yikang Shen et al. (2024). Gated Linear Attention Transformers with Hardware-Efficient Training. ICML.
- Songlin Yang, Jan Kautz, Ali Hatamizadeh (2025). Gated Delta Networks: Improving Mamba2 with Delta Rule. ICLR.
- Jusen Du, Weigao Sun, Disen Lan et al. (2026). MoM: Linear Sequence Modeling with Mixture-of-Memories. ICLR.
- Yu Sun, Xinhao Li, Karan Dalal et al. (2025). Learning to (Learn at Test Time): RNNs with Expressive Hidden States. ICML.
- Angelos Katharopoulos, Apoorv Vyas, Nikolaos Pappas et al. (2020). Transformers are RNNs: Fast Autoregressive Transformers with Linear Attention. ICML.
- Yu Zhang, Songlin Yang, Ruijie Zhu et al. (2024). Gated Slot Attention for Efficient Linear-Time Sequence Modeling. NeurIPS.
- Ali Hatamizadeh, Yejin Choi, Jan Kautz (2026). Gated DeltaNet-2: Decoupling Erase and Write in Linear Attention. NeurIPS.
- 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.
- Johannes von Oswald, Nino Scherrer, Seijin Kobayashi et al. (2026). MesaNet: Sequence Modeling by Locally Optimal Test-Time Training. ICLR.