The mechanisms
Twelve chapters, one for each mechanism. Each explains its mechanism in plain words, with a figure, a short piece of code and a question to try.
An atlas of 44 documented architectures. Follow a token through a model, see what it remembers, and work out why two designs can give very different answers to the same engineering problem.
Suppose a model reads “The cat sat on the”. To suggest what comes next, it first breaks the text into tokens, which may be whole words, word fragments or punctuation. An embedding turns each token into a list of numbers. Each layer updates those numbers. The output head then gives each possible next token a score.
As you read, keep two questions in mind. Which earlier tokens can influence this one? And what must the model keep in memory for the next prediction? Start with self-attention for the baseline. Then compare a sliding window, a handful of selected keys and a fixed-size state.
Each chapter has a figure and a question to try before opening the reasoning. The model sheets give the architecture, reported results and sources. The animations use illustrative tokens and routing choices. They show how information can move through a model.
Inspired by Sebastian Raschka's LLM Architecture Gallery and his articles, which are cited as secondary sources. All figures here are drawn from the data by this site; none of his images are reused.
The 2017 Transformer has four limits that matter at today’s scale. Each of the twelve mechanisms in this atlas works on one or two of them.
Every token is compared with every earlier one, so doubling the prompt quadruples the attention work. Some designs limit how far a query looks; others fold the past into a state of fixed size.
Chapters: self-attention, the sliding window, state-space models and linear hybrids and sparse attention.
With full attention, each new token reads the keys and values for earlier positions. As the prompt grows, moving that data from memory can limit decoding speed. Sharing or compressing it across heads, positions and layers makes it smaller.
Chapters: shared keys and values, latent attention and compressed memory and the encoder-decoder.
In a dense layer every weight is used on every token, so a larger model is a slower one. Routing, reusing layers and drafting several tokens at once separate what a model stores from what it computes.
Chapters: mixture of experts, multi-token prediction and looped depth.
Attention by itself ignores word order, and a standard stack adds every block’s update to one shared vector with a fixed weight. Position signals supply the order; newer residual designs change how that vector is carried through depth.
Chapters: position signals and the residual stream.
| Mechanism | What changes | Work per decoded token | Memory as the context grows | Trade-off |
|---|---|---|---|---|
| 1. Self-attention (MHA) | Every head queries all past positions | O(n) | O(n · H) | Can read any earlier position. Prefill work grows quadratically. |
| 2. RoPE, partial RoPE, NoPE | Encodes token order by rotation, or leaves it to other layers | O(1) extra | Unchanged | Relative angles generalise well; unseen distances still need rescaling |
| 3. GQA and MQA | Several query heads share one K/V head | O(n), less to read | O(n · G), with G below H | Smaller cache at close to MHA quality; a single KV head (MQA) costs some quality |
| 4. Latent attention (MLA) | Caches one shared low-rank latent and a small rotary key | O(n) in latent space | O(n · d_c) | Smaller cache than GQA; QK-Norm cannot be applied |
| 5. Sliding window | Reads only the most recent w tokens | O(w) | Capped at O(w) | One layer reads w positions. Earlier information can travel farther across successive layers. |
| 6. Mixture of experts | A router runs k of E feed-forward experts | k experts | Expert weights are fixed as context grows | Each token uses k experts. All E sets of weights must be available, and routing can be uneven. |
| 7. State-space and linear hybrids | Folds history into a state of fixed size | O(1) on linear layers | O(1) on linear layers | Linear-time prefill; a fixed state cannot copy arbitrary distant text |
| 8. Multi-token prediction | Extra modules draft the tokens after the next one | Drafting work plus one trunk pass per candidate block | Extra module weights are fixed as context grows | Faster when drafts match; wasted work when they do not |
| 9. Sparse attention | An indexer selects the top k past tokens for each query | O(n) index, O(k) attention | Still O(n) stored | Less attention work and fewer reads, not less storage |
| 10. mHC and attention residuals | Several parallel streams, or attention across depth | Small mixing overhead | Wider stream to carry | More flexible flow across depth; unconstrained mixing destabilises training |
| 11. Looped depth | Runs the same L layers P times | P × L layer evaluations | One set of weights, up to P caches | Saves weight memory, not computation |
| 12. Compressed memory, encoder-decoder | Older tokens compressed in blocks, or encoded once for the decoder | O(n / r) plus a local window | Smaller by block and layer sharing | Large prefill and cache savings; compressed blocks lose per-token detail |
Twelve chapters, one for each mechanism. Each explains its mechanism in plain words, with a figure, a short piece of code and a question to try.
The latest arrivals. Every card is drawn from the model's own numbers; open one for the full figure, the facts and the sources.
Stack height shows the number of drawn blocks on a shared scale. Each coloured row is one block. The table explains grouped layers and highlights differences.
papers, technical reports and official documents. Model sheets link to the reports and configuration files used for their architecture and measurements.