← Writing

Kimi Delta Attention: How It Works, Step by Step

Aug 17, 2026

Kimi Delta Attention: How It Works, Step by Step

Kimi Delta Attention (KDA) is the core linear-attention mechanism introduced in Moonshot AI’s Kimi Linear architecture. Its goal is ambitious: keep the inference efficiency of recurrent or linear attention while recovering enough expressivity to compete with conventional softmax attention.

The key idea is surprisingly compact. Instead of storing every past key and value in a growing KV cache, KDA maintains a fixed-size matrix state that acts like an associative memory. It updates that memory with a delta-rule correction and gives each key-channel its own learned forgetting rate.

That final detail — fine-grained, per-channel forgetting — is what distinguishes KDA from Gated DeltaNet.

This post builds KDA from first principles, starting with ordinary attention, then linear attention, DeltaNet, Gated DeltaNet, and finally KDA itself. We will also look at matrix dimensions, why the delta rule behaves like online learning, how the recurrent state replaces a growing KV cache, why KDA is hardware-friendly, and how Kimi Linear combines KDA with full attention.


1. Why change attention at all?

For a sequence of length LL, ordinary causal softmax attention computes, schematically,

O=softmax(QKTd)V.O = \operatorname{softmax}\left(\frac{QK^T}{\sqrt d}\right)V.

If Q,K,VRL×dQ,K,V \in \mathbb{R}^{L\times d}, then QKTQK^T is an L×LL\times L matrix. During training, this gives the familiar quadratic dependence on sequence length.

During autoregressive decoding, implementations avoid recomputing all old keys and values by storing them in a KV cache. But that cache grows linearly with sequence length:

KV-cache sizeL×layers×KV heads×dhead.\text{KV-cache size} \propto L \times \text{layers} \times \text{KV heads} \times d_{head}.

So long-context inference eventually becomes increasingly dominated by memory capacity and memory traffic.

Linear attention asks a different question:

Can the entire history be compressed into a fixed-size state, so each new token reads from and updates that state instead of attending explicitly to every previous token?

That is the family of ideas in which KDA lives.


2. Linear attention as an associative memory

Consider one attention head. For token tt, let

  • qtRdkq_t \in \mathbb{R}^{d_k} be the query,
  • ktRdkk_t \in \mathbb{R}^{d_k} be the key,
  • vtRdvv_t \in \mathbb{R}^{d_v} be the value,
  • StRdk×dvS_t \in \mathbb{R}^{d_k\times d_v} be a recurrent memory matrix.

The simplest linear-attention recurrence is

St=St1+ktvtTS_t = S_{t-1} + k_t v_t^T

followed by

ot=StTqt.o_t = S_t^T q_t.

Check the dimensions:

ktvtT:(dk×1)(1×dv)=dk×dv,k_t v_t^T:\quad (d_k\times 1)(1\times d_v)=d_k\times d_v,

so it can be added to St1S_{t-1}.

Then

StTqt:(dv×dk)(dk×1)=dv×1.S_t^T q_t:\quad (d_v\times d_k)(d_k\times1)=d_v\times1.

What does the state mean?

Each outer product ktvtTk_t v_t^T writes an association between a key direction and a value direction into SS.

A useful mental model is:

SS is a tiny learned-at-runtime lookup table represented as a matrix.

Given a query qtq_t, multiplying by StTS_t^T retrieves the value encoded in directions similar to the query.

Unlike softmax attention, the model no longer stores all previous keys and values separately. The entire past is compressed into StS_t.

That gives a fixed recurrent-state size of roughly

O(dkdv)O(d_k d_v)

per head, independent of context length.

But there is an obvious problem.


3. The problem with naive linear attention: memories only accumulate

The update

St=St1+ktvtTS_t=S_{t-1}+k_tv_t^T

only adds information. It has no explicit way to correct or erase an old key-value association.

Suppose two different tokens produce similar keys but different values. The state simply accumulates both writes. Over long sequences, unrelated associations interfere with each other.

This is one reason early linear-attention approaches struggled to match softmax attention.

The delta rule fixes this in a particularly elegant way.


4. DeltaNet: do not blindly write — first measure the error

Instead of saying “associate ktk_t with vtv_t,” ask:

What value does the current memory already predict for ktk_t, and how wrong is it?

The current prediction is

v^t=St1Tkt.\hat v_t = S_{t-1}^T k_t.

The desired value is vtv_t, so the residual error is

et=vtSt1Tkt.e_t = v_t - S_{t-1}^T k_t.

Now update only by that residual:

St=St1+βtktetT,S_t = S_{t-1} + \beta_t k_t e_t^T,

where βt[0,1]\beta_t\in[0,1] is a learned write strength.

Substitute the residual:

St=St1+βtkt(vtSt1Tkt)T.S_t = S_{t-1}+\beta_tk_t(v_t-S_{t-1}^Tk_t)^T.

Expanding:

St=St1βtktktTSt1+βtktvtT.S_t = S_{t-1} -\beta_t k_tk_t^T S_{t-1} +\beta_t k_tv_t^T.

Therefore

St=(IβtktktT)St1+βtktvtT\boxed{ S_t=(I-\beta_tk_tk_t^T)S_{t-1}+\beta_tk_tv_t^T }

This is the classical delta rule used by DeltaNet.

Why this is better

The update has two conceptual pieces:

βtktktTSt1-\beta_t k_tk_t^TS_{t-1}

removes the part of memory currently associated with ktk_t, while

+βtktvtT+\beta_tk_tv_t^T

writes the new target value.

So the rule performs an erase/correct + write operation rather than blind accumulation.

You can rewrite it in perhaps the most intuitive form:

St=St1+βtkt(vtSt1Tkt)T\boxed{ S_t=S_{t-1}+\beta_tk_t\left(v_t-S_{t-1}^Tk_t\right)^T }

That reads almost like code:

  1. query memory with the current key,
  2. calculate prediction error,
  3. write only the correction.

5. DeltaNet is online gradient descent

The same equation can be derived from a tiny optimization problem.

Define a reconstruction loss for the current key-value pair:

Lt(S)=12STktvt2.\mathcal L_t(S)=\frac12\|S^Tk_t-v_t\|^2.

This says: we would like the memory matrix SS to map key ktk_t to value vtv_t.

Taking one gradient-descent step with learning rate βt\beta_t gives

St=St1βtSLt(St1).S_t=S_{t-1}-\beta_t\nabla_S\mathcal L_t(S_{t-1}).

The gradient is

SLt=kt(St1Tktvt)T.\nabla_S\mathcal L_t =k_t(S_{t-1}^Tk_t-v_t)^T.

Therefore

St=St1βtkt(St1Tktvt)T,S_t =S_{t-1}-\beta_tk_t(S_{t-1}^Tk_t-v_t)^T,

which is exactly

St=St1+βtkt(vtSt1Tkt)T.S_t=S_{t-1}+\beta_tk_t(v_t-S_{t-1}^Tk_t)^T.

So an elegant interpretation is:

The attention layer is performing a tiny online learning problem inside the forward pass. The recurrent state is a set of “fast weights,” updated token by token.

The model’s ordinary neural-network weights learn how to produce qtq_t, ktk_t, vtv_t, and the update strength βt\beta_t; the fast state StS_t then adapts dynamically to the current sequence.


6. DeltaNet still has a problem: stale memory never globally fades

The delta update can overwrite a memory when a similar key arrives again. But information unrelated to later keys may remain indefinitely.

This motivates Gated DeltaNet (GDN).

GDN adds a learned scalar forget gate αt[0,1]\alpha_t\in[0,1]:

St=αt(IβtktktT)St1+βtktvtT\boxed{ S_t=\alpha_t(I-\beta_tk_tk_t^T)S_{t-1}+\beta_tk_tv_t^T }

Now the previous state is multiplied by αt\alpha_t before being carried forward.

If

αt1,\alpha_t\approx1,

memory is preserved.

If

αt1,\alpha_t\ll1,

old information decays rapidly.

This is analogous to weight decay on the fast memory.

But notice something coarse about it: one scalar controls the decay of an entire head.

Every row/channel of the state is forgotten at the same rate.

KDA’s main conceptual change is to remove that restriction.


7. Kimi Delta Attention: make forgetting channel-wise

KDA replaces the scalar αt\alpha_t with a vector

αt[0,1]dk.\alpha_t\in[0,1]^{d_k}.

That vector becomes a diagonal matrix:

Dt=Diag(αt)Rdk×dk.D_t=\operatorname{Diag}(\alpha_t) \in\mathbb{R}^{d_k\times d_k}.

The KDA recurrence is

St=(IβtktktT)Diag(αt)St1+βtktvtT\boxed{ S_t=(I-\beta_tk_tk_t^T)\operatorname{Diag}(\alpha_t)S_{t-1} +\beta_tk_tv_t^T }

and the output remains

ot=StTqt.\boxed{o_t=S_t^Tq_t.}

This is the central KDA equation.

The critical difference

Gated DeltaNet uses

αtI,\alpha_t I,

which means every key dimension decays identically.

KDA uses

Diag(αt,1,αt,2,,αt,dk),\operatorname{Diag}(\alpha_{t,1},\alpha_{t,2},\ldots,\alpha_{t,d_k}),

so each channel gets an independent retention rate.

One dimension might keep information almost indefinitely:

αt,1=0.999,\alpha_{t,1}=0.999,

while another rapidly resets:

αt,2=0.2.\alpha_{t,2}=0.2.

This lets the state contain memory components operating at different timescales.

That is much more expressive than asking a whole head to share one memory lifetime.


8. What exactly is being gated?

Because

St1Rdk×dv,S_{t-1}\in\mathbb{R}^{d_k\times d_v},

left-multiplication by

Dt=Diag(αt)D_t=\operatorname{Diag}(\alpha_t)

scales the rows of the state.

Those rows correspond to key-space channels.

If we write

S=[s1Ts2TsdkT],S= \begin{bmatrix} ---s_1^T---\\ ---s_2^T---\\ \vdots\\ ---s_{d_k}^T--- \end{bmatrix},

then

DtS=[αt,1s1Tαt,2s2Tαt,dksdkT].D_tS= \begin{bmatrix} \alpha_{t,1}s_1^T\\ \alpha_{t,2}s_2^T\\ \vdots\\ \alpha_{t,d_k}s_{d_k}^T \end{bmatrix}.

So KDA can preserve some learned key-space features while aggressively clearing others.

This is why the Kimi Linear paper describes KDA as fine-grained gating.


9. A tiny numerical example

Take a toy state with

dk=2,dv=2.d_k=2,\qquad d_v=2.

Suppose

St1=[4002].S_{t-1}= \begin{bmatrix} 4&0\\ 0&2 \end{bmatrix}.

Let KDA predict the channel-wise retention vector

αt=[0.90.2].\alpha_t= \begin{bmatrix} 0.9\\ 0.2 \end{bmatrix}.

Then

DtSt1=[0.9000.2][4002]=[3.6000.4].D_tS_{t-1} = \begin{bmatrix} 0.9&0\\ 0&0.2 \end{bmatrix} \begin{bmatrix} 4&0\\ 0&2 \end{bmatrix} = \begin{bmatrix} 3.6&0\\ 0&0.4 \end{bmatrix}.

The first memory channel is mostly preserved; the second is nearly cleared.

Now imagine the current token has

kt=[10],vt=[51],βt=0.5.k_t=\begin{bmatrix}1\\0\end{bmatrix}, \qquad v_t=\begin{bmatrix}5\\1\end{bmatrix}, \qquad \beta_t=0.5.

The delta operator is

IβtktktT=[1001]0.5[1000]=[0.5001].I-\beta_tk_tk_t^T = \begin{bmatrix} 1&0\\0&1 \end{bmatrix} -0.5 \begin{bmatrix} 1&0\\0&0 \end{bmatrix} = \begin{bmatrix} 0.5&0\\0&1 \end{bmatrix}.

Applied to the decayed memory:

[0.5001][3.6000.4]=[1.8000.4].\begin{bmatrix} 0.5&0\\0&1 \end{bmatrix} \begin{bmatrix} 3.6&0\\0&0.4 \end{bmatrix} = \begin{bmatrix} 1.8&0\\0&0.4 \end{bmatrix}.

The new write is

βtktvtT=0.5[10][51]=[2.50.500].\beta_tk_tv_t^T =0.5 \begin{bmatrix}1\\0\end{bmatrix} \begin{bmatrix}5&1\end{bmatrix} = \begin{bmatrix} 2.5&0.5\\ 0&0 \end{bmatrix}.

Therefore

St=[4.30.500.4].S_t= \begin{bmatrix} 4.3&0.5\\ 0&0.4 \end{bmatrix}.

Even in this tiny example you can see all three pieces:

  1. decay selected memory channels,
  2. correct/erase the old association in the current key direction,
  3. write the new value.

10. Why does this count as attention?

At first glance KDA looks more like an RNN than attention.

That is partly true: at inference time it is naturally recurrent.

But the state is specifically an associative key-value memory, and the read operation

ot=StTqto_t=S_t^Tq_t

has the same semantic roles as attention:

  • keys determine where information is written,
  • values determine what is written,
  • queries determine what is retrieved.

The major difference is how history is represented.

Softmax attention

History is explicit:

{k1,v1,k2,v2,,kt,vt}.\{k_1,v_1,k_2,v_2,\ldots,k_t,v_t\}.

KDA

History is compressed:

StRdk×dv.S_t\in\mathbb{R}^{d_k\times d_v}.

This distinction drives the efficiency difference.


11. Decode complexity: why a fixed state matters

With conventional cached attention, token tt compares its query against all previous cached keys. Ignoring implementation details, the amount of attention work and memory traffic therefore grows with context length.

KDA reads and updates a state whose dimensions do not depend on sequence length.

Per head, the persistent recurrent state is

StRdk×dv.S_t\in\mathbb{R}^{d_k\times d_v}.

So once decoding is underway, token 10,000 and token 1,000,000 interact with the same-size recurrent state.

This is especially attractive for long-horizon agent workloads, where models may generate or process very long trajectories.

In the Kimi Linear technical report, Moonshot reports up to a 75% KV-cache reduction for its hybrid architecture and up to roughly 6× higher decoding throughput than the full-attention baseline at a 1M-token context. Those are architectural-system results for Kimi Linear as a whole, not a universal constant for every KDA implementation.


12. Why not make the entire model KDA?

A fixed-size recurrent memory is efficient, but it has a fundamental limitation: finite capacity.

Softmax attention can access each previous token individually. A recurrent state must compress all previous information into a fixed number of values.

That makes exact long-range retrieval inherently more difficult.

Kimi Linear handles this pragmatically with a hybrid architecture:

KDA, KDA, KDA, MLA, KDA, KDA, KDA, MLA,\text{KDA},\ \text{KDA},\ \text{KDA},\ \text{MLA},\ \text{KDA},\ \text{KDA},\ \text{KDA},\ \text{MLA},\ldots

The paper describes a uniform 3:1 ratio of KDA layers to global Multi-Head Latent Attention (MLA) layers.

The KDA layers provide cheap recurrent processing, while periodic global-attention layers restore direct access to the broader context.

This is an important design lesson:

Kimi Linear does not claim that finite-state memory magically eliminates every reason for full attention. It uses full attention sparingly, where its global retrieval capability is valuable.


13. The transition-matrix view

KDA can be written as a state-space recurrence

St=AtSt1+Bt,S_t=A_tS_{t-1}+B_t,

where

At=(IβtktktT)Diag(αt)A_t=(I-\beta_tk_tk_t^T)\operatorname{Diag}(\alpha_t)

and

Bt=βtktvtT.B_t=\beta_tk_tv_t^T.

Expand AtA_t:

At=Diag(αt)βtktktTDiag(αt).A_t =\operatorname{Diag}(\alpha_t) -\beta_tk_tk_t^T\operatorname{Diag}(\alpha_t).

This has the form

DiagonalRank-1\boxed{\text{Diagonal} - \text{Rank-1}}

which is a specialized case of a Diagonal-Plus-Low-Rank (DPLR) transition.

That structure matters for implementation.

A completely general dense transition matrix would be expressive but expensive. KDA keeps the transition structured enough that chunks of tokens can be processed efficiently using matrix multiplications.


14. Recurrence is great for decode — but training needs parallelism

A token-by-token recurrence appears sequential:

S1S2S3S_1\rightarrow S_2\rightarrow S_3\rightarrow\cdots

That is ideal during autoregressive decoding, because tokens are generated sequentially anyway.

Training is different. GPUs want large matrix multiplications, not millions of tiny sequential updates.

So KDA uses a chunkwise parallel formulation.

Split a length-LL sequence into chunks of CC tokens:

L/Cchunks.L/C\quad\text{chunks}.

Within a chunk, the product of transitions can be compressed into structured terms, while state is passed recurrently between chunks.

Conceptually:

S[j+1]=P[j]S[j]+H[j],S_{[j+1]}=P_{[j]}S_{[j]}+H_{[j]},

where

  • P[j]P_{[j]} summarizes how the chunk transforms incoming memory,
  • H[j]H_{[j]} summarizes the new information written by that chunk.

The Kimi paper derives a compact WY-like representation of the repeated rank-1 updates and then applies a UT transform so much of the work becomes large matrix multiplication.

The important systems point is:

KDA is mathematically recurrent, but its training implementation is reorganized so GPUs can process chunks with high GEMM utilization.

This is similar in spirit to other modern recurrent/linear sequence models: recurrent form for inference, parallel or chunkwise form for training.


15. Why fine-grained decay creates an implementation challenge

A scalar decay is easy to combine across a chunk:

tαt.\prod_t \alpha_t.

KDA instead has vectors of decay rates:

αtRdk.\alpha_t\in\mathbb{R}^{d_k}.

Cumulative decay becomes element-wise across channels, which complicates the chunkwise algebra and can create numerical issues if implemented naively over long spans.

The Kimi team’s contribution is not only the recurrence itself, but also a specialized hardware-efficient algorithm exploiting the fact that its transition is diagonal plus a tightly structured rank-1 correction.

In the paper’s efficiency analysis, the authors argue that tying the low-rank terms to the key vector lets KDA avoid part of the overhead of a more general DPLR operator.

That implementation detail is easy to overlook, but it is crucial: an asymptotically attractive attention mechanism is not useful if its kernels cannot keep modern GPUs busy.


16. How are qq, kk, vv, α\alpha, and β\beta produced?

In the Kimi Linear model, each head receives token representation xtx_t and generates the ordinary query/key/value-like vectors plus two gating signals.

The paper uses learned projections along with short convolutions and nonlinearities for qq, kk, and vv. The key and query are normalized, while

αt[0,1]dk\alpha_t\in[0,1]^{d_k}

is the channel-wise decay vector and

βt[0,1]\beta_t\in[0,1]

is the write/update strength.

So every token decides two distinct things:

1. What memory should fade?

Controlled by

αt.\alpha_t.

2. How strongly should I correct/write the current key-value association?

Controlled by

βt.\beta_t.

These are separate operations, and that separation is useful conceptually.

A token may decide to preserve most old channels while strongly updating one new association, or rapidly decay selected channels while making only a weak write.


17. KDA versus softmax attention

Property Softmax attention Kimi Delta Attention
Representation of history Explicit past K/V vectors Fixed-size matrix state
State growth with context Linear KV-cache growth Constant recurrent state per head
Retrieval Direct weighted access to past tokens Query compressed associative memory
Exact token-level recall Strong Limited by finite-state compression
Forgetting Implicit through attention scores Explicit learned channel-wise decay
Update Store each K/V Delta-rule correction
Decode behavior Work/memory traffic grows with context State size independent of context
Training implementation Highly optimized full-attention kernels Chunkwise recurrent/parallel kernels

The tradeoff is therefore not “attention versus no attention.”

It is explicit uncompressed memory versus learned compressed memory.


18. KDA versus DeltaNet and Gated DeltaNet

The progression can be summarized in four equations.

Linear attention

St=St1+ktvtTS_t=S_{t-1}+k_tv_t^T

Blindly accumulate associations.

DeltaNet

St=(IβtktktT)St1+βtktvtTS_t=(I-\beta_tk_tk_t^T)S_{t-1}+\beta_tk_tv_t^T

Correct the old prediction before writing.

Gated DeltaNet

St=αt(IβtktktT)St1+βtktvtTS_t=\alpha_t(I-\beta_tk_tk_t^T)S_{t-1}+\beta_tk_tv_t^T

Add one scalar forgetting rate for the whole head.

Kimi Delta Attention

St=(IβtktktT)Diag(αt)St1+βtktvtT\boxed{ S_t=(I-\beta_tk_tk_t^T)\operatorname{Diag}(\alpha_t)S_{t-1} +\beta_tk_tv_t^T }

Give every key channel its own forgetting rate.

That is the conceptual ladder from basic linear attention to KDA.


19. The most useful intuition: KDA is a tiny database that learns how to overwrite itself

If you remember only one picture, use this one.

Imagine each head owns a small matrix-shaped database SS.

For each token:

  1. Decay: decide which portions of the database are becoming irrelevant.
  2. Probe: use ktk_t to ask what value is currently stored for this key direction.
  3. Compute an error: compare that answer with the new vtv_t.
  4. Correct: erase the conflicting part of the old association.
  5. Write: store the new association.
  6. Read: use qtq_t to retrieve from the updated database.

In compact form:

old memorychannel-wise decayretained memorydelta correctionupdated memoryqtot.\text{old memory} \xrightarrow{\text{channel-wise decay}} \text{retained memory} \xrightarrow{\text{delta correction}} \text{updated memory} \xrightarrow{q_t} o_t.

Softmax attention keeps the database rows themselves — effectively every prior token’s key and value.

KDA keeps only a learned compressed summary.


20. Why KDA is interesting beyond Kimi

KDA sits at the intersection of several ideas that have recently converged in sequence modeling:

  • linear attention — replace explicit pairwise token interactions with a recurrent sufficient state,
  • fast weights — let a neural network modify a small temporary memory during its forward pass,
  • online learning — interpret state updates as optimization steps on a per-token objective,
  • gating — learn how quickly different memories should decay,
  • structured state-space transitions — constrain the recurrence so it can be parallelized efficiently,
  • hybrid architectures — combine cheap finite-state layers with occasional full/global attention.

KDA is therefore useful not merely as a Kimi-specific trick. It is a concrete example of a broader direction: making the model’s context memory active and editable rather than an ever-growing passive cache.


21. What KDA does not solve

It is worth being precise about the limits.

Finite-state compression is still finite

A dk×dvd_k\times d_v matrix cannot losslessly encode an arbitrarily long context. Some information will interfere or be forgotten.

Long-context benchmark quality is architecture-dependent

Kimi Linear’s results come from a full trained model with a specific architecture, training recipe, hybrid layer pattern, MoE design, kernels, and system implementation. Dropping the KDA recurrence into an arbitrary model does not guarantee the same gains.

“Linear attention” does not mean every operation is literally O(L)O(L) with identical constants

Kernel design, chunk size, precision, head dimensions, batch size, and hardware matter enormously. The point is that the recurrent state avoids explicit growth with the number of past tokens during decode and enables subquadratic sequence processing in the linear-attention layers.


22. Final mental model

The easiest way to distinguish the mechanisms is this:

Softmax attention:

Keep every memory and search over them later.

Linear attention:

Compress every new memory into a matrix.

DeltaNet:

Before writing, correct what the matrix already believes for this key.

Gated DeltaNet:

Also let the entire memory head gradually forget.

Kimi Delta Attention:

Let different memory channels forget at different rates, while preserving the delta-rule overwrite behavior and a transition structure that can be implemented efficiently.

The core equation is only one line:

St=(IβtktktT)Diag(αt)St1+βtktvtT,ot=StTqt\boxed{ S_t=(I-\beta_tk_tk_t^T)\operatorname{Diag}(\alpha_t)S_{t-1} +\beta_tk_tv_t^T, \qquad o_t=S_t^Tq_t }

But that line combines three powerful ideas: learned forgetting, error-correcting memory writes, and fixed-size recurrent state.

That is the essence of Kimi Delta Attention.


Sources and further reading

  1. Kimi Team, “Kimi Linear: An Expressive, Efficient Attention Architecture.” Technical report, 2025. https://arxiv.org/abs/2510.26692
  2. Moonshot AI — Kimi Linear official repository. https://github.com/MoonshotAI/Kimi-Linear
  3. Official KDA kernels in Flash Linear Attention (FLA). https://github.com/fla-org/flash-linear-attention/tree/main/fla/ops/kda

The performance figures in this article are reported by the Kimi Linear authors; readers interested in implementation details and benchmark methodology should consult the technical report directly.