A Mathematical Framework for Transformer Circuits (2021)
TL;DR Highlight
Rewriting transformers mathematically exposed how small models work and how induction heads form.
Who Should Read
An LLM API or agent developer who wants an intuition for what happens inside transformers.
Core Mechanics
- They only dissected tiny models
- They studied toy transformers with at most two layers and attention only, no MLPs.
- GPT-3, by contrast, has 96 layers alternating attention and MLP blocks.
- Zero-layer models are bigram models
- They predict the next token from the previous token alone.
- The bigram table can be read straight from the weights without running the model.
- One-layer models ensemble bigrams and skip-trigrams
- A skip-trigram is a pattern of the form "A… B C".
- These tables can also be read from the weights without running the model.
- Very simple in-context learning (learning from examples in the prompt) arises here.
- Induction heads appear at two layers
- They are built by composing attention heads and implement a more general in-context learning algorithm.
- The paper says these heads only developed in models with at least two attention layers.
- The residual stream is a communication bus
- Each layer reads from and writes to it, and it does no processing itself.
- Layers talk through different subspaces of it.
- Attention heads are independent and additive
- The original concatenate-and-multiply formulation is mathematically equal to summing per-head outputs.
- A head's core job is moving information between tokens.
- Each head splits into a QK circuit (where to look) and an OV circuit (what to move).
Community Reactions
- Q/K/V is not the only way to see attention
- A commenter said the equivalent larger matrices are more useful for interpretability than Q, K and V.
- They argued that key/query analogies are not the only good way to understand attention.
- Redrawing diagrams around the residual stream
- One commenter came to see it as a main bus from embedding to output, not just layer bypasses.
- They now mentally redraw every architecture diagram with the residual stream at the center.
- Length is a barrier
- One commenter tried many times but found it too long and asked if it is worth it.
- Another predicted it will be seen as classic foundational work.
How to Apply
- Redraw an architecture diagram around the residual stream
- Today, pick a transformer diagram and draw a straight line from embedding to unembedding.
- Redraw attention and MLP as side blocks that add into that line.
- Test an induction pattern in a prompt
- Paste the prompt below and check whether the model continues the earlier pattern.
- The paper explains this behavior as in-context learning in small models.
- Split head roles in your model docs
- In internal explanations, describe attention as where to look (QK) and what to move (OV).
Try It
# Paste into Claude or ChatGPT as is (simplified version of the paper's idea: following an induction pattern)
Follow the rule below without explanation.
moon -> 7
cable -> 3
river -> 9
cable -> 3
moon -> 7
river -> ?
Question: {{swap in a new pattern to test}}
Next to try: replace the examples with {{meaningless token pairs}} and see if the model still continues the pattern.Terminology
Related Papers
Gemini 4 Neon is the new #1 on the Models Engineering Index
Gemini 4 Neon ranks first on the Models Engineering Index with 68.0, combining multiple benchmarks.
LLMs can read and write executables byte by byte from a hex dump
Given only a hex dump and no tools, an LLM analyzed, patched and wrote working executables.
Claude was trained on protein sequences at scale
Next-amino-acid tests on obscure proteins show only the latest Claude models predict them
Remembered as Brief: Stored Preferences SilentlyRemove Decision-Critical Information
A stored 'keep it short' preference silently drops warnings; listing must-know points first restores content.
All AI-generated code should be Open Source
A blog argues AI-generated code should be open source; most HN commenters disagreed.
What thousands of conversations look like inside a language model
Mapping Qwen3-1.7B states showed Chinese sitting apart from English, while German and Croatian overlapped it.
AI, activity, and outcomes in software engineering
AI sped up writing code, but shipping speed did not rise as much, says a talk
LLMs Play Zachtronics' TIS-100
16 LLMs played TIS-100 and set 133 new Pareto frontier points across 18 puzzles