technical
Notes on Linear Attention: From Linear Attention to KDA
A derivation-first path from softmax attention to fixed-size associative memory, DeltaNet, Gated DeltaNet, and Kimi Delta Attention.
This note follows one central question:
Can we reformulate attention so that, instead of looking back at every previous token for each query, past tokens continually update a fixed-size associative memory that the current query simply reads from?
Linear Attention provides the most basic version of this fixed-size memory. DeltaNet allows the memory to correct and overwrite old associations. Gated DeltaNet adds global forgetting, and Kimi Delta Attention (KDA) refines that mechanism further by controlling retention independently along each key-feature dimension.
Throughout the note, I consider a single causal attention head and treat every vector as a column vector:
- and ;
- the memory matrix is , with readout ;
- the multi-head case applies the same derivation independently to each head;
- output projection, RMSNorm, short convolution, and the output gate are omitted so that we can focus on the core structure.
Some papers represent tokens as row vectors and therefore transpose every equation below. The two conventions are equivalent as long as the state orientation and multiplication order remain consistent.
1. Starting from softmax attention
For the -th token, causal softmax attention is
It performs two operations:
- compare with every previous to decide where to attend;
- use those scores to compute a weighted sum of the corresponding .
Its main advantage is that every query can directly access every historical key–value pair. The cost is that
- a naively materialized training-time attention matrix contains entries;
- autoregressive decoding requires a KV cache that grows with sequence length;
- at step , the query must be compared with all previous keys.
FlashAttention substantially improves IO efficiency and avoids materializing large intermediate tensors, but it does not change the underlying mathematical structure: every query still interacts with all historical keys.
2. Why separate Q from K, but combine K and V?
This is the most important step in understanding Linear Attention.
The temporal roles of Q, K, and V are asymmetric. A pair must remain available to the current query and every future query, whereas is used only to produce the output at the current position.
2.1 Softmax fixes the order of computation
Ignoring normalization for a moment, attention can be written in matrix form as
The usual evaluation order first computes
and then computes . This corresponds to comparing every query with every key. The sequence dimension appears twice, which leads to quadratic complexity.
If the similarity function is an ordinary inner product, however, matrix multiplication is associative:
Under the column-vector convention used here, the state on the right-hand side is equivalently
This is what it means to separate Q from K while combining K and V.
2.2 Intuition: a query is a one-time request; key–value pairs form memory
A historical key and value together describe an association:
The outer product can be interpreted as writing this association into a linear map. Summing all historical associations gives . The current query does not need to participate in storing history; it only serves as an address at read time:
Therefore:
- K and V are combined because both belong to the history and together form an address–content pair that should persist;
- Q is separated from K because Q belongs to the current read operation, so there is no need to create and store an intermediate result between it and every historical key;
- more fundamentally, associativity lets us replace a token-by-token similarity matrix with a feature-to-feature memory state.
2.3 Why can we not simply reorder softmax attention?
Because
≠
Softmax is a nonlinear operation applied, for each query, across all key scores. That nonlinearity destroys the associativity required by the reordering. Linear Attention does not magically rearrange softmax; it replaces the softmax kernel with one that can be factorized.
3. Kernelization and the derivation of Linear Attention
Write the softmax similarity as a kernel:
Suppose we choose a feature map such that
Then
We can now group together the terms that depend only on the past:
which gives
The recurrent form is
This reveals the RNN, or fast-weight-memory, interpretation of Linear Attention: and are fixed-size recurrent states.
Later DeltaNet-style models commonly use normalized queries and keys and omit the explicit denominator state . When moving into DeltaNet below, I therefore write and directly instead of and . This does not mean that every form of Linear Attention lacks a denominator; it reflects a different parameterization.
3.1 In what sense is the complexity linear?
Assuming and are fixed:
- updating costs per token;
- reading costs per token;
- a sequence of length costs in total;
- the decoding state occupies memory and does not grow with context length.
“Linear” refers to sequence length , not to the head dimensions. A fixed-size state is not free either: when the state is large, decoding can become limited by the bandwidth required to read and write it.
3.2 What do we lose?
Softmax attention preserves every key and value, allowing a future query to decide exactly which token to retrieve. Linear Attention compresses an arbitrarily long history into a fixed-size matrix, creating an unavoidable information bottleneck:
- writes interfere when keys are not orthogonal;
- a finite-dimensional state cannot losslessly preserve infinitely many associations;
- the simplest additive update only accumulates information and cannot actively revise an old association.
The final limitation leads directly to DeltaNet.
4. The problem with additive memory: it can write, but not revise
Consider the simplest state update:
It is important to distinguish two different operations.
-
Normal attention readout uses the current query:
If we keep the feature-map notation from Section 3, this becomes , optionally with denominator normalization.
-
Inspecting or updating a particular key–value association asks the state, “What is currently stored at address ?” and therefore uses
With an explicit feature map, the more precise expression is . DeltaNet instead feeds an L2-normalized directly into the state, so I will use the shorter notation from here on.
Thus, evaluating below does not mean that we replace the query with the key during normal attention. It is a read-before-write check: to update an association, we first need to know what the old memory already predicts at that address.
Suppose the same key is first bound to and later should be rebound to . After two additive writes,
if we temporarily ignore interference from other keys. The memory returns the sum of the old and new values rather than replacing the old value.
A better update should not blindly add . It should first ask:
What does the current memory already predict at , and how far is that prediction from the new target ?
Writing only this error gives us the delta rule.
5. DeltaNet: treating the state as an online linear model
5.1 Derivation from an online regression objective
Interpret as an online linear model that receives a key and predicts a value:
For the current sample, define the squared error
Its gradient with respect to is
Taking one gradient-descent step with learning rate gives
while the normal readout remains
This is the core DeltaNet update. The model usually generates dynamically from the current input; it acts as a write gate that controls how strongly or confidently the current association should be updated.
5.2 The erase-and-write view
Expanding the update gives
DeltaNet therefore does not indiscriminately clear the whole memory. It only corrects the map along the current key direction.
5.3 Why L2-normalize the key?
Let . Reading immediately after the update with the same key gives
Therefore:
- if , then : the association is exactly overwritten along that direction;
- if , the result interpolates between the old prediction and the new target;
- without normalization, the effective step size is also multiplied by , making write strength harder to control.
The update can still affect other keys that are similar to . This is cross-talk in a finite-dimensional associative memory, not something the delta rule can eliminate completely.
5.4 Why the state transition is harder to parallelize
Define
Then
is an identity-minus-rank-one, generalized Householder-style transformation. Across multiple steps, we obtain an ordered product
This is harder to parallelize across the sequence than the prefix sum used by additive Linear Attention. An important contribution of the 2024 DeltaNet work was to construct a hardware-friendly chunkwise algorithm using compact WY and Householder representations. Training can then proceed in parallel within chunks, while decoding still uses the simple recurrent update.
Two ideas should remain separate:
- the model rule: the delta update improves overwrite behavior and associative recall;
- the implementation: the chunkwise parallel form makes that rule practical to train on GPUs.
6. Why add a gate? DeltaNet does not forget proactively
The delta rule corrects the current key direction. But if an old piece of information is never followed by a similar key, it may remain in the state indefinitely. For language modeling, we often want the model to decide how long the memory as a whole should persist.
Gated DeltaNet (GDN) introduces a scalar retention gate . A clear way to write the update is to decay the old state first:
and then apply the delta rule to the decayed memory:
or equivalently,
The two gates have different roles:
- is the retention, or forget, gate: it controls how much of the old state survives;
- is the update, or write, gate: it controls how strongly the current association is corrected.
But is a scalar. Whenever the model forgets, every key-feature direction decays by the same amount. Different features in a finite state may represent different kinds of information or operate on different time scales, so this all-or-nothing decay limits expressivity.
7. Kimi Delta Attention: from scalar to fine-grained retention
KDA makes one focused change: it replaces GDN’s scalar retention with a vector
The gate acts along the key-feature axis of the state. First define the decayed memory
then apply the familiar delta correction:
Expanding this gives KDA’s recurrent form under our state convention:
7.1 Why is fine-grained retention more expressive?
GDN gives the entire key-feature space a single retention time scale:
KDA lets different directions retain information for different lengths of time:
Some dimensions can decay rapidly to track local syntax, while others stay close to one and preserve long-range semantics. Because the gate is generated dynamically from the input, the time scale of a given feature can also change from token to token.
This mechanism also provides an implicit relative positional signal. Temporarily ignore the rank-one delta correction and consider only diagonal decay. A write introduced at position is multiplied, by the time it reaches position , by
The resulting memory depends both on distance and on which intervening tokens were encountered, and each feature can follow a different decay trajectory. In Kimi Linear, this allows the interleaved MLA layers to use NoPE while recurrent KDA supplies positional awareness. That is a property of the complete hybrid architecture, however; it should not be generalized into the claim that KDA never needs positional encoding in every possible setting.
7.2 KDA still follows the delta rule
Let
The KDA update remains
Every step still performs the same sequence:
- obtain the decayed memory used at the current step;
- read its old prediction at ;
- compute the residual between the target and that prediction;
- write only the residual back along the direction.
If and , then still holds. Fine-grained forgetting does not break the overwrite property of the delta rule.
8. Why is KDA a special DPLR recurrence?
KDA’s state-transition matrix is
Expanding it gives
This is a Diagonal Plus Low Rank matrix—more specifically, diagonal minus rank one:
The recurrence can therefore be written as
A general DPLR recurrence may obtain its two low-rank vectors from independent projections. That is highly expressive, but its chunkwise expansion requires more pairwise matrix products, additional numerical-stability machinery, and more computation. KDA ties both sides of the low-rank correction to the same normalized key, with one side modulated by the diagonal gate. This constrained structure preserves a clear delta-rule interpretation and enables a more efficient specialized chunkwise kernel.
A common-looking alternative formula defines the state as a matrix:
This is simply the transpose of the convention used in this note, not a different algorithm. When comparing a paper with an implementation, first check the state orientation and only then compare multiplication order.
9. Intuition for chunkwise computation
The recurrent form is ideal for autoregressive decoding: each incoming token updates a fixed-size state once. Training, however, should process many tokens in parallel rather than loop through the sequence in Python.
Split the sequence into chunks of size . Within a chunk, repeatedly substitute
which yields
This separates the work inside a chunk into three pieces:
- propagating the state at the start of the chunk through a sequence of transitions;
- propagating each within-chunk write to later positions;
- retaining only a much shorter recurrence across chunk boundaries.
DeltaNet exploits the compact representation of rank-one Householder-style transitions. KDA exploits its special diagonal-minus-rank-one DPLR structure. Both aim to turn token-by-token recurrence into the large matrix multiplications GPUs handle well, without explicitly constructing every transition product.
The exact kernel derivation involves WY representations, triangular systems within each chunk, and numerical-stability techniques. These are implementation-level optimizations. To understand the model itself, it is usually clearer to internalize the recurrent form before working backward from kernel code.
10. Three generations in one equation
Write all of the methods as
| Method | Core capability | ||
|---|---|---|---|
| Additive Linear Attention | Fixed-size additive associative memory | ||
| DeltaNet | Erases and rewrites the prediction along the current key direction | ||
| Gated DeltaNet | Adds global forgetting to the delta update | ||
| KDA | Adds fine-grained retention along key features |
Here, . The progression worth remembering is
11. A two-dimensional example
Let and choose two orthogonal keys:
The two columns of the state contain the values associated with and .
Additive update
If we first write at and then write at the same address, the first column becomes . There is no replacement semantics.
Delta update
If the second write uses , the update first subtracts the current contents of the first column and then writes . The first column becomes exactly , while the second column is unaffected.
GDN and KDA
If GDN uses , both columns are multiplied by . KDA can instead choose
so that memory associated with is forgotten quickly while memory associated with is almost completely retained. This is the simplest illustration of the difference between a scalar and a diagonal gate.
Keys in a real model are not orthogonal, so “one column equals one independent concept” is only a teaching intuition. Part of training is learning a key-feature space that supports useful reads and writes while minimizing conflicts.
12. Kimi Linear is not pure KDA
KDA is an attention module; Kimi Linear is a complete hybrid architecture that uses it. The representative architecture in the paper interleaves KDA and MLA layers at a roughly ratio. The goal is to combine
- KDA’s linear sequence complexity, fixed recurrent state, and fast long-context decoding;
- full attention or MLA’s direct access to individual historical tokens, which alleviates the information bottleneck of a fixed-size state.
The paper’s claim of reducing KV-cache usage by up to 75% follows from this hybrid ratio together with MLA’s cache design. It does not mean that an individual KDA layer stores 25% of the historical KV pairs. Likewise, the reported long-context throughput gains come from the complete system: architecture, kernels, and model layout together.
13. Common misconceptions and a checklist
Misconception 1: Linear Attention is a lossless reordering of softmax attention
It is not. Only a factorable kernel permits the associative reordering. Replacing the kernel changes the model’s inductive bias and usually introduces a fixed-capacity bottleneck.
Misconception 2: Combining K and V means computing once
That description works for a non-causal, full-sequence expression. A causal model must maintain a prefix state so that the query at position cannot access future tokens.
Misconception 3: DeltaNet increases state capacity
It does not change the dimensions of . It improves how the finite capacity is used, especially by overwriting stale associations instead of accumulating them indefinitely.
Misconception 4: and are the same kind of gate
They are not. controls retention of the old state; controls the strength of the current delta correction.
Misconception 5: KDA is merely per-channel GDN
That is a useful high-level intuition, but the gate acts on the key-feature axis and its order relative to matters. Matrix multiplication is not commutative:
≠
in general. Always align row- versus column-vector conventions before comparing equations or code.
Misconception 6: Linear complexity always means faster execution
Actual speed also depends on sequence length, head size, chunk kernels, hardware utilization, state-memory bandwidth, and whether the architecture mixes in full attention. At short sequence lengths, a highly optimized FlashAttention implementation can remain very competitive.
14. The shortest summary
-
Softmax attention retains every historical key and value, allowing each query to select the past independently. It is expressive, but expensive in sequence length.
-
Linear Attention uses a factorable kernel and associativity to compress historical pairs into , which is then read by . This is the meaning of separating Q from K and combining K with V.
-
A purely additive state cannot naturally overwrite an old mapping.
-
DeltaNet treats the state as an online linear model and writes its prediction error:
-
Gated DeltaNet uses a scalar to control retention of the whole memory.
-
KDA uses a diagonal matrix to control retention independently across key features:
-
KDA’s diagonal-minus-rank-one transition is more expressive than a scalar gate, preserves the delta-rule structure, and supports an efficient specialized DPLR chunkwise algorithm.
References
- Katharopoulos et al., Transformers are RNNs: Fast Autoregressive Transformers with Linear Attention, ICML 2020.
- Schlag, Irie, and Schmidhuber, Linear Transformers Are Secretly Fast Weight Programmers, ICML 2021. The fast-weight interpretation of Linear Attention and the delta rule.
- Yang et al., Parallelizing Linear Transformers with the Delta Rule over Sequence Length, NeurIPS 2024. Recurrent and chunkwise DeltaNet formulations and hardware-efficient training.
- Yang et al., Gated Delta Networks: Improving Mamba2 with Delta Rule, ICLR 2025. Data-dependent decay for DeltaNet.
- Kimi Team, Kimi Linear: An Expressive, Efficient Attention Architecture, 2025. KDA, its specialized DPLR chunkwise algorithm, and the hybrid Kimi Linear architecture.