The Delta Rule

Dive into Deep Learning · §12.7

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 \to rate = 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:

\mathbf{S}\mathbf{k} = \mathbf{v}^{(1)} + \mathbf{v}^{(2)} + \cdots + \mathbf{v}^{(R)}

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

Read Before Writing

\ell_t(\mathbf{S}) = \tfrac{1}{2}\,\|\mathbf{S}\mathbf{k}_t - \mathbf{v}_t\|^2 \implies \mathbf{S}_t = \mathbf{S}_{t-1} + \beta_t(\mathbf{v}_t - \mathbf{S}_{t-1}\mathbf{k}_t)\mathbf{k}_t^\top

  • Read Before Writing: Reads prediction \hat{\mathbf{v}}_t = \mathbf{S}_{t-1}\mathbf{k}_t first, then writes the scaled error residual \beta_t(\mathbf{v}_t - \hat{\mathbf{v}}_t)\mathbf{k}_t^\top.
  • Exact Replacement at \beta_t = 1: For \|\mathbf{k}_t\| = 1, \mathbf{S}_t \mathbf{k}_t = \mathbf{v}_t in one step.

Projection Geometry of the Delta Transition Matrix

Directional Erasure

Factoring \mathbf{S}_{t-1} out of the delta update reveals the right-multiplied state transition matrix:

\mathbf{S}_t = \mathbf{S}_{t-1}(\mathbf{I} - \beta_t \mathbf{k}_t \mathbf{k}_t^\top) + \beta_t \mathbf{v}_t \mathbf{k}_t^\top

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:

  • \beta_t = 0: Identity \mathbf{I} (memory untouched).
  • \beta_t \in (0, 1): Partial contraction along \mathbf{k}_t.
  • \beta_t = 1: Orthogonal projection \mathbf{I} - \mathbf{k}_t\mathbf{k}_t^\top (erases \mathbf{k}_t completely before writing \mathbf{v}_t \mathbf{k}_t^\top).
  • \beta_t = 2: Householder reflection \mathbf{I} - 2\mathbf{k}_t\mathbf{k}_t^\top (eigenvalue -1, reversing sign 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.
  • Negative Eigenvalues Unlock Parity: Positive decays a_t > 0 cannot count modulo 2; at \beta_t = 2, Householder reflection (\lambda_{\mathbf{k}} = -1) toggles readout \mathbf{0} \leftrightarrow 2\mathbf{v}.

The Hidden Cost of Correction: Signal Erosion

Crowded Random Keys

\mathbb{E}[\mathbf{S}_t \mathbf{k}_i] = \Big(1 - \frac{1}{d_k}\Big)^m \mathbf{v}_i \approx e^{-m / d_k}\mathbf{v}_i

  • 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:

squared read error                  additive   delta, β = 1 delta, β = 0.5  least squares
8 orthonormal keys, 4 writes            2.98           0.00           0.33           0.74
32 keys                                 0.49           0.29           0.37           0.00
64 keys                                 0.98           0.60           0.49           0.00
128 keys                                1.99           1.06           0.67           0.50
256 keys                                3.94           1.49           0.89           0.75
64 keys, ρ = 0.5                        5.82           0.76           0.61           0.00
recall                              additive   delta, β = 1 delta, β = 0.5  least squares
8 orthonormal keys, 4 writes            0.28           1.00           1.00           0.28
32 keys                                 1.00           1.00           1.00           1.00
64 keys                                 1.00           0.89           0.99           1.00
128 keys                                0.96           0.53           0.82           1.00
256 keys                                0.73           0.26           0.45           0.86
64 keys, ρ = 0.5                        0.54           0.77           0.89           1.00

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):

  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).
  2. 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).
  3. 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

The Gated DeltaNet Recurrence

\mathbf{S}_t = a_t\,\mathbf{S}_{t-1}(\mathbf{I} - \beta_t \mathbf{k}_t \mathbf{k}_t^\top) + \beta_t \mathbf{v}_t \mathbf{k}_t^\top

  • Three Operating Modes (Yang et al., 2024):
    1. Global Flush (a_t \to 0): Wipes the entire matrix at topic boundaries.
    2. Targeted Key Update (a_t \approx 1, \beta_t \to 1): Overwrites \mathbf{k}_t while preserving \mathbf{k}_t^\perp.
    3. Gentle Accumulation (a_t \approx 1, \beta_t \approx 0.2): Low-erosion associative write.

Chunked Evaluation via Lower-Triangular Solve (WY Form)

Intra-Chunk Triangular System

\mathbf{u}_t + \beta_t \sum_{s < t} L_{ts}\,(\mathbf{k}_s^\top \mathbf{k}_t)\,\mathbf{u}_s = \beta_t\big(\mathbf{v}_t - \gamma_t \mathbf{S}_0 \mathbf{k}_t\big)

  • 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:

\mathbf{S}_m = \mathbf{S}_0\,\underbrace{(\gamma_m \mathbf{I} - \mathbf{Z}^\top \mathbf{D}\mathbf{K})}_{\mathbf{A}^{(c)} \in \mathbb{R}^{d_k \times d_k}} + \mathbf{W}^\top \mathbf{D}\mathbf{K}

  • Balanced complexity: Composing \mathbf{A}^{(c)} across T/m chunks costs (T/m)d_k^3 FLOPs—matching the O(T d_k^2) intra-chunk GEMMs whenever chunk size m \approx d_k.
chunk size 16: relative deviation 2.1e-07
chunk size 64: relative deviation 3.1e-07

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.

The Implicit Proximal Delta Step (Longhorn)

Unconditional Stability Without Key Normalization

\mathbf{S}_t = \mathbf{S}_{t-1} + \frac{\beta_t}{1 + \beta_t \|\mathbf{k}_t\|^2}\,(\mathbf{v}_t - \mathbf{S}_{t-1}\mathbf{k}_t)\mathbf{k}_t^\top

  • 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

Test-Time Regression View

\min_{\mathbf{S} \in \mathbb{R}^{d_v \times d_k}} \sum_{s=1}^{t} \tfrac{1}{2}\,\|\mathbf{S}\mathbf{k}_s - \mathbf{v}_s\|^2

  • 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) Carried State
Linear Attention Unnormalized cross-moment \mathbf{V}_t^\top \mathbf{K}_t (omits (\mathbf{K}_t^\top\mathbf{K}_t)^{-1}) \mathbf{S}_t = \mathbf{S}_{t-1} + \mathbf{v}_t \mathbf{k}_t^\top d_v \times d_k
Gated Linear Attention Exponentially weighted cross-moment \mathbf{S}_t = a_t \mathbf{S}_{t-1} + \mathbf{v}_t \mathbf{k}_t^\top d_v \times d_k
DeltaNet Online SGD on \frac{1}{2}\|\mathbf{S}\mathbf{k}_t - \mathbf{v}_t\|^2 \mathbf{S}_t = \mathbf{S}_{t-1} + \beta_t(\mathbf{v}_t - \mathbf{S}_{t-1}\mathbf{k}_t)\mathbf{k}_t^\top d_v \times d_k
Gated DeltaNet Online SGD with weight decay a_t \in (0, 1) \mathbf{S}_t = a_t\mathbf{S}_{t-1}(\mathbf{I} - \beta_t\mathbf{k}_t\mathbf{k}_t^\top) + \beta_t\mathbf{v}_t\mathbf{k}_t^\top d_v \times d_k
Longhorn (Implicit Step) Proximal step \min_{\mathbf{S}} \frac{1}{2}\|\mathbf{S} - \mathbf{S}_{t-1}\|^2 + \frac{\beta_t}{2}\|\mathbf{S}\mathbf{k}_t - \mathbf{v}_t\|^2 Delta rule with normalized step \frac{\beta_t}{1 + \beta_t\|\mathbf{k}_t\|^2} d_v \times d_k
Recursive Least Squares Exact ridge regression \mathbf{V}_t^\top\mathbf{K}_t(\mathbf{K}_t^\top\mathbf{K}_t + \lambda\mathbf{I})^{-1} 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:

  1. 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?
  2. 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?
  3. 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?

Answers:

  1. \mathbf{S}_t \mathbf{k}_t = (1 - 0.5)\hat{\mathbf{v}}_t + 0.5\mathbf{v}_t = \mathbf{\tfrac{1}{2}(\hat{\mathbf{v}}_t + \mathbf{v}_t)} (halfway blend); for \mathbf{q} \perp \mathbf{k}_t, \mathbf{k}_t^\top \mathbf{q} = 0, so \mathbf{S}_t \mathbf{q} = \mathbf{\mathbf{S}_{t-1}\mathbf{q}} (completely unchanged).
  2. 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.
  3. 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).

Summary: The Delta Rule and Gated DeltaNet

Key Takeaways

Concept / Component Mathematical Form Key Capability & Trade-Off
The Delta Rule \mathbf{S}_t = \mathbf{S}_{t-1} + \beta_t(\mathbf{v}_t - \mathbf{S}_{t-1}\mathbf{k}_t)\mathbf{k}_t^\top Online gradient step on \frac{1}{2}\|\mathbf{S}\mathbf{k}_t - \mathbf{v}_t\|^2; reads before writing
Transition Geometry \mathbf{I} - \beta_t \mathbf{k}_t \mathbf{k}_t^\top (\|\mathbf{k}_t\| = 1) Eigenvalue 1 on \mathbf{k}_t^\perp, 1 - \beta_t along \mathbf{k}_t (projection at \beta=1, reflection at \beta=2)
Signal Erosion Cost (1 - 1/d_k)^m \approx e^{-m/d_k} after m random writes Aggressive \beta_t = 1 erodes early overlapping keys; learned \beta_t \in (0, 1) balances both
Gated DeltaNet \mathbf{S}_t = a_t\mathbf{S}_{t-1}(\mathbf{I} - \beta_t\mathbf{k}_t\mathbf{k}_t^\top) + \beta_t\mathbf{v}_t\mathbf{k}_t^\top Combines global head decay a_t with targeted key overwriting \beta_t (0.96+ on rebinding)
Chunked WY Algorithm Triangular solve \mathbf{M}\mathbf{W}, \mathbf{M}\mathbf{Z} + chunk scan Evaluates d_k \times d_k matrix transitions in O(T d_k^2) work via parallel Tensor Core GEMMs