Course 02 / Free & open

Mechanistic Interpretability of Large Language Models

Reverse-engineering transformers, from the residual stream to automated circuit discovery. Two refreshers, eleven chapters, thirteen runnable labs, and a quiz and exam for every unit.

Interpretability writing tends to split into two piles: papers that assume you already know the vocabulary, and explainers that stop before anything is reproducible. This course takes the middle path. It starts by rebuilding a transformer block by hand from the model's own weights, then works up through the logit lens, QK and OV circuits, activation and attribution patching, automated circuit discovery, probing, steering, model editing, and sparse autoencoders.

Every chapter pairs with a Jupyter lab that reproduces that chapter's key experiments on GPT-2 small using TransformerLens. The numbers quoted in the worked examples were measured from those labs' actual runs, not estimated. Every lab runs on CPU, so no GPU is required to complete the course.

The whole course is free and open. No signup, no email gate. Read the textbook in the browser, clone the repo, run the labs.

Free · No signup 11 chapters + 2 refreshers 13 labs Quizzes & exams TransformerLens CPU only
Start here

The textbook reads in the browser with a searchable table of contents. The repository holds the labs, assessments, syllabus, and PDF edition.

FormatTextbook + labs
Units13
ModelGPT-2 small
HardwareCPU
PriceFree

Prerequisites: comfortable with Python and basic deep learning. Python 3.10+, torch, transformer_lens, einops, matplotlib.

The textbook / 13 units

Two refreshers, then four parts in dependency order.

The book opens with two refresher units that run before Chapter 1. If you can already reimplement a transformer block from its weights and are fluent with einops and hooks, skim them. Otherwise work them fully, labs included, before starting Chapter 1.

Refreshers
Prerequisites
ATransformer Anatomy, the Interpretability Way
BLinear Algebra and the Tooling Stack
Part I
The Descriptive Toolkit
01Tracing the Residual Stream
02The Logit Lens and Direct Logit Attribution
03Attention Heads as Linear Maps: QK/OV Circuits and SVD
Part II
Causal Methods and Automated Discovery
04Activation Patching and Causal Localization
05Attribution Patching and Edge Attribution Patching
06Automated Circuit Discovery and Faithfulness
Part III
Representation Testing and Intervention
07Linear Probing and Subnetwork Probing
08Steering Vectors and Activation Engineering
09Model Editing: ROME, MEMIT, and Their Limits
Part IV
Dictionary Learning and the Frontier
10Superposition and Sparse Autoencoder Training
11Transcoders, Crosscoders, Attribution Graphs, and Open Problems
The labs / 13 notebooks

One notebook per unit, in course order.

Each lab is self-contained, asserts its own checkpoints as it goes, and closes with troubleshooting, stretch goals, and cleanup. All of them run on CPU against GPT-2 small.

A
Transformer Anatomy
Rebuild block 0 by hand from the model's own weights and verify each stage against the cached activations.
B
Linear Algebra and Tooling
The matrix vocabulary, einops, and the hook machinery the rest of the course runs on.
01
Tracing the Residual Stream
What is the stream, and what writes to it?
02
Logit Lens and DLA
Reading intermediate states through the unembedding, and attributing logits to components.
03
Attention Heads: QK/OV and SVD
A head as two linear maps: what it attends to, and what it moves.
04
Activation Patching
Localizing a behavior causally instead of correlationally.
05
Attribution Patching and EAP
The gradient approximation that makes patching affordable at scale.
06
Automated Circuit Discovery
Finding a circuit without hand-picking it, and testing whether it is faithful.
07
Probing and Subnetwork Probing
Is the information there, or did the probe learn the task itself?
08
Steering Vectors
Changing behavior by adding a direction to the stream.
09
Model Editing (ROME, MEMIT)
Rewriting a fact in the weights, and where the method stops working.
10
Superposition and SAE Training
Why features outnumber dimensions, and how a sparse autoencoder pulls them apart.
11
Frontier: Transcoders, Crosscoders, Attribution Graphs
Where the field is now, and which problems are still open.
How the course works

Every unit has the same shape.

The repetition is deliberate. Once you have worked one unit you know exactly where to look in every unit after it.

The chapter

Each chapter opens with learning objectives and closes with a summary. In between: the terminology it introduces, defined at first use; a worked example carried through end to end; and a going deeper section pointing at the primary sources rather than paraphrasing them.

Numerical values in the worked examples were measured from the labs' actual runs, so the book and the notebook agree.

The lab

One Jupyter notebook per unit, in course order. Self-contained, asserting its own checkpoints as it runs, so it fails loudly rather than quietly producing a plausible wrong answer.

Each ends with troubleshooting for the failures that actually happen, stretch goals for going further, and cleanup. GPT-2 small on CPU, so a laptop is enough.

The assessments

An open-notes quiz of 8 questions and a closed-book exam of 16 questions for every unit, then a comprehensive final of 32 questions after Chapter 11.

Answer keys with explanations are kept as instructor material, so the questions stay usable if you are teaching from this or working through it with someone else.

Get started

Open the book, or clone the repository.

The textbook is the narrative path through the material. The repository holds the executable version: the 13 lab notebooks, the quizzes and exams, the syllabus, requirements.txt, and the PDF edition.

Looking for the other courses? Distilling Generative Models covers knowledge distillation from the objective function to a reproducible study, or see all free courses.