Rúben GalvãoThe Rabbit Hole

The Rabbit Hole / AI and machine learning / Language models / Alternative language-model architectures

Gated DeltaNet: write the correction, not the whole fact

Linear attention averages the writes it receives. Could a later write correct an existing association instead?

Linear attention replaced the growing KV cache with weighted value totals H and contribution amounts z. Each token writes to those arrays, then its query requests information from them.

Calculated valuesLearned weights
The whole linear-attention blockWq, Wk and Wv project the current token. ReLU plus one maps queries and keys to positive features. The value-key outer product is added to H; the key is added to z. The query reads the updated H and z. Divide the weighted sum by the total weight, apply Wₒ, and add the update to the residual stream. H and z are carried to the next token.Residual streamCurrent token representationEarlier context is dimmed; outlined columns are current.Current token computation.7,168192WqEarlier context is dimmed; outlined columns are current.Current token computation.Query7,168192WkEarlier context is dimmed; outlined columns are current.Current token computation.Key7,168128WvEarlier context is dimmed; outlined columns are current.Current token computation.ValueReLU + 1qReLU + 1kvkᵀValue × key featuresHₜ₋₁+zₜ₋₁+Hₜzₜq×·Hqz · q÷Weighted average1287,168WₒUpdate+Enriched token representations7,168192192128128
Linear attention replaces the score, mask and softmax path with two state updates and a normalised read. Wq, Wk, Wv, Wₒ and the residual path keep their roles. Dashed loops carry each head’s H and z to the next token. Cells illustrate shapes. Blue/orange cells identify calculated values, including all-positive vectors; violet boxes are learned projections. Cell colours identify roles here, not numerical signs.

That gives us a weighted average of the writes so far. But what if a later token is meant to change an existing association, rather than contribute another value to its average?

What if the value changes?

Keep the two associations from the earlier example: [1, 0] → [2, 1] and [0, 1] → [8, 2]. Now the first key arrives with a new value, [4, 5]. What should the memory return for that key?

With linear attention, both writes contribute. The answer is their average, [3, 3]. That makes sense if we want to combine two observations. But suppose the later value is an update: we would want the answer to move to [4, 5].

Adding the new value cannot do that on its own: the old contribution is still there. Dividing by z keeps repeated writes from making the output grow, but it leaves us with the same question. How could a new write revise what is already stored?

Could we write only what needs to change?

Before adding anything, we could ask the memory what it currently associates with the incoming key. Here, that is [2, 1]. To reach [4, 5], the missing amount is only [2, 4].

That suggests a different purpose for H: keep the current associations, so Hk gives a prediction of the value associated with k. In the earlier article, H held weighted totals and needed z to turn them into an average. For this experiment, we want a direct prediction instead, so we leave out that division.

We already know how to write a value using its key: the outer product v kᵀ. Could we use the same operation with the missing amount instead of the whole value?

Call the prediction v̂ = Hk, and the difference e = v − v̂. Writing e kᵀ adds [2, 4] to the first association. It now reads [4, 5], while the second still reads [8, 2]:

Average old and new values, or correct the existing associationThe same key now arrives with a replacement valuev45k10Keep adding, then averageRead the old value, then correctAdd the complete valueRead the old state with k6862Weighted totals21v̂v − predicted value24eWrite e kᵀ21Contribution amounts: [2, 1]4852Updated associationsRead totals ÷ amountRead the updated stateq10Output33q10Output45
The first two writes stored [2, 1] and [8, 2] under orthogonal unit keys. A third write changes the first value to [4, 5]. The old weighted average becomes [3, 3]; a full delta correction makes that key read [4, 5]. Retention and write strength are both 1 in this example.

There is a useful consequence. If the same value arrives again, the prediction already matches it. The difference is zero, so the memory stays as it is. Reading before writing tells us whether anything needs to change.

Our example makes this especially clear because its keys are perpendicular unit vectors: each addresses a separate column of H. With other unit-length keys, adding e kᵀ still changes that key’s own prediction by e. But overlapping keys share some of the same memory, so other reads can change too. A correction is not guaranteed to affect only one association.

This is why the full block uses L2 normalisation to make keys unit length. It also L2-normalises queries, replacing the earlier positive-feature map. There is no z branch: the query now requests information directly through Hq. The extra read with k has a different job: checking what the incoming write would change.

Should a new value replace the old prediction completely?

So far, we have treated the incoming value as a complete replacement. But a token might only supply part of an update. What if we could move partway towards it?

In our example, half the difference is [1, 2]. Adding that to the old prediction [2, 1] gives [3, 3]. A later token could move it further. Applying the full difference would take it straight to [4, 5].

A write strength β between 0 and 1 gives us that choice. β = 1 applies the full correction; β = ½ applies half; β = 0 leaves the association alone. Instead of fixing that strength ourselves, we can let the model learn to calculate it from the current token.

What about old information that never gets corrected?

The correction only acts through the incoming key. An old association that new tokens do not address can remain in H, even when it is no longer useful in the current context.

Could the current token also control how much of the old state carries forward? A retention factor α between 0 and 1 would let it do that: α = 1 keeps H, while α = ½ halves it before the new write.

That raises another question: should we compare the incoming value with the memory before or after this fading? Suppose its old prediction was [2, 1]. After halving H, it is [1, ½]. A correction based on the original prediction would no longer supply the amount missing from the memory we actually have.

So we first retain H̄ = αH, then ask that retained state for its prediction. The correction becomes e = v − H̄k. Retention decides what survives; the correction responds to what is still missing.

How could the token control both choices?

We already use learned projections to turn the token into q, k and v. Two more projections can give us the controls we have just proposed.

For β, sigmoid keeps the write strength between 0 and 1. For α, we can use the same idea of input-dependent fading explored in Mamba: a positive step Δ and a learned negative parameter A give α = exp(A × Δ). A larger step leaves less of the old state.

The current token supplies retention and correction strengthSame current tokenRetentionCorrection strengthWαWβSoftplusΔAexp(A × Δ)αSigmoidβScale old H before predictionScale e kᵀ before writing
Both controls are calculated from the current token through learned projections. A is a learned negative parameter. α retains a fraction of the old state; β applies a fraction of the correction. These are the same two branches drawn on the right of the complete block.

Both controls come from the current token, but answer different questions: how much old state should survive, and how much of the missing value should we write?

What does the whole block look like now?

The Q/K/V branches still come from the current token. What changes is how they work with H. The key first asks what the retained memory predicts; the value tells us what is missing. We write a chosen amount of that difference, then the query requests information from the updated memory.

In the diagram, Wα and Wβ sit alongside the Q/K/V weights. Follow H down through retention, prediction, correction and the final query read:

Calculated valuesLearned weights
A complete simplified Gated DeltaNet blockThe current token produces q, k and v, plus retention alpha and write strength beta. Normalise q and k. Decay the old state by alpha, predict its value with k, and write beta times the prediction error times the transposed key. Read the updated state with q, apply the output projection, then add to the residual stream.Residual streamCurrent token representationEarlier context is dimmed; outlined columns are current.Current token computation.7,168192WqEarlier context is dimmed; outlined columns are current.Current token computation.Query7,168192WkEarlier context is dimmed; outlined columns are current.Current token computation.Key7,168128WvEarlier context is dimmed; outlined columns are current.Current token computation.ValueL2 normqL2 normkWαSoftplusΔAexp(A × Δ)αWβSigmoidβHₜ₋₁×H̄×kv̂v − v̂eβe kᵀ+Hₜ×qOutput1287,168WₒUpdate+Enriched token representations7,168192192128128
A simplified Gated DeltaNet head in the same attention shell. Normalise q/k, decay H, predict with k, write the correction, then read with q. Violet Wα, Wβ and A are learned parameters; blue/orange cells are calculated data. The token supplies α and β through the shown branches. Model-specific convolution, output gating and extra normalisation are omitted.

The updated H carries forward to the next token. Together, these steps give Hₜ = αHₜ₋₁ + β(v − αHₜ₋₁k)kᵀ, and its query read is y = Hₜq.

Qwen3-Next uses this kind of head with a 128 × 128 state per value head, plus convolution, output gating and normalisation around it. Kimi Linear uses a related delta update with finer-grained retention controls.

The state stays fixed in size, but its writes can still interfere. Hybrid architectures keep some attention layers so the network can also request information from separately stored key/value pairs.

Sources and assumptions

Rows of H are value coordinates and columns are key coordinates. The comparison uses two-coordinate values and orthogonal unit keys. It contrasts the normalised additive rule from the preceding article with an unnormalised delta-state read; the two heads do not share the same denominator rule. Exact replacement assumes a unit key, β = 1 and α = 1. Repeating a value does not double the preceding article’s normalised output.

The complete drawing shows a simplified head inside the familiar attention shell, with illustrative cells and model-dimension labels. Blue/orange cells identify calculated data rather than numerical signs; violet boxes identify learned parameters. Wα and Wβ are learned projections; A is a directly learned negative parameter. Decay precedes prediction. Model-specific convolution, output gating, head sharing, output scaling and extra normalisation are omitted from the drawing. Qwen3-Next has 32 value heads sharing 16 query/key patterns; Kimi Delta Attention uses finer-grained retention than the scalar α drawn here.

← Browse all subjectsBack to the beginning ↑