The Delta Rule and Gated DeltaNet read-before-write error correction · Householder projection geometry · chunked WY triangular solve · memory as online regression
Why Additive Matrix Memories Fail on Rebound Keys
Motivation
Programs and narratives constantly update state (rate = 0.05\torate = 0.07, or a character travelling from Paris to Rome). When a unit key \mathbf{k} is written R times with values \mathbf{v}^{(1)}, \ldots, \mathbf{v}^{(R)}, an additive memory returns their unweighted superposition:
Testing 8 mutually orthonormal keys in \mathbb{R}^{64} (zero cross-key interference) written R \in \{1, 2, 4, 8\} times each:
additive: 1.00 0.51 0.27 0.21
Even with 8\times more dimensions than keys, additive recall of the latest value collapses to a coin toss (0.51) at R = 2 and 0.21 at R = 8. Global decay a_t < 1 fades old values only by aging all keys indiscriminately.
The Delta Rule: One Online Gradient Step on Recall Loss
For a unit key \|\mathbf{k}_t\| = 1, \mathbf{I} - \beta_t \mathbf{k}_t \mathbf{k}_t^\top has eigenvalue 1 on the (d_k - 1)-dimensional subspace \mathbf{k}_t^\perp and eigenvalue 1 - \beta_t along \mathbf{k}_t:
Unit-Key Stability and Householder Parity Reflections
Spectral Properties
Mandatory Key \ell_2-Normalization: Along \mathbf{k}_t, eigenvalue \lambda_{\mathbf{k}} = 1 - \beta_t\|\mathbf{k}_t\|^2 stays in [-1, 1] for \beta_t \in [0, 2] only when \|\mathbf{k}_t\| = 1.
Collateral Contraction: Every later random unit key \mathbf{k}_s has expected squared overlap 1/d_k with \mathbf{k}_i, shrinking \mathbf{v}_i by 1 - 1/d_k per step.
Crowded Decay: After m = 2d_k random writes with \beta = 1, early signals erode to e^{-2} \approx 13.5\%.
Benchmarking Four Write Rules Across Three Regimes
Additive vs. Delta vs. Least Squares
Comparing additive, delta, β = 1, delta, β = 0.5, and offline least squares(\mathbf{S}^\star = \mathbf{V}^\top \mathbf{K}(\mathbf{K}^\top \mathbf{K})^+, fitting all pairs simultaneously) at width d = 64:
When Targeted Erasure Helps—and Why βt Must Be Learned
Interpreting the Write-Rule Table
The benchmark exposes three distinct regimes that motivate learning an input-dependent gate \beta_t \in (0, 1):
Key rebinding (8 orthonormal keys, 4 writes):delta(\beta = 1 or 0.5) achieves 1.00 recall of the latest value, whereas additive and unweighted least squares average all 4 values bound to each key (0.28).
Correlated keys (64 keys, ρ = 0.5):additive piles every value onto the shared key direction (error 5.82, recall 0.54), whereas delta subtracts the shared-direction prediction before writing (recall 0.89 at \beta = 0.5).
Crowded independent keys (128 keys,256 keys): At n = 128, delta, β = 1 has lower squared error than additive(1.06 vs. 1.99) yet worse recall (0.53 vs. 0.96) because shrinking old reads toward \mathbf{0} caps squared error near \|\mathbf{0} - \mathbf{v}_j\|^2 = 1 while eroding early signals. Halving the step to \beta = 0.5 restores 0.82 recall with 0.67 squared error.
Gated DeltaNet: Global Decay Plus Targeted Overwriting
WY Representation: Rewrites the delta recurrence as \mathbf{S}_t = a_t \mathbf{S}_{t-1} + \mathbf{u}_t \mathbf{k}_t^\top with corrected values \mathbf{u}_t.
Parallel m \times m Triangular Solve: Solves \mathbf{M}\mathbf{W} = \boldsymbol{\beta} \odot \mathbf{V} and \mathbf{M}\mathbf{Z} = (\boldsymbol{\beta} \odot \boldsymbol{\gamma}) \odot \mathbf{K} across all chunks in parallel to obtain \mathbf{U} = \mathbf{W} - \mathbf{Z}\mathbf{S}_0^\top.
Inter-Chunk Matrix Scan and Numerical Verification
Chunked Algorithm Verified
Substituting \mathbf{U} = \mathbf{W} - \mathbf{Z}\mathbf{S}_0^\top into the chunk-end state yields an affine matrix recurrence across the T/m chunks:
Implementing GatedDeltaNet as a Drop-In GLA Subclass
Clean Object-Oriented Design
Because GatedLinearAttention (§12.6) isolated its state recurrence inside memory(X, Q, K, V, log_a), GatedDeltaNet adds just one linear projection W_beta(d \to h) and overrides memory:
class GatedDeltaNet(d2l.GatedLinearAttention):"""Gated linear attention whose memory is written by the delta rule."""def__init__(self, num_hiddens, num_heads, chunk_size=32, conv_width=4, timescales=(4, 256)):super().__init__(num_hiddens, num_heads, chunk_size, conv_width, timescales)self.W_beta = nn.Linear(num_hiddens, num_heads) # Write strength d2l.init_lecun(self.W_beta)def memory(self, X, Q, K, V, log_a): beta = d2l.heads_to_batch(torch.sigmoid(self.W_beta(X)),self.num_heads).squeeze(-1)return chunked_delta_rule(Q, K, V, beta, log_a, self.chunk_size)
Every other component (width-4 causal convolution, \ell_2-normalized queries and keys, log-uniform head decay initialization, per-head RMSNorm, and SiLU output gating) is inherited unchanged.
Key Rebinding Experiment: Short-Gap Overwrites
Rebinding Benchmark Results
We compare a 1-block GatedLinearAttention model against a 1-block GatedDeltaNet model (d = 64,4 heads of 16 \times 16) on 16-pair associative recall where 8 of the 16 keys are rebound to a new value just gap=2 writes after their initial binding:
parameters written twice written once
gated linear attention 73,941 0.929 0.859 0.977 0.968
Gated DeltaNet 74,201 0.965 0.969 0.978 0.986
Why gap=2 isolates the delta rule: When a key is overwritten just 2 pairs after it was first bound, both bindings have nearly the same age—so global decay a_t cannot fade the old value without also erasing keys written once prior to that step.
Reliable overwriting: Adding the 260-parameter W_beta projection lifts rebound-key accuracy to 0.96 or more across runs, ahead of GatedLinearAttention (about 0.9) and within about 2 points of single-write accuracy.
Why We Tested 1 Block: Depth Approximates a Delta Step
Multi-Layer Interaction
Two Additive Layers Emulate One Delta Step: Block 1 (GLA) can query \hat{\mathbf{v}}_t = \mathbf{S}_{t-1}^{(1)}\mathbf{k}_t into the residual stream so Block 2 (GLA) writes (\mathbf{v}_t - \hat{\mathbf{v}}_t)\mathbf{k}_t^\top.
Why In-Layer Delta Wins:GatedDeltaNet performs read-before-write inside every single layer for arbitrary rebindings R, freeing deeper layers for reasoning.
Implicit Proximal Objective (Liu et al., 2024): Minimizes \frac{1}{2}\|\mathbf{S} - \mathbf{S}_{t-1}\|_F^2 + \frac{\beta_t}{2}\|\mathbf{S}\mathbf{k}_t - \mathbf{v}_t\|^2 at the new state \mathbf{S}_t.
Unconditional Stability: Directional eigenvalue \frac{1}{1 + \beta_t\|\mathbf{k}_t\|^2} \in (0, 1) for any \|\mathbf{k}_t\| and \beta_t > 0.
Unifying Sequence Mixers as Online Regression Solvers
Fast Weights (\mathbf{S}_t): Solve an in-context linear regression \mathbf{S}_t \mathbf{k}_s \approx \mathbf{v}_s across tokens 1\ldots t during the forward pass.
Slow Weights (\theta): Trained by outer-loop AdamW to shape (\mathbf{q}_t, \mathbf{k}_t, \mathbf{v}_t, a_t, \beta_t).
Taxonomy of Sequence Memories as Regression Algorithms
The Regression Table
Sequence Memory
In-Context Regression Objective / Estimator
Online Update per Token Pair (\mathbf{k}_t, \mathbf{v}_t)
Sherman–Morrison update along \mathbf{P}_t\mathbf{k}_t
d_v d_k + d_k^2
Softmax Attention
Nonparametric Nadaraya–Watson kernel regression
Appends (\mathbf{k}_t, \mathbf{v}_t) to cache; evaluates at query time
t \times (d_k + d_v)
Concept Check: Delta Transitions and Chunked Solves
Check Your Understanding
Test your mastery of the delta rule with these three questions:
Suppose \mathbf{S}_{t-1}\mathbf{k}_t = \hat{\mathbf{v}}_t. If we apply the delta rule with a unit key \|\mathbf{k}_t\| = 1 and write strength \beta_t = 0.5, what does an immediate readout \mathbf{S}_t \mathbf{k}_t return, and what happens to \mathbf{S}_t \mathbf{q} for any query \mathbf{q} \perp \mathbf{k}_t?
Why does the implicit proximal update (Longhorn) replace \beta_t with \tilde{\beta}_t = \beta_t / (1 + \beta_t\|\mathbf{k}_t\|^2), and why can’t an implicit step compute exact parity?
In chunked_delta_rule, why is the intra-chunk system matrix \mathbf{M} = \mathbf{I} + \textrm{diag}(\boldsymbol{\beta})\,\textrm{tril}_{-1}(\mathbf{L} \odot \mathbf{K}\mathbf{K}^\top) unit lower-triangular?
Solving \mathbf{S} - \mathbf{S}_{t-1} + \beta_t(\mathbf{S}\mathbf{k}_t - \mathbf{v}_t)\mathbf{k}_t^\top = \mathbf{0} uses the post-update prediction \mathbf{S}\mathbf{k}_t, yielding directional eigenvalue 1 - \tilde{\beta}_t\|\mathbf{k}_t\|^2 = \frac{1}{1 + \beta_t\|\mathbf{k}_t\|^2} \in (0, 1) for all \beta_t > 0—preventing overshoot without key normalization, but excluding negative eigenvalues (\lambda = -1) needed for parity reflections.
Because causality ensures the corrected value \mathbf{u}_t at step t depends only on earlier writes s < t within the chunk (\textrm{tril}_{-1} has zeros on and above the diagonal, so \mathbf{M} has 1s on the diagonal).