Linear Transformers as Fast Weight Programmers

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.

Keep the latest value

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

The Quadratic Wall

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.

Say it aloud

L squared d, over L d squared, equals L over d.

L²d
L squared d the work of full softmax attention over a sequence: L² comparisons of d numbers each.
Ld²
L d squared the work of the fixed-memory layer: L updates of a d by d matrix.
L / d
L over d how many times more work full attention does. Below 1, full attention is cheaper.
In plain words

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.

With numbers

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.

Find the crossover

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.

4,096

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.

CostFull attentionFixed memory
Whole sequence (training)L²dLd²
One more token (generation)Ld, grows foreverd², fixed
Memory keptevery key and valueone 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.

  1. Attention without softmax: one change turns attention into a running matrix.
  2. Fast weight programmers: that matrix is a 1991 memory. The hero's memory.
  3. When memory overflows: d dimensions hold d clean keys. The 12-key button.
  4. The delta rule: read, then write only the correction. The hero's second rule.
  5. DeltaNet on real text: the 2021 results.
  6. Why it resists parallelism: the update becomes a product of matrices.
  7. The WY trick: chunks that train in parallel and give the same answer.
  8. Where linear models stand: the 2024 results at 1.3B parameters.
  9. Field guide: numbers, code, links and the credit.
At d = 4,096 and L = 256, which layer does less attention work?

Chapter 1

Attention Without Softmax

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.

Say it aloud

S-i equals S-i-minus-one, plus v-i times k-i transpose.

Si
S-i the state after token i: a dv by dk matrix. The output is oi = Siqi.
Si−1
S-i-minus-one the state before token i. It starts as all zeros.
vi
v-i the value of token i, a column of dv numbers.
kiT
k-i transpose the key of token i, laid as a row. A column times a row is the outer product: a full matrix, entry (r, c) = vrkc.
In plain words

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.

With numbers

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

Compute one output two ways

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.

Which property lets the sum over past tokens become a running state S?

Chapter 2

Fast Weight Programmers

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

Say it aloud

W-i equals sigma of W-i-minus-one plus a-i outer b-i; and y-i equals W-i times x-i.

W(i)
W-i the fast weights after step i: the memory.
σ
sigma an activation function applied to every entry. Set it to the identity to get linear attention.
a(i)
a-i the first vector the slow net makes, Wax(i). Today we call it the value.
⊗
outer the outer product, a column times a row.
b(i)
b-i the second vector, Wbx(i). Today we call it the key.
y(i)
y-i the fast net's output at step i.
x(i)
x-i the input at step i. The fast net reads it, so today we call it the query.
In plain words

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 numbers

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.

Read the memory with any query

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.

45°

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.

In the fast weight view, what are a Transformer's keys and values?

Chapter 3

When Memory Overflows

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.

Say it aloud

W k-i equals v-i, plus the sum over j not equal to i of v-j times k-j dot k-i.

W ki
W k-i what you get back when you read the memory W with key k-i.
vi
v-i the value you stored with k-i: the part you want.
Σj≠i
the sum over j not equal to i one term for every other stored pair.
vj
v-j another stored value.
(kj · ki)
k-j dot k-i how much the two keys overlap. 0 for orthogonal keys, so that term vanishes.
In plain words

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.

With numbers

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.

Fill a 16-dimensional memory

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.

12

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 φddotWhere recall errors start
Linear attention (identity)64at about 60 pairs
DPFP, ν = 1, 2, 3128, 256, 384near each limit
FAVOR+ (random features)2mnever reaches zero loss
Softmax (KV cache)no fixed limitstruggles 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.

After a third, non-orthogonal pair is written, why does reading with k1 go wrong, though k1 and v1 never changed?

Chapter 4

The Delta Rule

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.

  1. Read. Get the value the key holds now: v̄ = W k.
  2. Blend. Mix the new value with the old one: vnew = βv + (1 − β)v̄.
  3. Replace. Remove v̄ at k and write vnew at k.

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.

Say it aloud

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.

Wi
W-i the memory after token i.
βi
beta-i the write strength for token i: 0 changes nothing, 1 overwrites fully.
vi
v-i the value token i wants stored at its key: the target.
Wi−1ki
W-i-minus-one k-i the value the key holds now, v̄. The bracket is the error: target minus current.
kiT
k-i transpose the key as a row. It places the correction only along the key's direction.
In plain words

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.

With numbers

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

Overwrite one key

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.

0.80

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.8Key 1 readsKey 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.

Writing (11, 4) at key 1 with the sum rule returns (16, 6). Why?

Chapter 5

DeltaNet on Real Text

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.

Say it aloud

Phi-prime of k equals phi of k, divided by the sum over j of phi of k, entry j.

φ′(k)
phi-prime of k the scaled key the memory uses. Its entries add up to 1.
φ(k)
phi of k the key after the feature map, with ddot positive entries.
Σj φ(k)j
the sum over j of phi of k, entry j all its entries added up.
In plain words

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.

With numbers

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.

Read the 2021 results

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.

With no cut-off, both models have a 0.13M state. Why does the sum rule pass 260 perplexity while the Delta Network stays at 29.4?

Chapter 6

Why It Resists Parallelism

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.

Say it aloud

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.

Wi
W-i the memory after token i.
Wi−1
W-i-minus-one the memory before token i. It is now multiplied, not added to.
I − βikikiT
I minus beta-i k-i k-i transpose a generalized Householder matrix. With a unit key and β = 1 it erases the part of a vector along k-i and keeps the rest.
βivikiT
beta-i v-i k-i transpose the new pair, written at strength beta-i.
In plain words

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.

With numbers

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.

Erase in two orders

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.

53°

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.

OptionWhy it fails for DeltaNet
Run the loop token by tokenL steps in sequence; small updates leave the GPU idle
Parallel scanO(log L) steps, but it stores a d by d state at every token: too much memory traffic
Fully parallel formneeds 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.

Why does the sum rule split into parallel chunks while the plain delta rule does not?

Chapter 7

The WY Trick

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.

Say it aloud

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.

ur
u-r the corrected value of token r in the chunk. A twin vector w-r uses the same rule with k-r in place of v-r.
βr
beta-r the write strength of token r.
vr
v-r the value of token r.
Σi<r
the sum over i less than r one term per earlier token in the same chunk.
(ki · kr)
k-i dot k-r the overlap of two keys inside the chunk: a C by C table, never the d by d memory.
In plain words

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.

With numbers

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.

Choose the chunk size

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 CSteps in sequence, L/CExtra work, LCd
1 (the plain loop)8,1921.0 million
6412867 million
12864134 million
8,192 (fully parallel)18.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.

Read the measured speed-up

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².

In the WY form, what do the u and w vectors of a chunk depend on?

Chapter 8

Where Linear Models Stand

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.

ModelHow its memory forgets
Transformer++never: a KV cache keeps every token
RetNeta fixed decay at every step
Mamba, GLAa learned decay that depends on the input
DeltaNetit overwrites along the key it writes

Pick a benchmark

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.

Why does the hybrid with 2 full attention layers beat Transformer++ on SWDE, SQuAD and FDA?

Chapter 9

Field Guide

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.

TermMeaningNumber to remember
Crossoverfull attention work over fixed-memory workL / d; 4 at L = 16,384, d = 4,096
State S, fast weights Wsum of outer products v kTdv by dk, fixed
Capacityorthogonal keys in ddot dimensionserrors from about 60 pairs at ddot = 64
DPFPfeature map that adds dimensionsddot = 2dkeyν
Delta ruleW += β(v − Wk)kT(9.8, 3.6) where the sum rule gives (16, 6)
No cut-off (2021)test perplexity, 0.13M statesum rule > 260; Delta Net 29.4
Householder formW(I − βkkT) + βvkTorder matters: (0, 0.36) vs (−2.4, 1.8)
Chunk size CL/C sequential steps, LCd extra work64 or 128
1.3B results (2024)WikiText ppl, SWDE16.87 vs 16.85; hybrid SWDE 71.0 vs 66.6

Checklist

  1. Compute L / d before you pick linear attention. Below 1, keep softmax.
  2. Compare the context length with ddot per head. Past it, expect crosstalk.
  3. Use the delta rule, with normalized keys, when new facts must replace old ones.
  4. Test recall by reading every stored key, not only the last one written.
  5. Train with the chunk form, C = 64 or 128. Generate with the token loop.
  6. Test recall-heavy tasks such as SWDE. Add a few full attention layers if they lag.
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

What the authors leave open

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.

Keep going

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.

The takeaway. A fixed memory costs the same at every token, but it holds only about d clean facts. Read before you write, train in chunks, and keep a little full attention for exact lookups.

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.

CS 8803 LLM Seminar, Session 17: Linear Transformers as Fast Weight Programmers
Fast Weight Programmers paper · Parallel DeltaNet paper · Back to Gleams