LLMModule 05 · Model architecture at frontier scale

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.

Sources: @antiAIvo's post (in Chinese), quoting Philip Kiely (Baseten) and his team's 1-hour explainer video · Kimi K3 repo and technical report (Moonshot AI, Jul 2026). I couldn't watch the video. The technical detail below comes from the report, which is saved in sources/.

In this module
  1. Summary
  2. Why this matters for robotics
  3. Deep dive: width, routing 896 experts (interactive)
  4. Deep dive: length, hybrid linear + global attention
  5. Deep dive: depth, attention residuals
  6. Deep dive: what this means for serving
  7. Deep dive: the compounding-learning lesson
  8. Playbook
  9. Self-check
  10. 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:

Kimi K3 (2.8T total, 104B active per token) answers each one:

Kimi K3 at a glance (from the report)
Parameters2.8T total · 104B active per token
Layers93: 69 KDA + 24 Gated MLA (3 KDA : 1 MLA per block, plus a final MLA)
Experts896 routed (16 picked per token) + 2 shared, per layer. Sparsity 56×.
Context1,048,576 tokens. No positional encoding at all ("NoPE").
VisionMoonViT-V2, 401M parameters, trained from scratch with next-token prediction
PrecisionMXFP4 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.

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

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 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.

Step
0
Max / target
–
Idle experts
–
Method
–

Each step routes a fresh batch using the bias computed from the previous one, as in the report. Compare how many steps each method needs to flatten the bars. Expect Quantile Balancing to get there in 1–2 steps. The fixed step takes ~10 and keeps wobbling. The leftover unevenness is sampling noise from each fresh 256-token batch.

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 sequenceFixed-size state matrix per headCache grows with every token (compressed into a small latent vector)
ComputeLinear in lengthQuadratic in length
StrengthRecency, position, cheap streamingExact recall of anything, anywhere in context
Share of layers69 of 9324 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
  1. Diag(α_t): fade old memory, channel by channel. Each channel learns its own forgetting rate.
  2. (I − β k kᵀ): erase whatever is currently stored under key k.
  3. + β k vᵀ: write the new value v under key k, with strength β.
  4. 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:

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).

Source: Kimi K3 technical report, §2.5. How Muon works: Module 12, video 08.

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:

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 needWhere
MoE routingSoftmax/sigmoid, top-k, quantiles02 (stats), this module
Linear attention / KDADot products, outer products, matrix state, recurrences02 (linear algebra, RNN/LSTM papers)
MLA / KV cacheScaled dot-product attention, KV caching02 (Transformers paper, LLM internals)
Attention residualsResidual connections (ResNet)02 (ResNet paper)
MXFP4 / QAT / speculative decodingNumber formats, quantisation, draft-and-verify04, 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

  1. 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.
  2. For each, ask: what does it cost at training, and what does it cost at serving (memory, latency, cache reuse)?
  3. 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.
  4. 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

TermMeaning
MoEMixture of experts: many sub-networks, with a router choosing a few per token
Active vs total parametersWeights used per token vs all weights stored
LatentMoERouted experts operate in a compressed (latent) space to cut traffic
Load balancingKeeping token counts per expert even, for speed and so all experts learn
Linear attentionAttention with a fixed-size recurrent state. Cost linear in length.
Delta ruleMemory update that erases the old value at a key and writes the new one
KDAKimi Delta Attention: delta rule + learned per-channel forgetting
MLAMulti-head Latent Attention (DeepSeek-V2): caches a small latent per token instead of full keys/values
KV cacheStored keys/values from earlier tokens so they aren't recomputed
NoPENo positional encoding
Attention ResidualsLayers attend over earlier layers' outputs instead of a single running sum
MXFP4 / QAT4-bit microscaling floats / training with quantisation in the loop
Speculative decodingA small draft model proposes tokens, and the big model verifies several at once