Introduction
In my last post, I walked through the transformer in LLMs, the decoder-only architecture that turns your prompt into a response one token at a time. Frontier models today are still built on that architecture, but new problems arise as LLMs are scaled and are given more complex tasks. In this post I'll go over what changed since the original transformer LLM that fixed each one of the following problems.
| Problem | Solution |
|---|---|
| Every parameter (trillions) runs for every token | Mixture of Experts |
| KV cache grows with every token and fills GPU memory | Efficient attention |
| Next-token prediction alone fails at hard problems | Reasoning |
There are also smaller tweaks, like SwiGLU instead of ReLU, RMSNorm instead of layer normalization, normalizing before each step instead of after, and RoPE for positions, but they don't change the big picture, so I won't be covering them in detail.
Mixture of Experts
Let's start with the feed-forward network. In the initial transformer LLM, every token goes through the same feed-forward network in every block, which makes the model dense. This means that every parameter is used for every token. The feed-forward layers hold about 2/3 of a typical model's parameters and much of its knowledge. So if you want a model that knows more, you make these layers bigger, and every parameter you add makes every token more expensive to process.
Mixture of Experts (MoE) completely changes this. Instead of one feed-forward network per block, an MoE block has many smaller feed-forward networks called experts, and each token only uses a few. A small network called the router decides which experts get used. For each token, the router gives every expert a score, keeps the top few (the top-k), and turns their scores into weights that add up to 1. The token goes through just those experts, and their outputs are blended by the weights using this formula:
Here, x is the token's vector, Ei is expert i, and gi is the weight the router gave it. The router itself is tiny as it's a single matrix with one row per expert, so scoring every expert takes one small matrix multiplication. The rest of the block, including attention, stays exactly the same.
One MoE layer, simplified to 8 routed experts. The router keeps the top 2 for this token; the grayed-out experts never run. The shared expert (more on it below) runs for every token.
This splits a model's size into two numbers. Total parameters count every expert, and they set how much the model can know. Active parameters count only what a single token uses, and they set how much each token costs to process. In a dense model, the two are the same. In a model with MoE, they're largely different. For example:
- DeepSeek V4-Pro: 1.6 trillion total, 49 billion active (about 3%)
- Qwen3.5: 397 billion total, 17 billion active (about 4%)
So DeepSeek V4-Pro has the capacity of a 1.6-trillion-parameter model at roughly the per-token cost of a 49-billion-parameter one, which is why nearly every frontier open-weight model is now a mixture of experts.
The design has also changed since Mixtral, the open model that made MoE mainstream in 2023 with 8 large experts per block and 2 active per token. Modern MoEs use many smaller experts: Qwen3.5 has 512 per block and uses 10, and DeepSeek V4-Pro has 384 and uses 6. That gives the router far more combinations to choose from: 8 experts with 2 picks allow 28 pairs, while 512 experts with 10 picks allow about 3 × 1020 combinations, so each expert can focus on something narrower.
Most modern MoEs also add a shared expert that every token goes through, whatever the router says. Some knowledge, like basic grammar and common words, is needed by nearly every token. Without a shared expert, many routed experts would each learn their own copy of it. With one, that knowledge lives in one place, and the routed experts are free to specialize. Qwen3.5 and DeepSeek V4-Pro each use one, an idea popularized by DeepSeekMoE.
So what do these experts specialize in? It's tempting to picture a "math expert" and a "biology expert", but that's mostly not what happens. When the Mixtral team analyzed their router, they reported that they "do not observe obvious patterns in the assignment of experts based on the topic": ArXiv papers, biology abstracts, and philosophy papers were spread across the experts in nearly the same way. Instead, the patterns were about tokens and syntax. Experts specialize in whatever makes next-token prediction easier, so it makes sense that each expert's specialties don't fit categories humans would immediately pick.
Training an MoE also has to stop the router from only picking a few experts. Early on, a few experts happen to be slightly better, so they get picked more, which trains them more, which makes them better still, until most tokens flow to a handful of experts and the rest go unused. The classic fix is an extra training penalty that grows when the routing load is noticeably uneven. DeepSeek found this penalty can hurt quality, so its models mainly rely on a per-expert bias that's added to each expert's score only when choosing the top-k. After each training step, the bias goes down for overloaded experts and up for underused ones.
MoE is what lets frontier models keep growing in parameter count and knowledge while keeping the cost of each token relatively low, but model size isn't the only factor to worry about at scale. The longer a conversation gets, the more memory it takes to hold. This is where efficient attention comes in.
Efficient Attention
In my previous post, I briefly mentioned the KV cache, which allows the model to save the keys and values it has already computed for earlier tokens, so each new step only has to process the newest one. This is great for speed, but the cache holds a key and a value for every token, in every head, in every layer, and it grows with every token the model reads or writes.
For example, let's take a hypothetical model with 64 layers and 64 attention heads, where each head's keys and values are 128 numbers long and each number takes 2 bytes. For every token, the cache holds a key and a value for each layer and each head:
That's 2 MB per token. So a 128K-token conversation (fairly standard nowadays) needs 256 GB of cache. An NVIDIA H100 (a workhorse GPU for AI) has 80 GB of memory, so one conversation's cache would fill more than three of them without even storing a single model weight. This is a problem from a compute standpoint as well. Each new token compares its query against every key before it, so the work for a whole sequence grows quadratically.
There are three fixes: shrink what's cached, attend to fewer tokens, or replace most attention layers with something that doesn't need a growing cache.
Shrink the Cache
The simplest fix is grouped-query attention (GQA). Instead of every head having its own keys and values, the heads are split into groups, and each group shares one set of keys and values while keeping its own queries. If 64 query heads share 8 sets, the cache shrinks by 8×. The extreme version, multi-query attention (MQA), has every head share a single set. Sharing costs some quality, and GQA is the middle ground that stays close to full multi-head attention while being much more efficient.
DeepSeek took a different approach with multi-head latent attention (MLA), introduced in DeepSeek-V2. Instead of sharing keys and values, MLA compresses them. A learned matrix squeezes each token's vector into a small latent vector (512 dims in DeepSeek-V3), and only that latent is cached. When attention runs, other learned matrices expand it back into full keys and values for every head. Those expansion matrices can even be folded into the query and output matrices, so the full keys and values never have to be rebuilt. RoPE gets in the way of that trick, so MLA also caches a small, separate 64-number key for position.
Since the compression is learned, the latent keeps what attention actually needs. DeepSeek reported that MLA's cache is about as small as GQA with just 2.25 groups, while performing better than standard multi-head attention in their tests. Here's how the approaches compare for our hypothetical model:
| Cached per token, per layer | Per token | 128K tokens | |
|---|---|---|---|
| Multi-head (64 K/V heads) | 16,384 numbers | 2 MB | 256 GB |
| GQA (8 K/V heads) | 2,048 numbers | 256 KB | 32 GB |
| MQA (1 K/V head) | 256 numbers | 32 KB | 4 GB |
| MLA | 576 numbers | 72 KB | 9 GB |
KV cache for the hypothetical model above (64 layers, 64 query heads, 128 numbers per head, 2 bytes per number), with 1 KB = 1,024 bytes. The MLA row uses DeepSeek-V3's 512-number latent plus its 64-number position key.
Select Fewer Tokens
Now that we've established how the cache can be shrunk, there is still the costly operation of each new token attending to every token before it. Sparse attention goes after that cost. In DeepSeek V3.2, a cheap scoring step called the lightning indexer (a miniature attention with a few heads and low-precision numbers) first scores every past token for the current query. Only the top 2048 are kept, and full attention runs on just those. Most of a long context is irrelevant to any given token, so not much information is lost. Since any past token might be picked, though, the full cache still has to be kept.
Replace Most Attention Layers
The most radical approach is to stop using standard attention in most layers. Linear attention works by having each layer keep a single matrix S that summarizes everything seen so far, which each new token writes into and each query reads from:
Writing files the token's value vt into the memory under its key kt, and reading multiplies the memory by the query qt, pulling out a mix of stored values weighted by how well their keys match. The memory is the same size after a hundred tokens or a million, and so is the cost of each step, which is why the total cost grows only linearly with the context.
However, a fixed-size memory updated one token at a time has the same weakness as RNNs. This is because a fixed-size memory can't hold everything, so older details blur together. Gated DeltaNet makes the memory smarter: a gate lets it fade out memories it no longer needs, and a delta rule checks what's already stored for a key and writes only the correction, so outdated information gets overwritten instead of piling up.
Still, a fixed memory can't match full attention's precise lookups, like quoting a line from 50000 tokens back. So frontier models use hybrids: most layers are linear, and a full-attention layer every few layers keeps exact lookups possible. Qwen3.5 uses 3 Gated DeltaNet layers for every 1 full-attention layer, and Kimi Linear uses the same 3:1 pattern with its own linear variant.
The first 8 of Qwen3.5's 60 layers. The 4-layer unit repeats 15 times. Only the full-attention layers keep a KV cache that grows with the context; the linear layers each keep a fixed-size memory.
Only a quarter of the layers keep a KV cache, and with GQA in those layers, Qwen3.5's cache comes to about 30 KB per token, or 7.5 GB across its full 262,144-token native context.
The field hasn't settled, though. MiniMax, whose earlier models used a linear-attention hybrid, went back to full attention in every layer for MiniMax M2. The hybrid had matched full attention on standard benchmarks, but at a larger scale it showed clear deficits in complex multi-hop reasoning tasks. DeepSeek went the other way with V4, combining several of these ideas. V4 alternates between layers that merge every 4 tokens' keys and values into one compressed entry and pick among those entries with a lightning indexer, and layers that merge every 128 tokens into one and attend to all of them, with every head sharing a single key-value entry. These labs seem to all take different approaches to achieve the sweet spot of cost and quality. But quality only becomes a bigger problem once complex tasks get involved, which typically require reasoning.
Reasoning
The first two fixes make the model cheaper to run. The third makes it better at hard problems. The initial transformer LLM was trained on internet text to predict the next token, then fine-tuned on example conversations. That produces a model that's great at sounding right but fails at hard multi-step problems like competition math or tricky debugging.
There's also a limit built into the architecture. Every token gets exactly one pass through the stack of blocks, a fixed amount of computation. A model that answers a hard problem immediately has to get it right using only the passes it spends writing the answer. The only way for a transformer to spend more computation on a problem is to write more tokens before it answers.
The fix is reinforcement learning (RL) on problems with answers that can be checked automatically, like math problems with a known final answer, or coding problems with tests to run. The loop is simple:
- Give the model a problem and let it generate several attempts.
- Check each attempt's final answer automatically.
- Adjust the weights to make the attempts that got it right more likely, and the ones that didn't less likely.
A popular algorithm for this, DeepSeek's GRPO, rewards each attempt by how much better it did than the average of a group of attempts at the same problem, so the model learns by comparing its own attempts, without a separate model to judge them.
Notice how the model is never shown how to solve anything. It's only asked to put its reasoning between special "thinking" tags and told whether its final answer was right, but that's it. Yet when DeepSeek trained their base model this way to create DeepSeek-R1-Zero, it taught itself to reason. Its responses grew steadily longer, and it started checking its work, trying different approaches, and backtracking when something didn't add up.
That reasoning is written out as thinking tokens, the text a reasoning model generates before its final answer (chat apps often show it as a collapsible "thinking" section), and they're generated exactly like any other token.
This also opened up a new way to scale. Besides a bigger model or more training data, you can now spend more test-time compute. When OpenAI introduced its o1 reasoning model in 2024, it reported that performance consistently improves not only with more RL training but also with more time spent thinking. The same model can give a better answer just by thinking longer.
With reasoning however, the workload does get larger. A single reasoning trace can run to tens of thousands of tokens, and every one of them goes into the KV cache and gets attended to by every token after it. With reasoning becoming so popular with users of modern frontier models, efficient attention (as discussed previously) becomes absolutely necessary for serving these models to millions of users.
Putting It All Together
Frontier LLMs are still the transformer I described in my previous post, but with changes to how the computation and memory-demanding parts are handled. Mixture of Experts makes each token cheaper by running only a small slice of a huge model. Efficient attention keeps long contexts affordable by shrinking, skipping, or replacing the KV cache. And reasoning puts that capacity to work at inference, trading extra tokens for better responses to complex prompts and tasks.
The first post's diagram, updated for a typical frontier open-weight model. The feed-forward network is now a Mixture of Experts, attention is one of the efficient variants, and normalization happens before each step instead of after.
Even the architectural loop is the same: read everything so far, predict the next token, repeat. Frontier models just run it with far more knowledge per unit of compute, far more text in view, and a learned habit of thinking before they answer.