Delete the softmax from attention and a 1991 memory appears: one fixed matrix that every token writes into. The plain write rule cannot overwrite, so its recall decays. The delta rule corrects before it writes. At 1.3B parameters, DeltaNet matches a Transformer on WikiText perplexity: 16.87 against 16.85.
Pick a write rule and press Play. A stream of 48 tokens writes key and value pairs into an 8 by 4 memory, and keys come back with new values. Each bar is the recall error for one key. Then try 12 keys. Then we build, piece by piece, linear attention, the fast weight memory, its capacity limit, the delta rule and the chunk trick that trains it fast.
You need attention as softmax(QKT)V and a matrix times a vector. We build the rest from zero.
Session 17 of Georgia Tech CS 8803, LLM seminar. It rests on two papers: Schlag, Irie and Schmidhuber, Linear Transformers Are Secretly Fast Weight Programmers (ICML 2021), and Yang, Wang, Zhang, Shen and Kim, Parallelizing Linear Transformers with the Delta Rule over Sequence Length (NeurIPS 2024). Every idea is re-taught here in our own words and devices.
Toy, run live: keys live in 8 dimensions, values in 4. The first 8 keys are orthogonal; keys 9 to 16 are random unit vectors, so they cannot be. Error is the distance from the latest value, in units of a value's length. The paper's version of this test is its Setting 2 (Figure 3), where the sum rule fails to learn and the delta rule wins.
Chapter 0
See why attention gets slower with every token, and where a fixed-size memory wins
A chatbot is 100,000 tokens into a long session. To write token 100,001, its attention layer compares the new token with every one of the 100,000 tokens before it. The next token compares with one more. The work per token never stops growing.
Each token makes three vectors. Its query asks what it needs. Each past token's key says what it holds, and its value is what it hands over. Call the sequence length L and the width of these vectors d. One comparison is a dot product of d numbers.
Token number L compares with about L keys. Add that up over the whole sequence and you get about L²/2 comparisons. Double the length and the attention work goes up four times.
This lesson builds a different layer. It keeps one d by d matrix as its whole memory. Each token updates the matrix once, at a cost of about d², whatever L is. Which is cheaper? Compare the two costs.
L squared d, over L d squared, equals L over d.
Divide the sequence length L by the width d. If L is smaller than d, keep softmax attention. If L is larger, the fixed memory does L / d times less attention work.
Llama-2-7B has d = 4,096. At L = 512, L / d = 0.125, so full attention is 8 times cheaper. At L = 16,384, L / d = 4: 1.10 × 1012 against 2.75 × 1011. The crossover sits at L = d.
The purple bar is full attention's L²d. The teal bar is the fixed memory's Ld². Drag the length and watch which bar wins.
Counts of multiply-adds for the attention part only, constants dropped. The bars use a log scale, so each grid step is 10 times more work.
Generation asks a second question: what does one more token cost after L tokens? Full attention pays about Ld for that token. The fixed memory pays d², at token 10 and at token 10 million.
| Cost | Full attention | Fixed memory |
|---|---|---|
| Whole sequence (training) | L²d | Ld² |
| One more token (generation) | Ld, grows forever | d², fixed |
| Memory kept | every key and value | one d by d matrix |
At L = 100,000 and d = 4,096, one token costs 409,600,000 under full attention and 16,777,216 under the fixed memory: 24.4 times less, which is L / d again.
Failure. A team quotes "977 times faster" for a whole model. Measure: profile the full layer. The feed-forward block costs about Ld² with either kind of attention. Fix: apply L / d only to the attention share of the time.
Chapter 1
Remove one function and turn "compare with everything" into "update a running matrix"
Softmax attention gives token i the output oi: a weighted average of all past values vj. The weight of value j is exp(kj · qi), divided by the sum of all such weights. The exponential is the problem. It ties each key to the query, so you must redo the whole sum for every new query.
Replace exp(k · q) with a plain product of features, φ(k)Tφ(q). Take the simplest case: φ is the identity and we drop the division. The output becomes oi = Σj vj (kj · qi). The query is the same in every term, so you can move it out of the sum: oi = (Σj vjkjT) qi. That move is associativity: you may regroup a product without changing its result.
The sum in brackets does not depend on the query. Give it a name: the state Si, a dv by dk matrix. Here dv is the value width and dk the key width. A running sum grows by one term per token.
S-i equals S-i-minus-one, plus v-i times k-i transpose.
For each new token, multiply its value v-i by its key k-i to make a matrix. Add that matrix to the state. To answer, multiply the state S-i by the query q-i.
Made-up tokens: k1 = (1, 0), v1 = (2, 0); k2 = (0, 1), v2 = (0, 3); k3 = (1, 1), v3 = (1, 1). After three steps S3 = [[3, 1], [1, 4]]. With q3 = (1, 1), o3 = (3 + 1, 1 + 4) = (4, 5).
Left: the state matrix grows by one outer product per step. Right: the same output as a weighted sum of values, no state. Press Step.
The made-up three-token example above, with the query fixed at (1, 1). Identity features, no normalization.
The parallel form is the right panel done for all tokens at once: O = (QKT ⊙ M)V, where M is the causal mask that zeroes future tokens. Training uses the parallel form, one big matrix product. Generation uses the recurrent form, one small update per token. Both give the same numbers.
pythonimport torch def full_attention_step(q, K, V): # K, V: (i, d), every past token return torch.softmax(K @ q, 0) @ V # i comparisons, more each step def linear_attention_step(q, k, v, S): # S: (d_v, d_k), fixed size S = S + torch.outer(v, k) # write: one outer product return S @ q, S # read: one matrix times vector
Failure. Training runs the recurrent loop token by token and the GPU sits mostly idle. Measure: GPU use during training. Fix: train with the parallel or chunked form. Chapter 6 shows why this fix breaks for the delta rule.
Chapter 2
Recognize the state S as a memory that one network writes for another
In a normal network, the weights stop changing after training. In 1991, Schmidhuber proposed a pair of networks. A slow net, trained by gradient descent, writes the weights of a fast net while the input streams in. The fast weights change at every step. The 2021 paper calls this a Fast Weight Programmer (FWP).
The write instruction is an outer product. At step i the slow net makes two vectors from the input x(i): a(i) and b(i). Call the fast weight matrix W(i).
W-i equals sigma of W-i-minus-one plus a-i outer b-i; and y-i equals W-i times x-i.
The slow net turns the input x-i into a and b. It adds a times b to the fast weights W. The fast net then multiplies W by x-i to give y-i.
With made-up numbers and σ the identity: write a = (5, 2) with b = (1, 0), then a = (3, 7) with b = (0, 1). W = [[5, 3], [2, 7]]. Read with x = (1, 0): y = (5, 2), the first stored value.
Set σ to the identity and rename a to v, b to k and x to q. You get Chapter 1's Si = Si−1 + vikiT and oi = Siqi, term for term. The keys and values are the slow net's write instructions. Linear attention makes q, k and v with three separate projections of x, but the memory is the same.
Two keys sit at 0° and 90°, holding (5, 2) and (3, 7). Turn the query and watch the read-out move between the two values.
The made-up memory W = [[5, 3], [2, 7]] from the worked example. The query is a unit vector.
Why is recall exact here? The read is W ki = Σj vj(kj · ki). If the keys are orthonormal (unit length, at right angles), every dot product is 0 except ki · ki = 1. Only vi survives. A query halfway between, (0.5, 0.5), returns (4, 4.5): half of each value.
pythonW = torch.outer(v1, k1) + torch.outer(v2, k2) # [[5,3],[2,7]], value first, key second print(W @ k1, W @ k2) # (5,2) and (3,7): exact recall
Failure. The code writes torch.outer(k, v) and every recall comes back wrong. Measure: store one pair and read it back by hand. Fix: value first, key second, so W has shape dv by dk.
Chapter 3
Count how many clean keys a d-dimensional memory can hold, and what leaks past that
A flat plane has two directions at right angles and no third. In general, a space of d dimensions holds at most d orthogonal vectors. So a memory with d-dimensional keys can store at most d associations without overlap. The paper calls the space where keys meet queries ddot.
Store one more key and it must overlap some earlier key. When you read with it, the overlapping values leak in. The paper calls the leak crosstalk, a term from Smolensky's 1990 theory of tensor product representations. Take a key ki of unit length and write the read in two parts.
W k-i equals v-i, plus the sum over j not equal to i of v-j times k-j dot k-i.
Read with k-i. You get the stored value v-i. Then for every other pair, you also get v-j scaled by its key overlap with k-i. That second part is the crosstalk.
Made-up: Chapter 2's memory plus k3 = (0.6, 0.8), v3 = (9, 1). Read with k3: (9, 1) + 0.6 × (5, 2) + 0.8 × (3, 7) = (14.4, 7.8), not (9, 1). Read with k1: (5, 2) + 0.6 × (9, 1) = (10.4, 2.6). The old pair broke too.
Each curve is the average recall error after the sum rule writes N pairs. Teal keys stay orthogonal while they can. Blue keys are random. Drag N past 16.
Toy, computed live: unit keys, unit values, ddot = 16. The curves are the average of 20 random draws. A trained model learns its keys; this toy does not.
The paper ran this test with trained models (Section 6.1.1, Figure 2). Keys had dkey = 64; the number of pairs S went from 20 to 600.
| Feature map φ | ddot | Where recall errors start |
|---|---|---|
| Linear attention (identity) | 64 | at about 60 pairs |
| DPFP, ν = 1, 2, 3 | 128, 256, 384 | near each limit |
| FAVOR+ (random features) | 2m | never reaches zero loss |
| Softmax (KV cache) | no fixed limit | struggles past 500 keys |
The paper's DPFP (deterministic parameter-free projection) buys room with more dimensions. In 2D it makes four features, one per quadrant, such as max(0, k1) · max(0, k2). Keys in different quadrants land on different features, so they become orthogonal. In general ddot = 2dkeyν.
Failure. On long text without a cut-off, a sum-rule model's perplexity explodes. Measure: recall error against the number of stored pairs. Fix: a bigger ddot moves the wall; a better write rule (Chapter 4) manages what stays inside it.
Chapter 4
Read what a key holds now, then write only the difference
The sum rule only adds. It cannot remove an old value, so a full memory only gets muddier. The 2021 paper borrows a fix from 1960: the error-correcting delta rule of Widrow and Hoff. At every token it does three steps.
Here β is the write strength, between 0 and 1. The model makes it per token: β = σ(Wβx), a sigmoid of a learned projection. Put step 2 into step 3 and the terms combine.
W-i equals W-i-minus-one, plus beta-i times the bracket v-i minus W-i-minus-one k-i, times k-i transpose.
Read what key k-i holds now. Subtract it from the target v-i. Scale that error by beta-i, and add it back along k-i. If the memory already holds v-i, nothing changes.
Made-up: W = [[5, 3], [2, 7]], k = (1, 0), target (11, 4), β = 0.8. Read: (5, 2). Error: (6, 2). Write 0.8 × (6, 2) = (4.8, 1.6) into column 1: W = [[9.8, 3], [3.6, 7]]. Key 1 now gives (9.8, 3.6). Key 2 still gives (3, 7).
The memory holds (5, 2) at key 1 and (3, 7) at key 2. We write (11, 4) at key 1. Pick a rule, move β, and read both keys.
Made-up 2 by 2 memory. Gated decay is W' = (1 − β)W + βvkT, the family of the gated update rule the paper compares in its Appendix B. The sum rule ignores β.
| Rule, β = 0.8 | Key 1 reads | Key 2 reads |
|---|---|---|
| Sum rule | (16, 6): old plus new | (3, 7) |
| Gated decay | (9.8, 3.6) | (0.6, 1.4): shrunk for no reason |
| Delta rule | (9.8, 3.6) | (3, 7): untouched |
The 2024 paper gives a second reading. The delta rule is one step of gradient descent, with learning rate β, on the loss ½‖Wk − v‖². The memory learns, at test time, to map this key to this value.
Failure. Take Chapter 3's broken memory and repair key 1 with β = 1. Key 1 returns (5, 2) again. Key 2 still returns (10.2, 7.8), not (3, 7). Measure: read every key, not only the one you wrote. Fix: none inside the rule; a key heals only when a token writes to it.
Chapter 5
Test the delta rule on WikiText-103 and on text with no cut-off
The paper calls a linear Transformer with the delta rule a Delta Network; the 2024 paper shortens it to DeltaNet. Before the results, one detail decides whether it trains at all: how it scales the keys.
Without any scaling, the models diverged. The paper divides each key and query feature vector by the sum of its own entries. Call the feature vector φ(k) and its j-th entry φ(k)j.
Phi-prime of k equals phi of k, divided by the sum over j of phi of k, entry j.
Add up the entries of the feature vector phi of k. Divide each entry by that total. A read with phi-prime is then a weighted average of the memory's columns.
Made-up: φ(k) = (3, 1). The sum is 4, so φ′(k) = (0.75, 0.25), and 0.75 + 0.25 = 1. The paper's Appendix A.2 shows this balances the write and remove terms of the delta rule.
The paper trained 16-layer models on WikiText-103, long Wikipedia articles of about 3,600 words each. Both sizes run past capacity on purpose. Small: model width D = 128 over 8 heads gives ddot = 16 at context L = 256, so 16 times over. Medium: ddot = 32 at L = 384, 12 times over.
Lower perplexity is better. Pick a table. The last one runs over the whole text with no cut-off, so a fixed memory must last.
Test perplexities from the paper (arXiv 2102.11174v3), Tables 2 and 4. Table 4 lists the state size in millions of numbers. "> 260" is drawn at 260.
The delta rule closes two thirds of the gap to softmax at small size (38.3 to 35.5, against 34.1) and 44% at medium size (33.0 to 31.5, against 29.6). In bits, the medium gain is log2(33.0 / 31.5) = 0.067 bits per word. With no cut-off, the sum rule breaks (> 260) and the Delta Network reaches 29.4. A Transformer-XL with the same 0.13M state gets 65.5. The cost is small: 66K against 63K words per second, 13 against 14 GB.
Failure. With the extra attention normalization of Chapter 1, the Delta Network's sum of keys grows without bound over long text. Measure: perplexity with no cut-off. Fix: drop that term; the ablation (Table 3) gives the best test perplexity, 31.1, with neither it nor positional encoding.
Chapter 6
Rewrite the delta rule and find a product of matrices where a sum used to be
The 2021 Delta Networks stopped at 90M parameters. The 2024 paper says why: the training algorithm "did not parallelize across sequence length". To see the problem, expand the delta rule. Open the bracket and collect the two terms that hold Wi−1. Call the d by d identity matrix I.
W-i equals W-i-minus-one times the bracket I minus beta-i k-i k-i transpose, plus beta-i v-i k-i transpose.
First squeeze the old memory W along the key k-i, by a factor of beta-i. Then add the new pair beta-i v-i k-i transpose. The squeeze is a matrix product.
Made-up: k = (1, 0) and β = 1 give I − kkT = [[0, 0], [0, 1]]. Applied to (3, 5) it gives (0, 5). The matrix erases the part along k, 3, and keeps the part across it, 5.
Unroll this to token t. Every Householder matrix after step i multiplies the pair written at step i. The sum rule had no products, and you can add terms in any order. Matrix products depend on order: in general AB is not BA.
Key 1 lies along x. Turn key 2. The vector (3, 5) goes through both erase matrices, first in one order, then in the other.
Made-up 2D vectors, β = 1. At the start, key 2 is (0.6, 0.8): H1H2x gives (0, 0.36) and H2H1x gives (−2.4, 1.8).
For the sum rule, a chunk of C tokens adds in one matrix product: S[t+1] = S[t] + V[t]TK[t]. Only L/C steps run in sequence. The delta rule has no such shortcut: each step needs the memory the previous step left.
| Option | Why it fails for DeltaNet |
|---|---|
| Run the loop token by token | L steps in sequence; small updates leave the GPU idle |
| Parallel scan | O(log L) steps, but it stores a d by d state at every token: too much memory traffic |
| Fully parallel form | needs a matrix inverse that grows with the cube of L |
Failure. A DeltaNet trains many times slower than a same-size linear Transformer. Measure: tokens per second against sequence length. Fix: Chapter 7's chunk form. Batching many sequences side by side was never the problem; the dependency runs inside one sequence.
Chapter 7
Pack a chunk of Householder products into two thin matrices, and train in parallel
A product of C Householder matrices looks like a dense d by d matrix. It is not. The WY representation (Bischof and Van Loan, 1985) writes it as I − Σ wrkrT: only C outer products.
Split the sequence into chunks of C tokens, numbered r = 1 to C. For each token build a vector ur: its value, minus what earlier tokens in the chunk already wrote along its key.
u-r equals beta-r times the bracket v-r minus the sum over i less than r of u-i times k-i dot k-r.
Go down the chunk. For token r, take its value v-r. Subtract each earlier u-i, scaled by how much key i overlaps key r. Scale by beta-r. Then the chunk changes the memory S by Σ (ur − S wr) krT.
Made-up chunk, C = 2, empty memory: k1 = (1, 0), v1 = (11, 4), β1 = 0.8; k2 = (0.6, 0.8), v2 = (9, 1), β2 = 1. Then u1 = (8.8, 3.2) and u2 = (9, 1) − 0.6 × (8.8, 3.2) = (3.72, −0.92). S = u1k1T + u2k2T = [[11.032, 2.976], [2.648, −0.736]]. Two plain delta-rule steps give the same matrix.
The rows depend on each other only inside a chunk, through the small overlap table. The paper turns that loop into a C by C triangular solve, the UT transform, which runs as matrix products. All chunks build u and w at once. Only the hand-off of S runs in sequence: L/C steps.
Top: the plain loop. Bottom: chunks, each done at once. Press Play to run both.
Toy timing: one tick per sequential step. Work counts use the paper's chunk cost, LCd + Ld², at L = 8,192 and d = 128.
| Chunk size C | Steps in sequence, L/C | Extra work, LCd |
|---|---|---|
| 1 (the plain loop) | 8,192 | 1.0 million |
| 64 | 128 | 67 million |
| 128 | 64 | 134 million |
| 8,192 (fully parallel) | 1 | 8.6 billion |
The fixed cost Ld² is 134 million. At C = 128 the extra work equals it, and the step sequence is 128 times shorter. The paper uses C = 64 or 128.
Each bar: how many times faster the chunk form runs than the plain loop. Pick a head size.
Read by eye from the paper's Figure 1 (Triton kernels, model width 2,048, length times batch fixed at 16,384), so each value is approximate. The plain-loop kernel is already 2 times faster than the 2021 CUDA kernel.
Failure. A big chunk shortens the step sequence but slows the run. Measure: time per training step against C. Fix: keep C near 64 or 128, where LCd stays below Ld².
Chapter 8
Compare DeltaNet with a Transformer and three linear-time models at 1.3B parameters
With fast training, the 2024 paper trained models of 1.3B parameters on 100B tokens of SlimPajama. All share one tokenizer and one recipe: a LLaMA-style stack where only the token-mixing layer changes. DeltaNet's layer uses SiLU features, L2-normalized keys, a short convolution and heads of size 128.
| Model | How its memory forgets |
|---|---|
| Transformer++ | never: a KV cache keeps every token |
| RetNet | a fixed decay at every step |
| Mamba, GLA | a learned decay that depends on the input |
| DeltaNet | it overwrites along the key it writes |
Each bar is one model at 1.3B parameters. The best bar has a ring. Perplexity: lower wins. Accuracy: higher wins.
From the paper's Table 1 (arXiv 2406.06484v6), 1.3B parameters and 100B tokens. Mamba, GLA and DeltaNet rows use the short convolution. Avg is the average over six commonsense accuracy tasks. SWDE, SQuAD and FDA test recall from the context. Perplexity bars start at 10.
Read the numbers. On WikiText, DeltaNet ties the Transformer: 16.87 against 16.85. On LAMBADA it wins, 12.21 against 13.44. On SWDE it trails, 49.5 against 66.6, and it also trails GLA there. The paper puts that on state size: DeltaNet's state is 128 times layers times width, GLA's is 256 times. At 340M parameters, with equal state, DeltaNet beat GLA on recall.
The hybrid swaps 2 layers for full softmax attention. It reaches SWDE 71.0, SQuAD 43.0 and FDA 29.8, all above the Transformer, with a KV cache in only those 2 layers.
The paper's synthetic suite MAD shows the same shape. DeltaNet scores 100 on In-Context Recall, Noisy Recall and Selective Copy, and 35.7 on Fuzzy Recall, the best of all. On Memorize it scores 52.8, the worst; the Transformer scores 85.2.
Failure. A team reads one average and ships a pure DeltaNet for document extraction. Measure: recall tasks such as SWDE, not only perplexity. Fix: keep a few full attention layers. At 3B parameters and 1T tokens, DeltaNet averages 59.8 against PowerLM-3B's 62.3.
Chapter 9
Keep the terms, the numbers, the code and the open questions in one place
Linear attention is a fast weight memory: one matrix that keys and values write into. It holds about ddot clean pairs. The sum rule cannot overwrite, so it breaks on long text. The delta rule reads first and writes the correction. The WY chunk form trains it in parallel, and a hybrid with 2 attention layers beat a Transformer on recall at 1.3B.
| Term | Meaning | Number to remember |
|---|---|---|
| Crossover | full attention work over fixed-memory work | L / d; 4 at L = 16,384, d = 4,096 |
| State S, fast weights W | sum of outer products v kT | dv by dk, fixed |
| Capacity | orthogonal keys in ddot dimensions | errors from about 60 pairs at ddot = 64 |
| DPFP | feature map that adds dimensions | ddot = 2dkeyν |
| Delta rule | W += β(v − Wk)kT | (9.8, 3.6) where the sum rule gives (16, 6) |
| No cut-off (2021) | test perplexity, 0.13M state | sum rule > 260; Delta Net 29.4 |
| Householder form | W(I − βkkT) + βvkT | order matters: (0, 0.36) vs (−2.4, 1.8) |
| Chunk size C | L/C sequential steps, LCd extra work | 64 or 128 |
| 1.3B results (2024) | WikiText ppl, SWDE | 16.87 vs 16.85; hybrid SWDE 71.0 vs 66.6 |
pythonimport torch def deltanet_recurrent(q, k, v, beta): # q, k: (L, d_k); v: (L, d_v); beta: (L,) S = torch.zeros(v.shape[1], k.shape[1]) out = [] for t in range(k.shape[0]): # generation: one step per token v_bar = S @ k[t] # read what the key holds now S = S + beta[t] * torch.outer(v[t] - v_bar, k[t]) # write the correction out.append(S @ q[t]) return torch.stack(out), S def wy_chunk(S, k, v, beta): # training: one chunk of C tokens C = k.shape[0]; w = torch.zeros_like(k); u = torch.zeros_like(v) for r in range(C): # needs only C x C key overlaps ov = k[:r] @ k[r] w[r] = beta[r] * (k[r] - ov @ w[:r]) u[r] = beta[r] * (v[r] - ov @ u[:r]) return S + (u - w @ S.T).T @ k # same S as C plain delta steps k = torch.tensor([[1., 0], [.6, .8]]); v = torch.tensor([[11., 4], [9, 1]]); b = torch.tensor([.8, 1]) print(wy_chunk(torch.zeros(2, 2), k, v, b)) # [[11.032, 2.976], [2.648, -0.736]] print(deltanet_recurrent(k, k, v, b)[1]) # the same matrix
The 2021 paper notes that its Delta Net does not yet match a Transformer-XL with a large state, and calls for better write rules. The 2024 paper lists three limits. Training is still slower than GLA. The kernel caps the head size, so the state stays small and recall suffers. And DeltaNet extends past its training length less well than GLA or RetNet; the authors guess it lacks a decay term and point to a gated version.
Credit: Session 17 of Georgia Tech CS 8803, LLM seminar. Papers: Linear Transformers Are Secretly Fast Weight Programmers (Schlag, Irie and Schmidhuber, ICML 2021, arXiv 2102.11174) and Parallelizing Linear Transformers with the Delta Rule over Sequence Length (Yang, Wang, Zhang, Shen and Kim, NeurIPS 2024, arXiv 2406.06484). The toy memories and all made-up numbers are ours.
Teach it back: open Present or Teach and explain the delta rule and the WY chunk to a friend. Then go back to the memory, pick 12 keys, and predict which rule keeps the error lower before you press Play.