LLM architecture at trillion scale: width, depth and length in Kimi K3
Kimi K3 as a case study in three scaling problems: routing among hundreds of experts, letting layers reach back across the stack, and holding a million-token memory at fixed cost.
- Summary
- Why this matters for robotics
- Deep dive: width, routing 896 experts (interactive)
- Deep dive: length, hybrid linear + global attention
- Deep dive: depth, attention residuals
- Deep dive: what this means for serving
- Deep dive: the compounding-learning lesson
- Playbook
- Self-check
- Glossary & further reading
1. Summary
TL;DR
The post's author, a backend engineer, started teaching themselves about LLMs five months ago. Today they could follow over half of Baseten's deep-dive on trillion-parameter inference, and they call it compounding learning paying off.
Kiely's framing: going past a trillion parameters forces three problems on inference engineers:
- Width: routing between hundreds of sparse experts.
- Depth: mixing global and linear attention.
- Length: handling 1M-token sequences.
Kimi K3 (2.8T total, 104B active per token) answers each one:
- width: Stable LatentMoE
- depth: Attention Residuals
- length: a 3:1 hybrid of Kimi Delta Attention (KDA) and Gated MLA
| Kimi K3 at a glance (from the report) | |
|---|---|
| Parameters | 2.8T total · 104B active per token |
| Layers | 93: 69 KDA + 24 Gated MLA (3 KDA : 1 MLA per block, plus a final MLA) |
| Experts | 896 routed (16 picked per token) + 2 shared, per layer. Sparsity 56×. |
| Context | 1,048,576 tokens. No positional encoding at all ("NoPE"). |
| Vision | MoonViT-V2, 401M parameters, trained from scratch with next-token prediction |
| Precision | MXFP4 expert weights / MXFP8 activations, with quantisation-aware training |
| Claimed gain | ~2.5× scaling efficiency over Kimi K2 |
Framing differences: the post lists Attention Residuals under "length", but the report says AttnRes works across depth (layers). The hybrid attention handles sequence length. Kiely's tweet puts "mixing global and linear attention" under depth, likely because the mix alternates layer by layer. This module follows the report's mapping.
2. Why this matters for robotics
Track: LLM. This is about how frontier LLMs are built and served. It carries over to robotics because robot foundation models (VLAs) use the same transformer backbones, with much tighter latency and memory budgets.
- Mixture-of-experts (MoE) for robots: one policy for many robot bodies and many skills is a natural fit for expert routing. Only the relevant experts run per input, which keeps on-board compute down.
- Fixed-size memory = long-horizon robots. A robot streaming camera frames for an hour can't keep a full attention cache of every frame. KDA keeps a fixed-size state updated each step, the same shape as a recurrent state estimator. The delta-rule update even resembles the online least-squares filters used in classical robotics.
- Forgetting is a design parameter. KDA's per-channel decay is learned forgetting. That's the same lesson as the intent model in Module 03: memory that can't forget gets stuck.
- Native vision: K3 trains its vision encoder from scratch inside the language model and says pre-trained contrastive encoders (SigLIP-style) were unnecessary and less stable. That's a relevant data point for VLA design, which usually starts from SigLIP.
- Deployment tricks transfer: quantisation-aware training, speculative decoding and distillation are how big models get onto small robot computers (Module 04).
3. Deep dive: width, routing 896 experts
In a mixture-of-experts layer, a small router scores each token against every expert and sends it to the top-k. K3 picks 16 of 896, so each token touches under 2% of the routed weights. That's how it has 2.8T parameters but only 104B active.
Two problems appear at this sparsity, and K3 adds three fixes for them:
Problem 1: traffic and exploding activations → LatentMoE + normalisation + SiTU-GLU
- LatentMoE: routed experts work in a compressed space (3,584 dims, vs 7,168 for the full model), so sending a token to 16 experts costs half the traffic. Two full-width shared experts handle common transformations for every token.
- That path chains about four matrix multiplies, and at 2.8T scale its activations blew up. Fixes:
- an RMSNorm before projecting back up
- SiTU-GLU, a new activation that behaves like SwiGLU near zero but is soft-capped (output bounded at β₁β₂ = 100) using
β·tanh(x/β). Bounded activations matter because they run in low precision (FP4/FP8).
Problem 2: load balancing → Quantile Balancing
If the router sends most tokens to a few favourite experts, those experts become hot spots that slow distributed training. Others get few tokens and stop learning ("dying experts"). The usual fix adds a per-expert bias to the routing scores, nudged up or down by a fixed step each training step. With 896 experts, fixed steps either adapt too slowly or oscillate.
Quantile Balancing computes each expert's bias directly:
- The target load is
q = m·k/ntokens per expert. - For each expert, find the score margin that exactly
qtokens exceed. That's a quantile of the margins. - Set the bias so that cut-off becomes the selection line.
The bias only affects which experts get picked, not how their outputs are weighted. It's computed from one batch and applied to the next. At scale they estimate the quantile with histograms summed across GPUs.
Interactive: top-k routing vs. Quantile Balancing
256 tokens, 16 experts, top-2. Router scores are skewed, so some experts are naturally popular. Bars show tokens per expert. The dashed line is the target load q = 32.
4. Deep dive: length, hybrid linear + global attention
Standard (global) attention compares every token with every earlier token. Its cost grows with n² and its key-value cache grows with n. At 1M tokens, both hurt. K3 interleaves two kinds of layer, 3 to 1:
| KDA (linear attention) | Gated MLA (global attention) | |
|---|---|---|
| Memory per sequence | Fixed-size state matrix per head | Cache grows with every token (compressed into a small latent vector) |
| Compute | Linear in length | Quadratic in length |
| Strength | Recency, position, cheap streaming | Exact recall of anything, anywhere in context |
| Share of layers | 69 of 93 | 24 of 93 (and always the final layer) |
The KDA update, in plain words
S_t = (I − β_t k_t k_tᵀ) · Diag(α_t) · S_{t−1} + β_t k_t v_tᵀ
output_t = S_tᵀ q_t
Diag(α_t): fade old memory, channel by channel. Each channel learns its own forgetting rate.(I − β k kᵀ): erase whatever is currently stored under keyk.+ β k vᵀ: write the new valuevunder keyk, with strength β.- Read by querying the state with
q.
This "delta rule" is online regression: each step nudges the memory to map k → v correctly. Robotics readers will recognise the shape: fixed-size state, predict, correct by the error. It's the same pattern as recursive least squares and Kalman-style estimators (an analogy, not an equivalence).
A numerics detail worth knowing: K3 bounds the log-decay to (−5, 0), so every channel keeps at least e⁻⁵ ≈ 0.7% per step. That sounds cosmetic, but it keeps intermediate values inside BF16 range. That lets all the work run as dense tensor-core matrix multiplies, removing a slow special-case path. Small bounds unlocking big speed is a recurring pattern (see SiTU-GLU above).
No positional encoding: the MLA layers use none. KDA's decay already tells the model how recent things are. So stretching context from 8K → 64K (pre-training) → 256K → 1M (cooldown) needs no positional-encoding retuning. The report also notes that length alone doesn't teach long-range skill. They synthesise tasks that can only be solved by combining information scattered across the full 1M tokens.
5. Deep dive: depth, attention residuals
A normal residual connection adds each layer's output into one running sum. By layer 90, everything earlier is blended into a single vector. The report likens this to how RNNs squeeze all of the past into one state.
Attention Residuals apply attention across layers:
- Each layer has a learned query vector.
- It attends over the outputs of earlier layers (and the original embedding).
- It picks a weighted mix of the representations it needs.
To keep memory down, K3 uses Block AttnRes. Layers are grouped into blocks of 12, each block is summed into one vector, and attention runs over the ~9 block summaries. Memory drops from O(layers × width) to O(blocks × width), and about 8 blocks recover most of the benefit.
A nice side effect: the speculative-decoding draft model reads features from blocks 1, 4 and the final block. AttnRes gives clean low-, mid- and high-level features for free.
Aside: the optimiser, Per-Head Muon
Like Kimi K2, K3 trains its matrix parameters with the Muon optimiser, which orthogonalises each update (Newton–Schulz iterations). For the attention projections, the report uses a per-head variant. Instead of orthogonalising the whole Q, K and V momentum matrices at once, it splits them by head and orthogonalises each head's block separately.
The report's reasoning: with full-matrix orthogonalisation, heads with larger gradients dominate the shared update direction while small-scale heads are under-normalised. Per-head treatment equalises update scale across heads, and the report credits it with more balanced learning, better stability at scale, and slightly lower optimiser overhead (the Newton–Schulz steps run on smaller blocks).
6. Deep dive: what this means for serving
This is Kiely's angle as an inference engineer. The report's serving section lists the consequences:
- Two caches, one pool. MLA's cache grows per token. KDA's is one fixed-size state per request. K3 packs both into the same paged memory pool with equal page sizes, so one allocator and one eviction policy handle both.
- Prefix caching gets harder. Reusing a shared prompt prefix needs the KDA state at that exact boundary, but states can only be checkpointed occasionally. They decouple hash granularity (512 tokens) from storage blocks (up to 6,144) and keep KDA checkpoints at boundaries.
- Request costs span ~1,000×, from short chats to 1M-token agent sessions. That requires cache-aware scheduling and budget-based admission control.
- Quantisation-aware training: experts are trained in MXFP4 throughout post-training, so the served model is the trained model. Compare Module 04, where int8 cost 0.5–0.7 WER points when applied after training.
- Speculative decoding: a one-layer draft model proposes up to 7 tokens, and the big model verifies them. They train the draft to maximise the acceptance rate directly instead of a KL proxy.
- Multi-teacher on-policy distillation: nine specialist teachers (by domain and reasoning effort) are merged into one student. It's Module 04's teacher → student pattern at frontier scale.
Baseten reports serving K3 at ~97 output tokens/s with 0.8 s latency on 1.05M-token context (Baseten model page).
7. Deep dive: the compounding-learning lesson
The quoting post's real message: 150 days ago none of this made sense to me; today I follow over half. Understanding compounds because each concept makes the next one cheaper to learn. Here's the prerequisite map for this video, with where this course covers each item:
| To follow… | You need | Where |
|---|---|---|
| MoE routing | Softmax/sigmoid, top-k, quantiles | 02 (stats), this module |
| Linear attention / KDA | Dot products, outer products, matrix state, recurrences | 02 (linear algebra, RNN/LSTM papers) |
| MLA / KV cache | Scaled dot-product attention, KV caching | 02 (Transformers paper, LLM internals) |
| Attention residuals | Residual connections (ResNet) | 02 (ResNet paper) |
| MXFP4 / QAT / speculative decoding | Number formats, quantisation, draft-and-verify | 04, 02 |
Pairing this with Module 03's advice: don't aim to understand everything on the first pass. Watch, note the 3–4 concepts you didn't follow, implement one of them from scratch (TensorTonic has MoE, attention and KV-cache problems), then re-watch. The second pass is where it compounds.
8. Playbook
- When reading any new model card, sort its features into width (experts/channels), depth (layers/residuals) and length (attention/context). It makes new architectures much easier to parse.
- For each, ask: what does it cost at training, and what does it cost at serving (memory, latency, cache reuse)?
- Look for the numerical-stability fix behind each feature (bounded decay, soft-capped activations, normalisation). At scale and low precision, these are what make it work.
- For robotics: prefer fixed-size-state memory for streaming sensors, use sparsity to fit more skills into on-board compute, and train with the quantisation you'll deploy with.
9. Self-check
K3 has 2.8T parameters. Why does each token only cost ~104B parameters of compute?
Each MoE layer runs only 16 of 896 routed experts (plus 2 shared) per token. The remaining expert weights sit idle for that token.
What problem does Quantile Balancing solve that fixed-step bias updates struggle with?
With 896 experts, a fixed step size either adapts too slowly or oscillates. QB sets each bias directly to the score quantile that gives that expert exactly its target load, in one step from the previous batch.
Why does a KDA layer's memory not grow with context length, while MLA's does?
KDA folds every token into a fixed-size state matrix (decay, erase, write). MLA keeps a compressed latent for every token so it can attend to any of them exactly.
Why keep any global-attention layers at all?
A fixed-size state must forget or compress. Exact recall of a detail from 800K tokens ago needs global attention. The 3:1 mix gets most of the efficiency while keeping that capability.
Why could K3 skip positional encodings entirely?
KDA's learned decay already encodes recency and order. The MLA layers then do content-based lookup. This also means extending to 1M tokens needs no positional-encoding retuning.
Robotics: why is a fixed-size recurrent state attractive for a robot watching a camera stream?
Memory and per-frame compute stay constant however long the robot runs, which suits fixed on-board hardware. A full attention cache would grow without bound.
10. Glossary & further reading
| Term | Meaning |
|---|---|
| MoE | Mixture of experts: many sub-networks, with a router choosing a few per token |
| Active vs total parameters | Weights used per token vs all weights stored |
| LatentMoE | Routed experts operate in a compressed (latent) space to cut traffic |
| Load balancing | Keeping token counts per expert even, for speed and so all experts learn |
| Linear attention | Attention with a fixed-size recurrent state. Cost linear in length. |
| Delta rule | Memory update that erases the old value at a key and writes the new one |
| KDA | Kimi Delta Attention: delta rule + learned per-channel forgetting |
| MLA | Multi-head Latent Attention (DeepSeek-V2): caches a small latent per token instead of full keys/values |
| KV cache | Stored keys/values from earlier tokens so they aren't recomputed |
| NoPE | No positional encoding |
| Attention Residuals | Layers attend over earlier layers' outputs instead of a single running sum |
| MXFP4 / QAT | 4-bit microscaling floats / training with quantisation in the loop |
| Speculative decoding | A small draft model proposes tokens, and the big model verifies several at once |
- Kimi K3 repo and technical report: sections 2 (architecture), 4.1.3–4.1.4 (distillation, QAT, drafting), 5.4 (serving)
- Philip Kiely's post and explainer video (Baseten). Kiely is the author of Inference Engineering.
- Kimi K3 on Baseten
- Related: Module 10: the scaffolding route to long context (Recursive Language Models), complementary to K3's architectural route
- Related: Module 07 explains the post-training stages (SFT, preference RL, verifiable rewards) that K3's pipeline builds on
- Kimi Linear (the KDA paper) and DeepSeek-V2 (MLA): references 64 and 28 in the report
- TensorTonic: mixture-of-experts, KV cache, speculative decoding, quantisation