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.
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 .
Price plain 96-head attention (MHA) on K3’s shapes. One layer caches B per token for keys and values in bf16. Over 93 layers and 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:
The fixed term is bytes: the recurrent states plus three short-convolution caches per layer. The per-token term is 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.
Three crossovers fall out of the formula. Against a hypothetical K3 whose 69 KDA layers were MLA, the fixed state pays for itself after 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 does not factor: each past key gives a different function of the query, so every key must stay. A linear score factors, so the past can merge into one running matrix before the query arrives. For one head that matrix is numbers at any length; a 1M-token list of keys and values is 256M numbers.
The price is capacity. A matrix holds at most 128 orthogonal key directions. With random unit keys, the cross-talk on a read grows as after 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 as a linear map from keys to values and take one gradient step per token on with step size . With and a unit key, a read at then returns exactly . KDA adds a decay vector , one factor per key channel, applied before the erase:
Here has key channels on its rows and value channels on its columns, is the per-channel retention, is a scalar write strength, and goes on to an output gate and RMSNorm. Each of the 96 heads runs its own copy. Because 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 keeps a write for about tokens: 1.44 tokens at , about 1,000 at . 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 . 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.
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 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 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 tokens. Each chunk reads the carried state with one matmul, adds a causal 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 matrices through the WY / UT transform.
The inside-chunk scores multiply queries by the cumulative decay and divide keys by it, so bf16 must hold both and . With the gate bound, the worst case over a chunk is :
| Chunk | worst | bf16 (min normal ) |
|---|---|---|
| 16 | normal number, fits | |
| 64 (Kimi Linear’s default) | flushes to 0; overflows |
The ceiling is , 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 runs Gated MLA if is a multiple of 4 or ; 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, 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, , 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.
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 and adds a per-expert bias that only affects which experts win, never the gradient. DeepSeek-V3 nudges each bias by a fixed per step. The step size trades slow adaptation against oscillation. Quantile Balancing computes the bias instead. Take the -th largest biased score of token as its cutoff . Expert ‘s margin on token is , and the expert wins the token when . For a target of tokens per expert, the bias is minus the -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 γ.
Exact aggregate balance is what MoonEP, K3’s expert-parallel runtime, builds on. If every rank receives exactly rows per step ( tokens per rank, ), 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, rows over 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 tokens gets reward whatever its task score, so every in-budget answer, even a wrong one, beats every over-budget answer. The multiplier 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:
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.
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- 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.
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 , then steps back to the newest checkpoint at or before it and recomputes the gap .
playground
Where a cache hit resumes
Drag the match end along the strip. Change the checkpoint spacing and the session length.
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.