Kimi K3 · Lesson 2 of 14 · Sequence axis

KDA, the memory matrix

Three quarters of K3's attention layers never look at a past token. They keep a fixed-size notebook instead, and continuously fade, erase, and overwrite it.

Last lesson you drew the block: three KDA layers to one Gated MLA layer. This lesson is about what a KDA layer actually does. By the end you should be able to explain, without equations, why a fixed-size memory makes a million-token context affordable, and what it gives up in exchange.

The mechanism only makes sense against the thing it replaces, so we start there.

What standard attention actually stores

Here is the part of a transformer that matters for this lesson. When a model reads a token, it produces three vectors from it. The query says what this token wants to know. Its key is a label advertising what it offers in return. The value is the content it hands over if asked.

To compute attention for a new token, the model takes that token's query and compares it against the key of every token before it. Strong matches get a high weight, weak matches get near zero, and the output is the weighted blend of all those values.

KV cache
Because keys and values never change once computed, a model saves them and reuses them for every subsequent token. That saved pile is the KV cache. It is why generating token 900 does not require re-reading tokens 1 through 899 from scratch.

The cache is the whole problem. It has to hold a key and a value for every token so far, so it grows without limit as the context fills. And each new token must compare itself against every entry, so the work per token grows too.

    FULL ATTENTION — keep everything, compare against everything

    token:   1     2     3     4     5   ...   n
             │     │     │     │     │         │
    cache:  [k₁]  [k₂]  [k₃]  [k₄]  [k₅]  …  [kₙ]      grows with n
            [v₁]  [v₂]  [v₃]  [v₄]  [v₅]  …  [vₙ]

    new token n+1 arrives with query q
                          │
                          ├──▶ compare q against ALL n keys
                          │
                          └──▶ blend ALL n values by match strength

    cost per token:  proportional to n        ← gets slower as you go
    memory:          proportional to n        ← never stops growing
The bill for perfect recall. Full attention can reach any past token exactly, at any distance. The price is state and work that both scale with how much you have read.

At a 4,000-token context nobody cares. At a million tokens, both terms are ruinous. Drag this to feel the shape:

The numbers above are relative units showing growth shape, not K3's exact byte counts. The shape is the point: full attention's state climbs a thousandfold between 1K and 1M, while a KDA layer's stays flat.

The other way to remember

Now the alternative. Instead of keeping every past key and value, what if a layer kept one fixed-size scratchpad and wrote each new token into it as it arrived?

That scratchpad is a matrix, and it is the central object in KDA. Call it S. Its job is to store associations: given a key, hand back the value that key was filed under. It is the same read-a-key-get-a-value contract as the KV cache, except the storage never grows, because new writes go on top of old ones.

Linear attention
A family of attention mechanisms that replace the growing KV cache with a fixed-size state updated once per token. Cost per token is constant, so total cost over a sequence is linear in length rather than quadratic. KDA is the variant K3 uses.
Recurrent state
The fixed-size memory carried from one token to the next. In KDA this is a matrix of shape (key dimension × value dimension), one per attention head.
Outer product
Multiplying a column vector by a row vector to get a matrix. It is how one key–value pair becomes a memory entry: the result stores the association between that key and that value, ready to be read back later.

The obvious way to write into such a matrix is to just add: take the new key and value, form their outer product, and add it to what is already there. That is classical linear attention, and it has a well-known failure. Nothing is ever removed, so the matrix accumulates every association ever written and the useful signal drowns in old writes. Read from it after a hundred thousand tokens and you get mud.

KDA fixes this with two ideas layered on top of the plain write. Both are about removing information rather than adding it.

Fade, erase, write

This is the core of the lesson. Every KDA layer performs three operations per token, in order.

One KDA step: fade, erase, write Memory state arrives from the previous token and passes down through three operations in order. First fade, which multiplies every channel by its own retention factor alpha, a number just under one, so channels the model deems stale decay fast while channels it wants to preserve decay slowly. Second erase, which looks up what the current key already retrieves from memory and subtracts it, clearing the slot so the new value replaces the old rather than piling on top. Third write, which files the new value under the new key with strength beta. The updated memory passes to the next token. Reading is separate: the output is the memory transposed times the query, one matrix multiply with no scan over history. memory S from t − 1 FADE × α(t) ERASE what kₜ already got WRITE kₜ → vₜ strength β memory S at t state carried in from the previous token passed to the next token ① FADE Multiply every channel by its own retention factor α, a number just under 1. Channels the model deems stale decay fast; channels it wants to preserve decay slowly. Decided per token, per channel, from the token itself. ② ERASE Look up what this key already retrieves from memory, and subtract it. This clears the slot before writing, so the new value replaces the old one instead of piling on top. ③ WRITE File the new value vₜ under the new key kₜ, with strength β. Small β means a tentative note, large β means commit firmly. READ output = Sᵀq the query looks up the memory: one matmul, no history scan
One KDA step. The three heavier boxes are the update; the lighter ones are the state passing through. Fade is the forget gate, and it is channel-wise: each dimension of the memory has its own decay rate rather than the whole matrix dimming uniformly. Erase is the delta rule, borrowed from classical associative memory. Together they make the fixed-size matrix behave like a managed workspace rather than a landfill.

Step ② is the one worth pausing on, because it is the "delta" in Kimi Delta Attention and it is the least intuitive. The name comes from the delta rule in classical associative-memory research: rather than blindly adding, you first ask what the memory currently returns for this key, then write the difference. If the memory already holds a stale association for a similar key, that stale association gets cleared instead of blended with the new one.

Step ① is what KDA adds over its predecessor, Gated DeltaNet. The decay is not one scalar for the whole memory but a separate factor for every channel, computed from the current token.1 The layer can hold one part of the memory steady across thousands of tokens while letting another part turn over rapidly.

show me the actual equation

From §2.1.1 of the report, this is the whole recurrence in one line:1

S_t = (I − β_t k_t k_tᵀ) · Diag(α_t) · S_{t−1} + β_t k_t v_tᵀ õ_t = S_tᵀ q_t

Reading it right to left, in the order things happen:

Where α and β come from, also §2.1.1:

q_t, k_t = L2Norm( Swish( ShortConv( W_q/k · x_t ) ) ) v_t = Swish( ShortConv( W_v · x_t ) ) β_t = Sigmoid( W_β · x_t ) ∈ (0,1) z_t = W_α↑ ( W_α↓ · x_t ) + b_α ← low-rank, per-head bias

Two details that matter later. ShortConv is a small convolution across neighbouring positions, so each query, key, and value sees a little local context before entering the recurrence. L2Norm on q and k bounds their magnitude, which keeps the erase term well behaved. The decay logits z_t come from a low-rank projection plus a per-head bias, and lesson 3 is about how z_t becomes α_t, a seemingly small choice that turns out to unlock the entire Tensor Core fast path.

What this buys and what it costs

The gain is the one the simulator showed. State per layer is constant, so a KDA layer costs the same at token 900,000 as at token 9. This is the mechanism behind K3's million-token context. It is also why K3 needs no positional encoding in its global layers, which is a strange enough claim that it gets its own treatment in lesson 3.

The cost is real and you should be able to state it. A fixed-size memory is a lossy summary. Full attention can retrieve token 12,345 exactly, because token 12,345's key and value are still sitting in the cache untouched. KDA cannot promise that. It has faded and overwritten that region of memory many times since, and what survives is whatever the gates chose to preserve.

Which is why K3 is a hybrid

This is the reason the block is 3:1 and not 4:0. Some tasks genuinely need exact retrieval from an arbitrary distance: finding one line in a large file, or quoting a number from page 200. The Gated MLA layers keep that capability, and the report places one at the very end of the backbone so the model's final act is always full global attention. K3 pays for perfect recall in a quarter of its layers and takes the cheap linear path in the rest.

Locating this on the map

SEQUENCE AXIS — two ways to mix information across tokens
Layer typeState grows?Exact recall?Layers in K3
KDA
linear
no, fixed approximate 69  (74%)
Gated MLA
global
yes, with n
(compressed)
exact 24  (26%)
Division of labour on the sequence axis. Neither mechanism is strictly better. The hybrid exists because their weaknesses are complementary.

MLA has a trick of its own for that growing cache: it stores one small latent vector per token instead of full keys and values. Lesson 3 takes it apart. Note what it does and does not achieve, because the distinction matters for the 1M-context claim: it shrinks the cache substantially, but the cache still grows with every token.

Check yourself

From memory. These are deliberately the questions that separate understanding the mechanism from recognising the words.

Why does a plain linear-attention layer degrade over a long context?

Classical linear attention only ever adds outer products to its state. With no removal mechanism, signal-to-noise falls as the sequence runs on. KDA's fade and erase steps exist precisely to remove.

What does the "delta" in Kimi Delta Attention refer to?

The delta rule comes from classical associative memory: read what the memory currently returns for this key, then write the difference. This makes a write behave as replacement rather than accumulation.

A task needs one exact figure quoted from deep in a long document. Which K3 layers carry that?

Exact long-range retrieval is precisely what KDA gives up and what the periodic global layers preserve. This complementarity is the whole argument for a hybrid, and it is why the final backbone layer is Gated MLA.

What comes next

Lesson 3 finishes the sequence axis with the two choices that make KDA practical at scale rather than merely elegant. First, how a memory that is defined one token at a time can be computed in parallel on a GPU. Second, the single constant g_min = −5, which looks like an arbitrary implementation detail and is in fact the reason K3's kernels run entirely on Tensor Cores. That lesson also covers Gated MLA properly, and the NoPE decision.