Source-linked AI summary

Interpretability in the Wild: a Circuit for Indirect Object Identification in GPT-2 small

Kevin Wang, Alexandre Variengien, Arthur Conmy, Buck Shlegeris, Jacob Steinhardt

arXiv:2211.00593v1cs.LGcs.AIcs.CL

TL;DR

Mechanistic interpretability seeks to explain model behavior through internal components, but prior work often addresses either simple behaviors in small models or complex behaviors only broadly. This paper reverse-engineers GPT-2 small’s indirect object identification using causal interventions and related analyses, identifying a 26-head, 7-class circuit whose validation supports the explanation while exposing remaining gaps.

  • Problem

    Mechanistic interpretability lacks detailed explanations spanning a natural behavior in a language model while remaining grounded in internal components.

    Source: §1 · pp. 1–2
  • Method

    The authors trace components from logits using path patching, supplement this with complementary analyses, and validate the resulting circuit using faithfulness, completeness, and minimality.

    Source: §1 · pp. 1–2
  • Results

    The paper identifies a circuit of 26 attention heads grouped into 7 categories that completes the bulk of indirect object identification in GPT-2 small.

    Source: §1 · p. 2
  • Takeaways & Limitations

    The investigation provides a detailed example of reverse-engineering transformer behavior and identifies redundant, unexpected, and negatively contributing internal structures.

    Source: §1 · p. 2, §5 · p. 12

    The explanation’s validation is incomplete: the circuit fails the most challenging tests, while zero ablation is noisy and layer-normalization scaling complicates some measurements.

    Source: §2.1 · p. 3, §3.2 · p. 6

Abstract

from arXiv · show

Research in mechanistic interpretability seeks to explain behaviors of machine learning models in terms of their internal components. However, most previous work either focuses on simple behaviors in small models, or describes complicated behaviors in larger models with broad strokes. In this work, we bridge this gap by presenting an explanation for how GPT-2 small performs a natural language task called indirect object identification (IOI). Our explanation encompasses 26 attention heads grouped into 7 main classes, which we discovered using a combination of interpretability approaches relying on causal interventions. To our knowledge, this investigation is the largest end-to-end attempt at reverse-engineering a natural behavior "in the wild" in a language model. We evaluate the reliability of our explanation using three quantitative criteria--faithfulness, completeness and minimality. Though these criteria support our explanation, they also point to remaining gaps in our understanding. Our work provides evidence that a mechanistic understanding of large ML models is feasible, opening opportunities to scale our understanding to both larger models and more complex tasks.

1 INTRODUCTION

This paper mechanistically explains how GPT-2 small performs indirect object identification by isolating and validating a human-understandable circuit. The investigation combines causal interventions with complementary interpretability analyses and examines both the circuit’s structure and remaining validation gaps.

  • The work aims to make GPT-2 small’s computation human-understandable because transformer models remain difficult to understand despite deployment in high-impact settings.Mechanistic interpretability is presented as a way to discover, understand, and verify algorithms implemented by model weights.Source: §1 · p. 1
  • The circuit is discovered by tracing important components back from the logits with path patching, supplemented by embedding projections, attention-pattern analysis, and activation patching.Source: §1 · p. 1
  • GPT-2 small performs indirect object identification by predicting the name that is not the subject of the last clause.For example, in “When Mary and John went to the store, John gave a drink to”, the expected completion is “Mary”.Source: §1 · p. 2
  • The authors identify a circuit of 26 attention heads, grouped into 7 categories, that completes the bulk of IOI.The heads route information between name tokens, the end position, and the output.Source: §1 · p. 2
  • The analysis reveals redundant heads, unexpected uses of induction-head structures, and heads that reliably write opposite to the correct answer.Backup Name-Mover Heads copy names correctly only when regular Name-Mover Heads are ablated.Source: §1 · p. 2
  • The study validates the circuit with faithfulness, completeness, and minimality criteria, but it fails the most challenging tests.The circuit improves significantly over a naïve faithful circuit while leaving gaps in the explanation.Source: §1 · p. 2

2 BACKGROUND

The paper defines IOI, describes the relevant GPT-2 small architecture and circuit abstraction, and specifies knockout methods for isolating circuit behavior. It also replaces noisy zero ablation with mean ablation using a modified reference distribution.

Task description

  • IOI requires predicting the indirect object at the final token of templates containing an initial clause and a main clause.The dataset uses 15 templates with random single-token names, places, and items.Source: §2 · p. 3

Transformer architecture

  • GPT-2 small is a decoder-only transformer with 12 layers and 12 attention heads per layer.Source: §2 · p. 3

Circuits and knockouts

  • A circuit is a subgraph of the model’s computational graph responsible for a behavior, with nodes as model components and edges as their interactions.Source: §2.1 · p. 3
  • The circuit function is measured by knocking out all model nodes outside the circuit and taking the resulting logits.Source: §2.1 · p. 3
  • Zero ablation is noisy because replacing removed nodes with 0 is arbitrary and later nodes may rely on average activation as an implicit bias.Source: §2.1 · p. 3
  • Mean ablation replaces nodes with their average activation over a reference distribution, removing varying task information while preserving constant information.All knockouts use pABC, which contains three unrelated names while preserving the grammatical structure of IOI templates.Source: §2.1 · pp. 3–4
  • Template-matched averaging preserves grammatical information when a node is knocked out because token positions have different grammatical roles across templates.Source: §2.1 · p. 4

3 DISCOVERING THE CIRCUIT

The authors trace GPT-2 small’s IOI circuit backward from the logits, identifying head classes that detect duplicated subjects, inhibit subject attention, and move the indirect object to the output. Causal interventions and activation analyses support these roles while revealing redundancy and remaining validation gaps.

Related and redundant components

  • Backup Name Mover Heads provide redundant output behavior, activating when regular Name Mover Heads are ablated, while Negative Name Mover Heads write opposite name directions.These redundancies complicate efforts to identify complete mechanisms because ablations can reveal different model structure.Source: §3 · p. 5, §3.1 · p. 6

Scope and caveats

  • The investigation focuses on attention heads and does not intervene on MLPs, layer norms, or embedding matrices, leaving the role of MLPs for future work.Individually knocking out most MLPs preserved task performance, but knocking out all MLPs after the first layer prevented the task.Source: §3 · p. 5

Which heads directly affect the output?

  • Path patching identifies heads that directly influence the IOI logit difference, including positive Name Mover Heads and negatively influencing Negative Name Mover Heads.Heads 9.6, 9.9, and 10.0 contribute positively, whereas 10.7 and 11.10 contribute negatively.Source: §3.1 · pp. 5–6
  • Name Mover Heads attend strongly to the indirect-object token and copy attended names into the output representation.Their average attention to the IO token is 0.59, and attention probability correlates with output in the corresponding name direction at ρ > 0.81 over N = 500.Source: §3.1 · pp. 5–6

Which heads affect the Name Mover Heads’ attention?

  • S-Inhibition Heads modify Name Mover queries so those heads attend less to subject occurrences and preferentially select the indirect object.The four S-Inhibition Heads attend from END to S2 and write token and position signals that suppress subject attention.Source: §3.2 · pp. 7–8

Scope and caveats

  • Additional parameter-level checks were still needed to validate whether Duplicate Token and Induction Heads implement their proposed collision-detection, copying, and key-composition mechanisms.The omitted checks concern interactions between QK matrices and token embeddings, OV matrices and positional embeddings, and the parameter-level analysis of Induction Heads.Source: §3.3 · p. 8

4 EXPERIMENTAL VALIDATION

The authors evaluate the IOI circuit with faithfulness, completeness, and minimality criteria, compare it with a naive circuit, and use circuit knowledge to construct adversarial examples. The circuit performs well on faithfulness and minimality, but completeness testing reveals gaps and the adversarial analysis has important limitations.

Faithfulness

  • The circuit’s faithfulness gap is 0.46, only 13% of the full model’s logit difference, so it achieves 87% of model performance.Source: §4 · p. 9

Completeness

  • Completeness requires circuit and model performance to remain similar under knockouts of arbitrary subsets of components.Source: §4.1 · pp. 9–10
  • 3.09, or 87% of the original logit difference, was the largest incompleteness score found by greedy subset optimization.Random sampling and class-based knockouts suggested completeness, but greedy optimization found high-scoring, usually uninterpretable subsets.Source: §4.1 · p. 10

Minimality

  • Every circuit head had a nontrivial impact of at least 1% of the original logit difference, although some heads contributed only modestly.Source: §4.2 · pp. 10–11

Baseline comparison

  • The naive circuit matched the full circuit’s faithfulness score of 0.1 but was more easily shown to be incomplete.Source: §4 · p. 9, §4.3 · p. 11

Adversarial examples

  • Duplicating both subject and indirect-object tokens reduced the logit difference and made the model predict the subject 23% of the time.The examples were inspired by the circuit’s duplicate-detection account, but they were simple enough to find without that understanding.Source: §4.4 · p. 11

5 DISCUSSION

The discussion presents the validated circuit as a detailed account of GPT-2 small’s IOI behavior while highlighting pointer communication, compensatory and negatively contributing heads, unresolved mechanisms, and the challenge of scaling beyond GPT-2 small.

  • The study isolates, understands, and validates an attention-head circuit for indirect-object identification in GPT-2 small.Source: §5 · p. 12
  • Some attention heads communicate by sharing information locations through pointers rather than copying the information itself.Source: §5 · p. 12
  • Other heads compensate for lost functions, while some contribute negatively to next-token prediction; early results suggest negative contributions beyond IOI.Source: §5 · p. 12
  • The analysis leaves several components unresolved, and GPT-2 small is orders of magnitude smaller than state-of-the-art transformer language models.Source: §5 · p. 12
  • GPT-2 medium also has a sparse set of heads directly influencing logits, but not all attend to IO and S as in GPT-2 small.Source: §5 · p. 12
  • The authors view narrowly defined, highly detailed analyses as useful starting points for understanding broader model behavior.Source: §5 · p. 12

A DISENTANGLING TOKEN AND POSITIONAL SIGNAL IN THE OUTPUT OF S-INHIBITION HEADS

The authors disentangle token and positional signals emitted by S-Inhibition Heads using counterfactual datasets and activation patching. The signals independently affect the IOI logit difference, with positional information contributing more strongly and appearing to depend on relative rather than absolute position.

C DIRECT EFFECT ON S-INHIBITION HEADS’ KEYS

Path-patching experiments identified heads that influence S-Inhibition Heads through their keys, including three newly recognized positive contributors. Attention patterns characterize these contributors as fuzzy Duplicate Token and fuzzy Induction Heads.

D IDENTIFICATION OF PREVIOUS TOKEN HEADS

The section uses path patching to trace heads affecting Induction Heads at S1+1, the repeated-pattern position associated with the [B] token. It also reports that query-side interventions at S2 found no significant effects.

F BACKUP NAME MOVER HEADS

Knocking out the three main Name Mover Heads reveals backup heads that compensate for their lost function. These heads exhibit diverse behaviors, but their exact selection has little effect on the circuit’s behavior.

  • After the three main Name Mover Heads are knocked out, the logit difference is only 5% lower because other heads compensate for the lost function.Negative Name Mover Heads become less negative, and head 10.7 even has a positive effect after knockout.Source: F BACKUP NAME MOVER HEADS · p. 19
  • Eight positively influencing heads not assigned to other groups were selected as Backup Name Mover Heads using a 2% logit-difference effect threshold.Source: F BACKUP NAME MOVER HEADS · p. 19
  • The backup heads divide into four behavioral categories based on attention patterns and output directions.Source: F BACKUP NAME MOVER HEADS · p. 19
  • Four heads behave similarly to Name Mover Heads, while two attend equally to S1 and IO and write both tokens.Source: F BACKUP NAME MOVER HEADS · p. 19
  • Head 11.2 attends more to S1 and writes preferentially toward WU[S], whereas head 9.7 attends to S2 and writes negatively.Source: F BACKUP NAME MOVER HEADS · p. 19
  • The backup heads were not thoroughly investigated, but they have low individual importance and their exact selection does not significantly change circuit behavior.Source: F BACKUP NAME MOVER HEADS · p. 19

G GPT-2 SMALL FULL ARCHITECTURE

GPT-2 small combines token embeddings, positional information, attention heads, layer normalization, and one-hidden-layer MLPs in a unidirectional transformer architecture. The forward pass combines these elements across the model’s layers.

H VALIDATION OF THE INDUCTION MECHANISM ON SEQUENCES OF RANDOM TOKENS

Validation on repeated random-token sequences supports the roles of Previous Token and Induction Heads, including prefix matching and copying. Other circuit heads also contribute to next-token prediction, suggesting the mechanism extends beyond IOI.

I VALIDATION OF DUPLICATE TOKEN HEADS

Repeated random-token tests provide evidence that heads 3.0 and 0.1 detect duplicate tokens outside the IOI circuit. Fuzzy Duplicate Head 0.10 requires qualitative analysis because it does not appear in the repeated-token test.

J ROLE OF MLPS IN THE TASK

MLP0 strongly affects IOI performance, while individually ablating later MLPs has little effect; ablating them collectively nevertheless disrupts the task. The circuit analysis therefore leaves MLP contributions incompletely characterized.

Loading 2211.00593v1…