← notes Architectures

Kimi K3: a fixed-size memory, 896 experts, cheap sandboxes

Kimi K3 runs 69 of its 93 layers as Kimi Delta Attention, a linear attention with one fixed 128×128 state per head, and spends the budget on an 896-expert MoE and agentic RL in microVMs. This note prices each part and marks what the sources do not prove.

21 min read 7 interactive

The numbers in this note come from the K3 technical report, the released config.json, and a third-party blog post that the long walkthrough audits. Where a figure was rebuilt from config values rather than read from the report, or where a step is a reconstruction, the note says so.

Where long-context cost lives

A long-context design trades on three axes: cache bytes per token (state kept for the request and re-read at every decode step), FLOPs per token, and exactness (can the model recover an arbitrary earlier token, or only a lossy summary). Softmax attention is exact, but its cache and per-token FLOPs both grow with the length TT.

Price plain 96-head attention (MHA) on K3’s shapes. One layer caches 96×128×2×2 B=49,15296 \times 128 \times 2 \times 2\text{ B} = 49{,}152 B per token for keys and values in bf16. Over 93 layers and 10610^6 tokens that is 4.57 TB. Decode must read all of it for every new token: about 1.4 s per token at one H100’s 3.35 TB/s. Decode does about 1 FLOP per byte read, against the H100’s ridge point of about 295 FLOP/byte, so faster matmuls do not help. At decode, cache bytes are the latency.

K3’s per-request state has two parts. The 69 KDA layers hold a fixed state; the 24 MLA layers add a small cache per token:

bytes(T)=232,316,928⏟KDA, fixed+27,648 T⏟MLA, per token\text{bytes}(T) = \underbrace{232{,}316{,}928}_{\text{KDA, fixed}} + \underbrace{27{,}648\,T}_{\text{MLA, per token}}

The fixed term is 69×(96×1282×2+3×3×12,288×2)69 \times (96 \times 128^2 \times 2 + 3 \times 3 \times 12{,}288 \times 2) bytes: the recurrent states plus three short-convolution caches per layer. The per-token term is 24×1,15224 \times 1{,}152 B, which the next sections derive.

calculator

Three caches, one context slider

Move T from 256 tokens to 1M. Switch the ledger to FLOPs to compare one KDA head with one softmax head.

Ledger
K3 becomes cheaper than an all-MLA K3 after 2,923 tokens and ends 3.84× smaller at 1M, near the 3.875× ceiling. Per head, KDA's FLOPs are flat at 104,704 per token and pass softmax at 409 tokens.

Three crossovers fall out of the formula. Against a hypothetical K3 whose 69 KDA layers were MLA, the fixed state pays for itself after 232,316,928/(69×1,152)=2,923232{,}316{,}928 / (69 \times 1{,}152) = 2{,}923 tokens. Against uncompressed MHA it pays back after 68.5 tokens. Inside K3, the KDA bytes exceed the MLA bytes until 8,403 tokens; above that the MLA cache dominates and keeps growing.

KDA: decay, erase, write

Softmax attention needs a cache because the score exp⁡(q⊤k)\exp(q^\top k) does not factor: each past key gives a different function of the query, so every key must stay. A linear score ϕ(q)⊤ϕ(k)\phi(q)^\top \phi(k) factors, so the past can merge into one running matrix SS before the query arrives. For one head that matrix is 128×128=16,384128 \times 128 = 16{,}384 numbers at any length; a 1M-token list of keys and values is 256M numbers.

The price is capacity. A 128×128128 \times 128 matrix holds at most 128 orthogonal key directions. With random unit keys, the cross-talk on a read grows as (n−1)/128\sqrt{(n-1)/128} after nn writes: equal to the signal at 128 writes, 88× the signal at 1M. A fixed state needs two repairs. Correction handles key collisions: when a key comes back, replace its value instead of adding to it. Forgetting handles age: old content must fade to leave room.

The delta rule gives correction. Treat SS as a linear map from keys to values and take one gradient step per token on 12∥S⊤kt−vt∥2\tfrac12\lVert S^\top k_t - v_t\rVert^2 with step size βt\beta_t. With βt=1\beta_t = 1 and a unit key, a read at ktk_t then returns exactly vtv_t. KDA adds a decay vector ata_t, one factor per key channel, applied before the erase:

St=(I−βtktkt⊤)Diag(at) St−1+βtktvt⊤,o~t=St⊤qtS_t = \left(I - \beta_t k_t k_t^{\top}\right)\mathrm{Diag}(a_t)\,S_{t-1} + \beta_t k_t v_t^{\top}, \qquad \tilde{o}_t = S_t^{\top} q_t

Here StS_t has key channels on its rows and value channels on its columns, at∈(0,1)128a_t \in (0,1)^{128} is the per-channel retention, βt\beta_t is a scalar write strength, and o~t\tilde{o}_t goes on to an output gate and RMSNorm. Each of the 96 heads runs its own copy. Because Diag(at)\mathrm{Diag}(a_t) is a matrix, it does not commute with the erase; KDA measures the erase against the state a query would read after decay. Gated DeltaNet uses one scalar decay per head, so the order does not matter there.

Per-channel decay turns one head into a bank of timescales. A channel with constant rate aa keeps a write for about τ=−1/ln⁡a\tau = -1/\ln a tokens: 1.44 tokens at a=0.5a = 0.5, about 1,000 at a=0.999a = 0.999. With 128 rates, one head can keep a document-level fact in a slow channel and flush local syntax from a fast one. K3’s one change from Kimi Linear is a lower bound on the gate, gate_lower_bound = -5.0, so every at[c]≥e−5≈6.7×10−3a_t[c] \geq e^{-5} \approx 6.7 \times 10^{-3}. The decay also carries recency, which is why the MLA layers can drop positional encoding.

animation

The KDA state update on a 4×4 state

Press Play or Step to watch decay, erase and write for each token. Drag a purple decay bar. Switch the rule to Additive and read k₁ after t4.

Rule
Read with query
Toy numbers on a 4×4 state (K3 uses 128×128). After t4 the KDA read at k₁ returns the revised value exactly, while the additive rule returns the sum of both writes. Row c3 fades at a = 0.5. The write at k₄, which overlaps k₁ and k₂, damages both reads: the erase removes the whole k₄ direction.

The last token in the toy shows what KDA cannot do. The erase projects out the whole key direction, so a write damages every stored key that correlates with it. Add the rank bound and the need to keep ∏a≈1\prod a \approx 1 over every token for long retention, and exact retrieval from an arbitrary position is out of reach. K3 does not try to fix this inside KDA. It keeps 24 softmax layers next to it.

FlashKDA: why a chunk is 16 tokens

Run token by token, the recurrence is a rank-1 update of a 128×128128 \times 128 matrix: 0.5 FLOP per byte, and a reduction length of 1, which cannot use a Tensor Core (the bf16 MMA instruction always reduces over 16 elements). FlashKDA, Moonshot’s CUTLASS kernel for the forward pass, cuts the sequence into chunks of C=16C = 16 tokens. Each chunk reads the carried state with one matmul, adds a causal 16×1616 \times 16 attention inside the chunk, and advances the state once. A 1M-token sequence becomes 62,500 serial steps instead of a million, and the delta rule folds into two 16×12816 \times 128 matrices through the WY / UT transform.

The inside-chunk scores multiply queries by the cumulative decay γ\gamma and divide keys by it, so bf16 must hold both γ\gamma and 1/γ1/\gamma. With the gate bound, the worst case over a chunk is e−5Ce^{-5C}:

Chunk CCworst e−5Ce^{-5C}bf16 (min normal 2−1262^{-126})
161.8×10−351.8 \times 10^{-35}normal number, fits
64 (Kimi Linear’s default)1.1×10−1391.1 \times 10^{-139}flushes to 0; e+5Ce^{+5C} overflows

The ceiling is C≤126ln⁡2/5=17.5C \leq 126 \ln 2 / 5 = 17.5, so 16 is the largest power of two that fits. The walkthrough reads the gate bound and the chunk size as one design choice; the report states the two separately, so that link is inferred. The blog reports that splitting the work into two kernels (a chunk-parallel one and a serial state walk) gave at least 15% end to end; that figure is not re-measured. The backward pass and the decode kernel are not released.

Twenty-four exact layers

Layer ℓ\ell runs Gated MLA if ℓ\ell is a multiple of 4 or ℓ=93\ell = 93; every other layer runs KDA. That is 23 blocks of (3 KDA + 1 MLA) plus one extra MLA layer at the top, so the last layer always attends globally. Layer 1 has a dense FFN; the other 92 have MoE FFNs.

MLA (from DeepSeek-V2) caches a 512-number latent plus a 64-number key channel per token, 576×2=1,152576 \times 2 = 1{,}152 B per layer, 42.67× less than MHA. In K3 the MLA layers use no positional encoding (NoPE), because the KDA decay already carries recency; the report credits this for reaching 1M tokens without RoPE rescaling or YaRN. Keeping the 64-wide channel in the cache when it is not rotated is the walkthrough’s reading of the config; without it the cache would be 1,024 B. A sigmoid output gate, σ(Wgxt)⊙o~t\sigma(W^g x_t) \odot \tilde{o}_t, sits before the output projection. K3 also uses Attention Residuals (AttnRes): each layer attends over the outputs of earlier 12-layer blocks instead of one residual stream.

diagram

The 93-layer map

Hover or tap a layer. Change the ratio and the context to see where the cache bytes go.

KDA : MLA ratio
Context

KDA: fixed state Gated MLA: grows per token dense FFN (layer 1)
KDA / MLA layers
cache, one request
KDA share
ceiling vs all-MLA
Kimi Linear val PPL*
Each row is one 12-layer Attention Residuals block. At 3:1 and 1M tokens, 99.2% of the bytes sit in the 24 MLA layers. Only 3:1 is K3; the other ratios use the same placement rule as a what-if. *PPL is from Kimi Linear's 27-layer sweep, not from K3.

Why 3:1. The direct evidence is Kimi Linear’s sweep at 27 layers: validation perplexity 5.77 for pure MLA, 5.65 at 3:1 and 5.70 at 7:1, with the same training loss at 3:1 and 7:1. Sparser global attention hurts generalisation, and the ability that erodes is retrieval. Other hybrids point the same way: on needle-in-a-haystack, MiniMax-01’s pure linear model scored 10.9 against 95.7 for its hybrid. Two cautions. There is no published ratio ablation at K3 scale. And MiniMax moved back to full attention in every layer of M2, citing multi-hop reasoning deficits at scale.

The layer map also shows the limit of the design. The 69 KDA layers remove most layers from the growth term, but at 1M tokens their 221.55 MiB is under 1% of the request. Further long-context gains must come from the MLA layers themselves, for example by windowing or sparsifying them, not from the ratio alone.

896 experts and a closed-form balance

Each MoE layer has 896 routed experts, 16 active per token, and 2 shared experts. K3 projects the 7,168-wide residual down to a 3,584-wide latent before routing, so routed experts read and write half-width vectors (each expert’s FFN hidden width is 3,072). The shared experts stay at full width. Halving the routed width halves the bytes each token sends across GPUs, which is what makes 896 experts affordable. Note that K3 is not sparser than K2 (3.75% active against 3.13%); what grows is the expert count, 2.33× K2’s 384.

The router scores s=σ(Wrx)s = \sigma(W_r x) and adds a per-expert bias bb that only affects which experts win, never the gradient. DeepSeek-V3 nudges each bias by a fixed ±γ\pm\gamma per step. The step size trades slow adaptation against oscillation. Quantile Balancing computes the bias instead. Take the (K+1)(K{+}1)-th largest biased score of token tt as its cutoff θt\theta_t. Expert ii‘s margin on token tt is rt,i=st,i−θtr_{t,i} = s_{t,i} - \theta_t, and the expert wins the token when rt,i>−bir_{t,i} > -b_i. For a target of mm tokens per expert, the bias is minus the (m+1)(m{+}1)-th largest margin, then mean-centred. At scale the quantile comes from a per-expert histogram summed by one integer all-reduce: about 0.92 MB per layer at 256 bins, against about 940 MB of expert all-to-all. The exact binning code is a reconstruction; the blog confirms the histogram and the all-reduce.

playground

Fixed step against Quantile Balancing

Press Step or Play: both rules see the same batches. Press Shift data to swap the hot and cold experts, and change γ.

fixed step ±γ Quantile Balancing target m = SK/E = 500
step
max load / m, fixed step
max load / m, QB
Toy router: 8 experts, 2 active, 2,000 tokens per batch. QB removes most of the imbalance in one step and settles near the batch-noise floor within a few, also after a shift. The fixed step needs many steps and then ripples. QB is not exact in one step: it holds every token's cutoff fixed, and the cutoffs move once the biases change.

Exact aggregate balance is what MoonEP, K3’s expert-parallel runtime, builds on. If every rank receives exactly S×KS \times K rows per step (SS tokens per rank, K=16K = 16), the receive buffer has a fixed shape. The CPU then launches each layer without asking the GPU for token counts, and the layer can be captured as a CUDA graph. DeepEP instead sizes for the worst case, S×K×RS \times K \times R rows over RR ranks. The skew that remains inside one step is handled by a planner that runs in one warp, with its state in registers. It copies an expert from an overloaded rank to an underloaded one for that step. The source gives two smaller savings: a token whose 16 experts share a rank sends its row once (about 20% fewer bytes at 32 ranks, under a uniform routing model), and rows arrive grouped by expert, so no permutation kernel runs.

Nine teachers, one student

Post-training runs SFT, then RL, then distillation. RL trains one model for each pair of domain (general, general agents, coding agents) and effort level (low, high, max): nine models. Effort is a hard budget. A trajectory longer than τbud b0(x)\tau_{\mathrm{bud}}\, b_0(x) tokens gets reward −1-1 whatever its task score, so every in-budget answer, even a wrong one, beats every over-budget answer. The multiplier τbud\tau_{\mathrm{bud}} is annealed down per domain to make the high and low variants. The RL objective is not GRPO. It follows K2.5: a group-mean baseline and a squared log-ratio penalty per token, which tolerates the staleness of partial rollouts.

MOPD (multi-teacher on-policy distillation) merges the nine into one student. The student samples its own trajectory, and the one teacher that matches the sampled (domain, effort) pair scores each token:

rt=clip ⁣(sg ⁣(log⁡πteacher(d,e)(yt∣x,y<t)πθ(yt∣e,x,y<t)),−Rmax⁡,Rmax⁡)r_t = \mathrm{clip}\!\left(\mathrm{sg}\!\left(\log \frac{\pi^{(d,e)}_{\text{teacher}}(y_t \mid x, y_{<t})}{\pi_\theta(y_t \mid e, x, y_{<t})}\right), -R_{\max}, R_{\max}\right)

Here sg is stop-gradient. Used as a policy-gradient reward, this log-ratio minimises the reverse KL from student to teacher on the student’s own states. Off-policy distillation trains on teacher text and does not teach the student to recover from its own errors. The student is conditioned on the effort level and the teacher is not, which is how one checkpoint gets a runtime low | high | max switch. The reward is dense, so distillation runs on the same RL infrastructure, partial rollouts included; that consequence is inferred, not stated.

playground

Reverse KL commits, forward KL hedges

Drag the student's bars. Try the Sharp and Flat presets: both are at the same total-variation distance from the teacher.

Student preset
teacher p (fixed) student q (drag a bar) reward log p/q > 0 reward < 0
reverse KL(q‖p), MOPD
forward KL(p‖q), off-policy
TV distance
mean reward under q
Toy four-token vocabulary from the walkthrough. Reverse KL, which MOPD minimises, prefers the sharp student (0.261 against 0.311). Forward KL prefers the flat one. The mean reward under the student's own samples is minus the reverse KL, until the clip acts. K3 publishes no Rmax.

Mode-seeking matters here because the nine teachers disagree by design. A low-effort coding teacher and a max-effort general teacher differ at states that look alike, and a mass-covering objective would blur them into an average. The report also says that finer top-kk distillation objectives showed no clear advantage.

51 million sandboxes

Agentic RL gets its reward by executing: run tests, install packages, start servers. Each concurrent trajectory needs its own isolated machine. K3’s training and evaluation created 51,219,741 sandboxes from 1,505,678 images, about 34 boots per image, so the runtime must boot unfamiliar images cheaply, not only clone a hot one. AgentENV runs Firecracker microVMs on overlaybd images with a custom ublk driver. The report gives a 133 ms checkpoint and a 49 ms resume (best case), zero CPU and memory for a paused sandbox, and memory overcommit up to 6.5×. Model inference can take up to 98% of a sandbox’s lifetime.

animation

Pause between turns

Press Play or drag the time line. Raise the resume latency toward 2 s and watch the overhead.

resident: resume + tool call + checkpoint paused: 0 CPU, 0 RAM (policy thinks)
resident now, pause policy
idle share of a turn
memory-time saved
pause overhead on wall clock
Toy schedule from the walkthrough: 10 s thinking and a 0.2 s tool call per turn. Pausing holds memory 26.7× less of the time, and snapshots take 1.75% of the wall clock. At a 2 s resume the overhead is 17.3%, and pausing stops being an easy win.

This is what lets partial rollouts work. The scheduler parks unfinished trajectories and resumes them in the next iteration. With 1M-token rollouts of very different lengths, it does that all the time. Fork gives reward judging a disposable copy, so scoring leaves no side effects. The dependency of partial rollouts on near-free pause is the walkthrough’s inference; the report gives the 98% figure and the scheduler separately.

Serving: prefix caching with a recurrent state

An agent’s next turn shares nearly every token with the previous one, so prefix caching is the largest serving lever. The report’s example: at a 1M-token window, a coding request carries a 400K-token prefix and adds only 4K new tokens. (The 1M is the window; this request is 404K tokens. Reading 1M as the request length gives a 600K prefill, which is wrong.)

A KV cache is append-only, so every prefix of it is a valid cache. A KDA state is overwritten in place by every token, so the state at an earlier position no longer exists. Prefix caching therefore needs explicit checkpoints. K3 hashes the stream in 512-token blocks, chains the hashes, and stores both MLA pages and KDA checkpoints in one paged pool with 6,144-token physical blocks. A lookup finds the longest matching hash prefix ℓ\ell, then steps back to the newest checkpoint at or before it and recomputes the gap RR.

playground

Where a cache hit resumes

Drag the match end along the strip. Change the checkpoint spacing and the session length.

Session length
matched prefix (KV cached) roll-forward R (recompute) KDA checkpoint
resume at / roll-forward R
prefill time: hit / miss @10⁴ tok/s
memory: checkpoints / MLA KV
mean R over hit positions
One checkpoint is 221.55 MiB, the MLA cache of about 8,400 tokens. A checkpoint on every block costs 16× the KV cache it serves. At one per 16 blocks the checkpoints cost about as much as the KV cache, and a hit still recomputes only a few thousand tokens instead of the whole prefix.

The source does not say which checkpoint policy K3 uses. Uniform spacing assumes hits are spread evenly. If hits cluster at a few points (a system prompt, the end of the last turn), keeping states only at those points can be better. Context compaction has a cost here too: rewriting the middle of a context changes every later hash and drops every later checkpoint. K3 scores 91.2 on BrowseComp with compaction past 300K tokens and 90.4 without it. That gap is within noise, and the run does not measure the fixed state.

What to believe

Most headline figures reconcile to the last digit: the 69/24 split, the 221.55 MiB state, the 27 KiB per token, the 2,923 breakeven, the 51,219,741 sandboxes. Several claims need their context:

  • “2.5× scaling efficiency over K2” means FLOPs to reach the same loss. The fit covers one decade of FLOPs with no fit constants or error bars, and the report credits architecture, data and recipe together. Because K3 activates 3.2× more parameters per token than K2, the same claim implies about 8× fewer training tokens; the report does not state that number.
  • Benchmarks are vendor-reported. On Terminal-Bench 2.1 the vendor gives 88.3, and Artificial Analysis gives 85 on its own harness.
  • The weak spot is research-level reasoning: CritPt 23.4 and HLE 43.5 without tools, while GPQA Diamond is 93.5. The walkthrough’s reading, which is inferred, is that RL rewards loops a tool can check. Its budget penalty pushes against long derivations, and there is no cheap verifier for frontier physics.
  • Small conflicts remain: the report lists one MTP layer but the config sets none, and the overcommit figure is 6.5× in the report but 9.6× in the AgentENV README.