↑↓ move Enter open ⌘K find from any page 256 of 256 tabs
Loading the recording…

Splitting a logit into parts

GPT-2's final residual stream is a sum: the token and position embeddings, plus everything each attention head and MLP wrote into it. The logits are almost a linear function of that sum, so a logit can be split into one share per component. Direct logit attribution (DLA) computes those shares and asks which components push the answer up directly, in a single forward pass and with no intervention.

This page splits GPT-2 small's logit difference on the Patching tab's eight indirect-object prompts, such as “When Mary and John went to the store, John gave a drink to”, where the answer “ Mary” (the indirect object, IO) should beat “ John” (the subject, S). The terms are the token embedding, the position embedding, all 144 heads, the 12 attention output biases, the 12 MLPs and the final LayerNorm's bias.

Freezing the final LayerNorm

The only non-linear step between the stream and the logits is the final LayerNorm, which divides by the stream's own standard deviation. DLA freezes that divisor at its value on the prompt, , and the rest is linear. Writing the stream as a sum of components ,

each component's share of the logit of token is

where is the mean of 's 768 entries, and the final LayerNorm's is one more term. Here is head of layer 's output, its attention-weighted values times its slice of the output projection. The shares add up to the model's logit; on this page they do so within , and the 12 heads of a layer plus its bias give that layer's attention output within the same margin.

For the answer the page reads along the difference of the two names' unembeddings, , which gives each component's share of the logit difference. The toolbar's read along buttons switch to logit(IO) or logit(S) alone.

Every head's share

The Every head's share map colours each head by its share, red for the answer and blue against it; letters mark the IOI paper's head classes for comparison. Averaged over the eight prompts, a handful of heads in layers 9 to 11 (counting from 0) carry the result. Head 9.9 adds +2.01 to the logit difference, 9.6 adds +1.06 and 10.10 adds +0.73: the IOI paper's name movers, plus one of its backup name movers. Heads 10.7 (−1.38) and 11.10 (−0.48), its negative name movers, push the other way.

The Head card shows how: the head's attention pattern, its push on logit(IO) and on logit(S) separately, and how much of the last token's attention goes to IO, S1 and S2. Averaged over the prompts, heads 9.9 and 9.6 put about 60 % of the last token's attention on the indirect object's earlier mention and copy it into the logits; 10.7 puts 67 % on the same name and lowers it. McDougall et al. showed that 10.7 does this across GPT-2's whole training distribution, suppressing tokens that earlier layers predict and that appear in the context, which makes the model less overconfident.

Adding up

The Adding up panel sums the shares by layer. Layer 9's attention contributes +3.05 on average, more than the whole logit difference, and layers 10 and 11's attention take back about half a logit each; the MLPs add little, layer 11's most. The strip's Logit difference built up, layer by layer chart draws the running total from the embeddings to the output, where it equals the model's logit difference on each prompt, between about 1.0 and 3.6 here.

The direct picture differs from the Patching tab's in instructive ways. The S-inhibition heads in layers 7 and 8 and the induction head 5.5 each restore between 0.16 and 0.28 of the gap when patched, yet their direct shares are small (5.5's is +0.03): they attend to the subject's mentions, not to the answer, and act through later heads by changing where the name movers look. DLA sees only the last step of a circuit.

What a share does not say

A direct share is not what would happen without the component. Freezing ignores how removing a component would change the stream's scale; components that read the stream downstream would react; and later heads can partly make up for a removed one, an effect called self-repair. McGrath et al. found whole layers compensating when another is ablated, and Rushing and Nanda traced part of self-repair to the final LayerNorm's scale itself, the very quantity DLA holds fixed. DLA is exact as a decomposition of one forward pass and cheap to compute for every component at once; it is a guide to the last step of a computation, to be checked by interventions such as patching.

Where it came from

Elhage et al. (2021) set out the residual-stream view of transformers in which the logits decompose into paths through individual heads, the basis of direct attribution. Wang et al. (2022) used heads' direct effects on the logit difference to find the name movers and negative name movers of the IOI circuit, together with patching for the indirect paths. McDougall et al. (2023) then explained head 10.7 as copy suppression, and work on self-repair showed how far direct and total effects can differ. The Logit lens tab reads the same stream through the same readout, a block at a time instead of a head at a time.

Papers

  1. A Mathematical Framework for Transformer Circuits Nelson Elhage et al. · Transformer Circuits Thread 2021 The residual stream as a sum of head and MLP outputs, and the logits as a sum of paths through them: the decomposition DLA computes.
  2. Interpretability in the Wild: a Circuit for Indirect Object Identification in GPT-2 small Kevin Wang, Alexandre Variengien, Arthur Conmy, Buck Shlegeris, Jacob Steinhardt · ICLR 2022 The IOI task and circuit; heads' direct effects on the logit difference identify its name movers and negative name movers.
  3. Copy Suppression: Comprehensively Understanding an Attention Head Callum McDougall et al. · arXiv 2023 Explains GPT-2 small's head 10.7, the largest negative share on this page, as suppressing tokens that are predicted and already in the context.
  4. The Hydra Effect: Emergent Self-repair in Language Model Computations Thomas McGrath et al. · arXiv 2023 Ablating one attention layer makes another compensate, so a component's direct effect can differ from what removing it does.
  5. Explorations of Self-Repair in Language Models Cody Rushing, Neel Nanda · ICML 2024 Self-repair across models, partly through changes in the final LayerNorm's scale, the factor DLA freezes.
  6. Language Models are Unsupervised Multitask Learners Alec Radford et al. · OpenAI technical report 2019 GPT-2, whose small model this page decomposes.

See also