
Inside a 53.6x Wan2.2 Speedup
How sparse attention, persistent CUDA kernels, four-step distillation, and NVFP4 turn a 133-second pipeline into near-real-time video generation.
Read MoreHow attention and memory research transformed a 124M GPT-2 baseline into Kimi K3's hybrid 2.8T architecture.

Ali Taha's worklog, 22580: From GPT2 to Kimi3, Explained, is a code-first tour through seven years of language-model architecture. It starts with a small GPT-2 implementation, follows the pressure created by long sequences and growing KV caches, and ends inside Kimi K3's hybrid system of recurrent memory, periodic softmax retrieval, sparse experts, and depth-wise attention.
This technical literature edition reconstructs the complete argument in a more explicit sequence. It cross-checks the worklog against Moonshot AI's official Kimi K3 release, the original GPT-2 report, and the papers behind linear attention, DeltaNet, Gated DeltaNet, Kimi Delta Attention, and Attention Residuals.
Evidence status: architecture dimensions and model counts below come from Moonshot AI's official report. The explanatory path and several implementation observations come from Taha's worklog. Performance figures such as 6x decode throughput or 2.5x scaling efficiency are author-reported results from the cited model papers, not universal guarantees for every sequence length, batch size, kernel, or device.
The title is mathematically real, but only under a specific comparison:
2.8 trillion / 124 million = 22,580.6
The denominator is the compact GPT-2 configuration used by the worklog and by Karpathy's nanoGPT implementation: 12 layers, 12 attention heads, and a 768-dimensional hidden state. nanoGPT counts that configuration at about 124 million parameters. OpenAI's original GPT-2 report listed the small model at 117 million and the largest GPT-2 at roughly 1.5 billion, so "22,580 GPT-2s" is not a ratio to GPT-2 XL.
There is a second distinction. Kimi K3 has 2.8T total parameters, but its sparse Mixture-of-Experts path activates 104B parameters per token. The active-parameter ratio to the 124M baseline is therefore about 839x, not 22,580x.
| Comparison | Approximate ratio | What it describes |
|---|---|---|
| Kimi K3 total / GPT-2 small | 22,580x | Stored model capacity |
| Kimi K3 active / GPT-2 small | 839x | Parameters participating per token |
| Kimi K3 total / GPT-2 XL | 1,816x | Total capacity against the largest GPT-2 |
| Kimi K3 active / GPT-2 XL | 67x | Active sparse compute against GPT-2 XL |
The number is a useful scale marker, not a measure of intelligence, training compute, energy use, latency, or quality. The deeper story is how the model uses memory and capacity.
GPT-2 is a stack of decoder blocks. Token and position embeddings enter the stack. Each block applies causal self-attention and an MLP, with residual connections carrying information through depth. A final normalization and language-model head produce vocabulary logits.
x = token_embedding(tokens) + position_embedding(positions)
for block in transformer_blocks:
x = x + block.attention(block.norm_1(x))
x = x + block.mlp(block.norm_2(x))
logits = language_model_head(final_norm(x))
The 124M configuration is small enough to understand as a complete program:
| GPT-2-small component | Value |
|---|---|
| Decoder layers | 12 |
| Attention heads | 12 |
| Hidden width | 768 |
| Context length | 1,024 tokens |
| Vocabulary | 50,257 tokens |
| Parameters in nanoGPT convention | About 124M |
Autoregressive generation consumes only the logits at the newest position. Without caching, the model would recompute projections for every earlier token after each new token is appended. A KV cache avoids that duplication by retaining the keys and values produced at previous positions.
That optimization creates the next bottleneck: the cache grows with sequence length. Each new query still needs to compare itself with an expanding history, and the keys and values must be read from memory.
For one attention head, standard causal attention can be summarized as:
Attention(Q, K, V) = softmax(QKᵀ / √d) V
During training or prompt prefill, a sequence of length N forms an N x N score structure, so arithmetic grows quadratically with sequence length. FlashAttention improves the memory traffic and avoids materializing the entire score matrix, but it does not remove all query-key comparisons.
During cached decoding, only one new query is produced at each step. The arithmetic for that step grows linearly with the number of cached tokens, while the KV cache itself also grows linearly. This distinction matters:
| Phase | Dense attention pressure |
|---|---|
| Training and prefill | Quadratic sequence mixing |
| Cached token-by-token decode | Linear scan of an expanding KV history |
| Cache memory | Linear growth with sequence length |
Softmax attention is expressive because it can retrieve an individual earlier token with high precision. Its weakness is that the model pays for an explicit token history.
The Linear Transformers paper changes the order of operations. Softmax applies a nonlinearity after query-key interaction, which prevents simple reassociation. Linear attention applies a nonnegative feature map to queries and keys separately:
φ(Q) (φ(K)ᵀ V)
The model can update a fixed-size state instead of appending every key and value:
state = state + outer(phi(key), value)
normalizer = normalizer + phi(key)
output = phi(query) @ state
output = output / (phi(query) @ normalizer)
For head dimension d, the associative state is roughly d x d, independent of sequence length. Decode no longer scans an unbounded KV list. New information is folded into the same matrix, producing constant-state recurrent inference.
The price is compression. The state is not a bag of perfectly isolated token slots. Multiple key-value associations share a finite matrix, and a simpler kernel feature map is less expressive than exact softmax retrieval.

Additive linear attention writes every new association into the same state:
S_t = S_(t-1) + k_tᵀ v_t
When keys are well separated, a later query can recover a useful approximation of the matching value. As more associations accumulate, similar key directions overlap. Old and new facts interfere because nothing is removed.
The Fast Weight Programmers paper frames this as an over-capacity problem. A finite memory needs a way to decide what to retain, what to replace, and what to forget. Pure addition has no eviction policy.
This is the first major architectural shift in the worklog:
| Memory design | Storage behavior | Main limitation |
|---|---|---|
| Dense softmax attention | Keeps token-level K and V vectors | Cache and retrieval cost grow with context |
| Additive linear attention | Compresses history into fixed state | Associations interfere and cannot be precisely replaced |
| Delta rule | Corrects a selected association before writing | Sequential dependency complicates parallel training |
| Gated delta rule | Adds adaptive forgetting | Coarse decay can forget useful associations together |
| KDA | Applies finer channel-wise decay | Requires specialized kernels and hybrid retrieval |
DeltaNet reads the value currently stored at a key before writing. It then writes only the difference between the desired value and the retrieved old value:
old_value = key @ state
correction = beta * (new_value - old_value)
state = state + outer(key, correction)
output = query @ state
In compact form:
S_t = S_(t-1) + β_t k_tᵀ (v_t - k_t S_(t-1))
β_t is a learned write strength. Near zero, the token barely changes memory. Near one, the update strongly replaces the association along the current key direction.
This is more than a cache optimization. It changes the state from an append-only accumulator into an editable associative memory. If a key retrieves a stale value, the model can subtract that value and write a corrected one without clearing every unrelated association.

The direct delta recurrence is sequential. Token t must read S_(t-1) before it can compute its correction, which appears incompatible with the wide matrix operations GPUs prefer.
The parallel DeltaNet algorithm rewrites the recurrence with products of generalized Householder transition matrices and a compact WY representation. The sequence is split into chunks of C tokens:
The work can be understood as two terms:
approximately 2Ld² + 2LCd
L is sequence length, d is head dimension, and C is chunk length. Full attention appears when C approaches L. A very small C reduces arithmetic but may underuse tensor cores. Practical chunk sizes such as 64 or 128 balance recurrent efficiency with hardware-friendly matrix tiles.
This is a recurring systems lesson: fewer FLOPs do not automatically mean lower wall-clock time. The algorithm must expose enough regular matrix work to keep the GPU busy.
The delta rule can replace one association when a matching key arrives, but it has no general mechanism for clearing a stale context. Gated DeltaNet combines targeted delta updates with a data-dependent decay:
S_t = α_t (I - β_t k_tᵀk_t) S_(t-1) + β_t k_tᵀv_t
α_t controls how much previous memory survives:
α_t near one preserves history and behaves like the delta rule.α_t near zero rapidly clears old state.The gate and the delta correction solve complementary problems. The gate erases broadly when context changes. The delta term edits a particular key-value association.
Because decay compounds across time, an association written at position x reaches a later position multiplied by the intervening gates. Efficient chunkwise implementations therefore need cumulative products as well as the DeltaNet correction machinery.
The Kimi Linear paper extends Gated DeltaNet with Kimi Delta Attention, or KDA. Instead of one scalar decay for an entire head, KDA learns finer per-channel decay. Different features can retain or forget information at different rates.
Kimi Linear does not replace every softmax layer. It uses a hybrid:
In the paper's controlled experiments, the 48B-total / 3B-active Kimi Linear model outperformed a full-MLA baseline using the same training recipe. The authors report up to 75 percent lower KV-cache use and up to 6x decode throughput at a one-million-token context. Those are architecture-and-system results under the paper's setup, not a claim that every KDA layer is always six times faster.
The hybrid is important because finite-state memory and full retrieval fail differently. KDA is efficient but must compress. MLA is more expensive but can inspect the token context directly.
Moonshot AI's official model summary describes Kimi K3 as a 93-layer, open-weight, native multimodal model with a one-million-token context window.
| Kimi K3 architecture field | Official value |
|---|---|
| Total parameters | 2.8T |
| Activated parameters | 104B |
| Layers | 93 |
| Attention composition | 69 KDA + 24 gated MLA |
| Attention hidden width | 7,168 |
| Attention heads | 96 |
| Routed experts | 896 |
| Experts selected per token | 16 |
| Shared experts | 2 |
| Latent MoE width | 3,584 |
| Context length | 1,048,576 |
| Vision encoder | MoonViT-V2, 401M parameters |
| Quantization | MXFP4 weights, MXFP8 activations |
The 69-to-24 attention split forms a repeating rhythm: three KDA layers for every gated-MLA layer across 23 four-layer macrocycles. The first feed-forward layer is dense; later layers use the sparse latent MoE path.
This arrangement spends explicit retrieval where compression alone would be risky, while recurrent layers handle most sequence mixing with constant state.
Kimi K3 routes each token to 16 of 896 routed experts and also uses two shared experts. The full parameter set contributes to model capacity, but only a small fraction of expert weights participates in one token's forward pass.
The expert computation operates in a compressed latent width rather than the full model width. That design reduces expert-side arithmetic and communication, helping Kimi K3 activate 104B parameters from a 2.8T model.
Sparse routing creates its own systems problems:
This is why total parameters, active parameters, FLOPs, memory footprint, and latency should be reported separately.
Kimi K3 uses the SiTU-GLU activation. In simplified form, the gate applies both a bounded tanh term and a sigmoid, controlled by learned scale parameters:
gate, up = split(x)
activated_gate = beta * tanh(gate / beta) * sigmoid(gate)
output = activated_gate * up
The worklog notes a practical tension: a mathematically attractive activation can be slower than an older path until its operations are fused into an efficient kernel. Architecture and implementation cannot be evaluated independently at this scale.
The periodic MLA layers are also gated. A learned signal controls how much retrieved attention output enters the residual stream. This lets the model suppress unhelpful retrieval instead of injecting every attended feature at full strength.

Standard PreNorm transformers accumulate residual outputs with fixed weight:
h_l = h_1 + Σ f_i(h_i)
As depth grows, hidden-state magnitude can increase and the contribution of an individual layer can become diluted. Different sublayers also receive the same accumulated mixture even when they need different earlier representations.
The Attention Residuals paper replaces the fixed sum with softmax attention over earlier residual states. Each layer learns a query. Earlier states provide keys and values. The current layer then forms a content-dependent weighted combination of the depth history.
Full AttnRes would make every layer attend to every earlier layer, which adds memory and communication overhead. Block AttnRes groups several layers into one stored representation. Kimi K3 uses a block size of 12, so depth retrieval happens at a manageable granularity.
KDA and AttnRes address two different axes:
| Mechanism | Retrieval axis | Why it exists |
|---|---|---|
| KDA | Sequence time | Maintain compressed recurrent memory |
| Gated MLA | Token context | Recover precise information from the sequence |
| AttnRes | Model depth | Select useful earlier representations |
| Sparse MoE | Parameter capacity | Route tokens to specialized computation |
This is the strongest idea in the worklog. Modern architecture is not one attention trick. It is a set of selective memory systems operating across time, token context, depth, and expert capacity.
The evolution can be read as a sequence of specific failures and repairs:
| Stage | New capability | New limitation exposed |
|---|---|---|
| GPT-2 softmax attention | Precise token retrieval | Quadratic prefill and growing KV cache |
| Linear attention | Fixed-size recurrent state | Additive memory interference |
| DeltaNet | Targeted association replacement | Sequential training dependency |
| Chunkwise DeltaNet | GPU-parallel training | No broad adaptive forgetting |
| Gated DeltaNet | Context-dependent memory decay | Coarse per-head control |
| KDA | Fine channel-wise decay | Finite state still loses exact context |
| Hybrid KDA + MLA | Efficient memory plus periodic exact retrieval | Larger system and kernel complexity |
| Latent MoE | Huge sparse capacity | Routing and communication complexity |
| AttnRes | Selective retrieval across depth | Additional residual-state infrastructure |
The trajectory is not "transformers became 22,580 times larger." It is "memory became editable, forgetful, hybrid, sparse, and depth-selective."
Several caveats keep the comparison honest:
For practical serving, our AI inference latency guide explains why architecture, kernel speed, batching, and user-visible latency must be measured separately. Our small language models guide covers the opposite design point: reducing capacity so models can run near users. The Wan2.2 runtime study shows the same algorithm-system co-design pressure inside video generation.
Readers who want to move from explanation to implementation can follow this order:
d x d state and compare its decode memory to a KV cache.Useful tests include associative recall, repeated-key replacement, context switches, long-sequence numerical stability, recurrent-versus-chunkwise equivalence, expert load balance, and end-to-end decode memory.
This literature review was checked on July 31, 2026 against:
The illustrations are original editorial diagrams created for this ZharfAI edition. They explain relationships and data flow; they are not official Moonshot AI architecture schematics.

How sparse attention, persistent CUDA kernels, four-step distillation, and NVFP4 turn a 133-second pipeline into near-real-time video generation.
Read More
How affective computing interprets voice, face, and behavior—and why consent, bias, clinical validation, and human oversight determine whether emotion AI is safe.
Read More
How event-driven chips and brain-inspired architectures could reduce AI energy use—and where benchmarks, software maturity, and manufacturing still limit adoption.
Read MoreGet in touch with our team to discuss how we can help your business.