Finding circuits inside GPT-2 Small

gpt2 at revision 607a30d783dfa663caf39e06633721c8d4cfcd7e, float32, on a beginning-of-text token, then 16 random tokens, then the same 16 again. Tokens: <|endoftext|> | continued | SS | Louis | attack | vary | CD | Does | deeper | Gr | pro | shopping | clean | leadership | Is | girl | facility | continued | SS | Louis | attack | vary | CD | Does | deeper | Gr | pro | shopping | clean | leadership | Is | girl | facility

Attention pictures and scores show where heads look: observations, not causal evidence. What the model needs is tested by interventions, on the Effects and Edges pages.

What this is

A language model reads text and guesses the next word. Inside, GPT-2 Small is a stack of 12 layers. Each layer has 12 attention heads, which look back at earlier words and move information from them, and one MLP, which works on each word where it stands. Every word carries a running notepad up the stack, the residual stream: each head and MLP reads it and adds to it, and the top of the stack turns it into a guess.

Nobody wrote down which head does what; the model learned it from text. A circuit is a small group of heads (and MLPs) that together do one job. This site shows how we look for one, and how sure we are about each part of it.

The job studied: copying a repeat

Give the model a list of random words, then the same list again. The second time through, it predicts each next word almost perfectly: it looks back at what followed this word the first time, and copies it. Two kinds of heads are known to do this together:

This is the simplest way a model learns from the text in front of it. The paper behind this project, Gao and Gao's "A Circuit for In-Context Learning", studies a richer version of it in larger models.

How we test it

Looking is not proving. Where a head looks, its attention, only names a suspect. So we:

  1. pair each prompt with a twin that differs in one controlled way (the second copy replaced by fresh words), lined up word by word;
  2. measure how strongly the model prefers the right next word over the twin's, the logit difference;
  3. switch one head off (ablation), or copy its output from one prompt into the other (patching), and see how far that measure moves;
  4. compare each effect with 20 random changes of the same size (controls), and require at least 5%;
  5. check the heads that pass on ten new prompts that played no part in choosing them (held-out seeds).

How sure we are

Every head and every arrow between heads carries one of three evidence levels, drawn the same way in every picture:

What we found so far

GPT-2 Small's copying needs or uses 12 heads that pass every check (confirmed): the previous-token head, the five induction heads, and six more that the interventions found and whose roles are not yet known. Which head feeds which is tested edge by edge on the Edges page: 4.11 feeds every induction head's key, and the induction heads feed the queries of 7.6, 9.6, 9.9 and 10.1, against random controls and again on held-out prompts. The circuit's 22 arrows are confirmed.

HeadRoleEvidenceBasis (percent effects)
4.11previous tokenconfirmedmean ablation confirmed (10%, held-out 13%); denoising under 5%
5.1inductionconfirmedmean ablation confirmed (22%, held-out 22%); denoising confirmed (12%, held-out 13%)
5.5inductionconfirmedmean ablation confirmed (6%, held-out 5%); denoising confirmed (11%, held-out 12%)
6.9inductionconfirmedmean ablation tested only (5%, held-out 4%); denoising confirmed (15%, held-out 15%)
7.2inductionconfirmeddenoising confirmed (12%, held-out 12%); mean ablation under 5%
7.10inductionconfirmeddenoising confirmed (8%, held-out 8%); mean ablation under 5%
7.6needed; reads the induction heads through its queryconfirmedmean ablation confirmed (9%, held-out 8%); denoising under 5%
8.5needed, role not yet knownconfirmedmean ablation confirmed (9%, held-out 7%); denoising under 5%
9.9restores; reads the induction heads through its queryconfirmeddenoising confirmed (7%, held-out 7%); mean ablation under 5%
9.6restores; reads the induction heads through its queryconfirmeddenoising confirmed (7%, held-out 6%); mean ablation under 5%
10.1restores; reads the induction heads through its queryconfirmeddenoising confirmed (6%, held-out 6%); mean ablation under 5%
0.1restores; feeds 6.9's queryconfirmeddenoising confirmed (5%, held-out 6%); mean ablation under 5%

The pages

the model map