Search

Search papers and lessons

Sparse Feature Circuits: Discovering and Editing Causal Graphs

Samuel Marks, Can Rager, Eric J. Michaud et al. · 2024

Marks and colleagues explain language model behaviour with circuits built from sparse autoencoder features instead of neurons, then use one to remove a classifier's reliance on gender.

On this page

  • Colour = topic mix
  • Linear algebra
  • Calculus
  • Probability
  • Architectures
  • Neural network basics
  • Discrete math
  • ReadReady to readNot yet

TL;DR

Single neurons in a language model are hard to read, because each one mixes many unrelated things. This paper splits a model's internal activations into sparse autoencoder features, each meant to track one human-readable idea. It then finds the small set of features, and the links between them, that causally carry out a behaviour, which the authors call a sparse feature circuit. They use circuits in two ways: to explain how a model handles subject-verb agreement, and to remove a classifier's dependence on gender without any extra labelled data.

Builds on: Sparse Autoencoder, Attribution Patching, Integrated Gradients, Causal Tracing · Leads to: later circuit-discovery work that uses learned features rather than neurons

Why it mattered

The paper shows that interpretability results can be used to change a model, not only to describe it. Its Shift method took a classifier that had learned gender as a shortcut for profession, removed the features a human judged irrelevant, and raised the worst-group accuracy of a Pythia-70M classifier from 24.4 to 76.0 without retraining, and to 89.0 with a retrained head. The same idea applied to Gemma-2-2B raised the worst-group accuracy from 18.2 to 92.9 after retraining.

The work also made interpretability tools easier to reuse. The authors released code, data and autoencoders, and they used open-weights models throughout. Their experiments depend on public sparse autoencoders: they trained their own for Pythia-70M and used the Gemma Scope suite (Lieberum et al., 2024) for Gemma-2-2B. The features can be browsed on Neuronpedia, and the clusters and circuits on a separate site, feature-circuits.xyz.

The problem

Mechanistic interpretability tries to explain a network by finding its internal parts and the paths between them. Two obstacles made that hard for language models.

The first is the unit of analysis. Coarse parts such as attention heads or MLP blocks are polysemantic: each one responds to several unrelated things, so a finding about a head is hard to apply. Single neurons have the same problem, and the paper notes that they are rarely interpretable. Methods that work on finer units, such as probes, usually need a hypothesis written down before the search starts. Those hypotheses are often missing when a model does something surprising.

The second is scale. Testing whether each unit matters with a separate forward pass is slow when there are tens of thousands of units. A causal test here means changing one internal value and checking whether the output changes. Setting a value to zero or to its average over the data is called ablation. The indirect effect of a unit is the change in a chosen metric, such as the log probability of the correct verb, when that unit alone is set to its value from a different input.

The paper keeps the causal test but makes it cheap enough to run on every candidate unit, and it runs it on sparse features.

How it works

The method turns a model into a graph whose nodes are features and whose edges are the links between them. Here is the pipeline for one contrastive dataset.

  1. Start with a language model MM, a sparse autoencoder for each sublayer, a dataset of input pairs that differ in one way (for example, "The parents" and "The parent"), and a metric mm that scores the output, such as the log probability of the correct verb minus the log probability of the wrong one.
  2. Write each hidden state as a sum of sparse features plus an error term that the autoencoder does not capture. Features and errors become nodes of the graph.
  3. Run the model on the clean input and the patch input, and store every node's value.
  4. Run one backward pass to get the gradient of mm with respect to every node at the clean values. Multiply each node's gradient by the change in its value from clean to patch. This gives an estimated indirect effect for every node at once.
  5. Average each node's estimate over inputs and keep the nodes whose size is above a threshold. Scores below the threshold are dropped.
  6. Estimate the effect of each edge with an analogous linear approximation, and keep the edges above a second threshold. The details are in the paper's appendix.
  7. The kept nodes and edges form the circuit. Check it by measuring its faithfulness and completeness (see The math).
  8. To apply Shift, a person reads each feature in the circuit, decides which ones are task-irrelevant, ablates them, and optionally fine-tunes the model.
flowchart LR
  A["Clean and patch input pairs"] --> B["Cache activations at each feature and error node"]
  B --> C["One backward pass for gradients at clean values"]
  C --> D["Score each node with the linear estimate"]
  D --> E["Average over inputs and keep nodes above threshold"]
  E --> F["Score edges and keep those above threshold"]
  F --> G["Sparse feature circuit"]

Here is one tiny instance of step 4. Take a single node whose value is 2.0 on the clean input and 3.0 on the patch input. Suppose the gradient of the metric at the clean value is 0.5. The estimated effect is 0.5 times (3.0 minus 2.0), which is 0.5. If the true effect of setting the node to 3.0 is close to 0.5, the linear estimate is good for this node. The paper finds that the estimate is good for most features, but underestimates the effect for nodes in the layer 0 MLP and the early residual stream, so it uses integrated gradients for those.

The math

Definition: Sparse feature circuit
A subgraph of the model's computation graph, made of SAE feature nodes and SAE error nodes, that carries most of the metric's value and is small enough for a person to read. Its quality is measured by faithfulness and completeness.

Step 1 in symbols: the sparse autoencoder decomposition

For a hidden state x∈Rd\mathbf{x} \in \mathbb{R}^{d}, the autoencoder writes

x=x^+ϵ(x)=∑i=1dSAEfi(x) vi+b+ϵ(x)\mathbf{x} = \hat{\mathbf{x}} + \boldsymbol{\epsilon}(\mathbf{x}) = \sum_{i=1}^{d_{\text{SAE}}} f_i(\mathbf{x})\,\mathbf{v}_i + \mathbf{b} + \boldsymbol{\epsilon}(\mathbf{x})

where dSAEd_{\text{SAE}} is the number of features, each vi\mathbf{v}_i is a unit-length feature direction, each fi(x)≥0f_i(\mathbf{x}) \geq 0 is how strongly feature ii is active on this input, b\mathbf{b} is a bias, and ϵ(x)\boldsymbol{\epsilon}(\mathbf{x}) is what the features do not reconstruct. The Pythia autoencoders use dSAE=64dd_{\text{SAE}} = 64d, and the Gemma Scope autoencoders use dSAE=8dd_{\text{SAE}} = 8d. The paper keeps ϵ\boldsymbol{\epsilon} as a node so that the circuit accounts for everything the model computes.

Step 4 in symbols: the indirect effect and its estimates

The exact indirect effect of a node a\mathbf{a} is

IE(m;a;xclean,xpatch)=m(xclean∣do(a=apatch))−m(xclean)\text{IE}(m; \mathbf{a}; x_{\text{clean}}, x_{\text{patch}}) = m\big(x_{\text{clean}} \mid \text{do}(\mathbf{a} = \mathbf{a}_{\text{patch}})\big) - m(x_{\text{clean}})

that is, the output on the clean input after setting the node to its patch value, minus the clean output. Computing this for every node needs one forward pass per node, which is too many. The first-order estimate, called attribution patching, is

IE^atp=∇am∣a=aclean(apatch−aclean)\widehat{\text{IE}}_{\text{atp}} = \left.\nabla_{\mathbf{a}} m\right|_{\mathbf{a} = \mathbf{a}_{\text{clean}}} \left(\mathbf{a}_{\text{patch}} - \mathbf{a}_{\text{clean}}\right)

The gradient ∇am\nabla_{\mathbf{a}} m is the vector of partial derivatives of the metric with respect to the node's values. The paper's more accurate version, from integrated gradients, averages the gradient along the straight path between the clean and patch values:

IE^ig=1N(∑α∇am∣αaclean+(1−α)apatch)(apatch−aclean),α∈{0,1N,…,N−1N}\widehat{\text{IE}}_{\text{ig}} = \frac{1}{N}\left(\sum_{\alpha} \left.\nabla_{\mathbf{a}} m\right|_{\alpha \mathbf{a}_{\text{clean}} + (1-\alpha)\mathbf{a}_{\text{patch}}}\right)\left(\mathbf{a}_{\text{patch}} - \mathbf{a}_{\text{clean}}\right), \qquad \alpha \in \left\{0, \tfrac{1}{N}, \dots, \tfrac{N-1}{N}\right\}

with N=10N = 10 equally spaced values of α\alpha. The integral form is the same one used in the integrated gradients lesson. The attribution form needs only two forward passes and one backward pass for all nodes; the integrated form costs roughly NN times as much, because it takes NN gradients.

Step 7 in symbols: faithfulness and completeness

Let m(C)m(C) be the average metric when every node outside the circuit CC is set to its average value over the data. Then

faithfulness(C)=m(C)−m(∅)m(M)−m(∅)\text{faithfulness}(C) = \frac{m(C) - m(\varnothing)}{m(M) - m(\varnothing)}

where ∅\varnothing is the empty circuit and MM is the full model. A faithfulness of 1 means the circuit reproduces the whole model's behaviour. Completeness is the faithfulness of the complement M∖CM \setminus C, and its ideal value is 0, which means that removing the circuit removes all of the behaviour.

Worked examples

Example
Example 1: one node, one input pair
  1. The node's value on the clean input is aclean=2.0a_{\text{clean}} = 2.0, and on the patch input it is apatch=3.0a_{\text{patch}} = 3.0.
  2. The gradient of the metric at the clean value is ∇am=0.5\nabla_{\mathbf{a}} m = 0.5.
  3. The change in the node's value is apatch−aclean=3.0−2.0=1.0a_{\text{patch}} - a_{\text{clean}} = 3.0 - 2.0 = 1.0.
  4. The estimate is 0.5×1.0=0.50.5 \times 1.0 = 0.5.

Interpretation: patching this node should raise the metric by about 0.5. A node whose estimate is large in size (ignoring the sign) matters more, and the sign says whether the change raises or lowers the metric.

Example
Example 2: faithfulness and completeness of a small circuit
  1. The full model scores m(M)=4.0m(M) = 4.0. The empty circuit scores m(∅)=1.0m(\varnothing) = 1.0.
  2. The circuit CC, with the rest mean-ablated, scores m(C)=3.0m(C) = 3.0.
  3. Faithfulness is 3.0−1.04.0−1.0=2.03.0≈0.67\dfrac{3.0 - 1.0}{4.0 - 1.0} = \dfrac{2.0}{3.0} \approx 0.67.
  4. The complement M∖CM \setminus C, with the circuit mean-ablated, scores m(M∖C)=1.5m(M \setminus C) = 1.5.
  5. Completeness is 1.5−1.04.0−1.0=0.53.0≈0.17\dfrac{1.5 - 1.0}{4.0 - 1.0} = \dfrac{0.5}{3.0} \approx 0.17.

Interpretation: the circuit explains about two thirds of the behaviour above the baseline. The complement still carries about a sixth, so the circuit is not complete. Ideal values would be 1 and 0.

Example
Example 3: Shift on a real classifier

The paper's Table 2 reports worst-group accuracy, which is the lowest accuracy among the four groups of profession and gender. For Pythia-70M, the original classifier scores 24.4, and after Shift it scores 76.0. For Gemma-2-2B, the original classifier scores 18.2.

  1. Compute the Pythia gain: 76.0−24.4=51.676.0 - 24.4 = 51.6 points.
  2. Compare Pythia's gender accuracy before and after Shift: it drops from 87.4 to 54.0, so the classifier relies much less on gender.
  3. Compute the Gemma gain before retraining. Shift gives Gemma a worst-group accuracy of 50.0.
  4. Compute the difference: 50.0−18.2=31.850.0 - 18.2 = 31.8 points.

Try it: after retraining, Gemma's worst-group accuracy rises to 92.9. How many points is that above the Shift-only result of 50.0? Answer: 92.9−50.0=42.992.9 - 50.0 = 42.9 points. The retrained result is close to the oracle, which reaches 93.1 worst-group accuracy when trained on ground-truth labels for the balanced set.

Results

Interpretability. Crowdworkers rated the Pythia sparse features as more interpretable than neurons, and features that take part in circuits as more interpretable than random features. The paper relies on earlier work for the Gemma features.

Faithfulness. On Pythia-70M, about 100 feature nodes explain most of the model's performance on subject-verb agreement. On Gemma-2-2B, about 500 nodes do. To explain half the performance with neurons, the paper reports about 1,500 neurons for Pythia and about 50,000 for Gemma.

Completeness. Ablating a few nodes of the feature circuit removes the task performance, even when all SAE error terms stay in place. Neuron circuits need hundreds of neurons for Pythia and thousands for Gemma.

Case study. The Pythia circuit for agreement across a relative clause has 86 nodes and faithfulness 0.21. The Gemma circuit has 223 nodes and faithfulness 0.21. Both circuits route the number of the subject through a detector for the start of a prepositional phrase or relative clause, and then promote the matching verb form.

Shift. Shift removed 55 Pythia features and 43 Gemma features judged task-irrelevant. On the balanced set, Pythia's gender accuracy fell from 87.4 to 54.0, and its profession accuracy rose from 61.9 to 88.5. After retraining, Pythia reaches 93.1 profession accuracy and 89.0 worst-group accuracy. Ablating random SAE features had essentially no effect, and Shift with neurons was dropped because almost no neurons were interpretable. A neuron baseline that picked the most spurious neurons automatically was worse than Shift.

Unsupervised discovery. On a large subset of The Pile with Pythia-70M, the authors clustered inputs by the behaviour they show and found feature circuits for thousands of clusters. Many clusters match narrow behaviours such as predicting "to" as an infinitive object, or commas in dates.

Limits. The method needs sparse autoencoders for the model, which take a large one-time compute cost to train. Much of the evaluation is qualitative, and feature labels depend on the annotator and the task. Model components the autoencoders do not capture stay uninterpretable.

Reading guide

Check yourself

QuestionIn one sentence, what is a sparse feature circuit?Show answer
A small subgraph of a model whose nodes are sparse autoencoder features (and their error terms) and whose edges are the causal links between them, chosen because it carries most of the model's behaviour and can be read by a person.
QuestionA node has clean value 1.0, patch value 4.0 and gradient −0.5-0.5 at the clean value. What is its attribution estimate?Show answer
Compute −0.5×(4.0−1.0)=−0.5×3.0=−1.5-0.5 \times (4.0 - 1.0) = -0.5 \times 3.0 = -1.5. The negative sign means that moving the node to its patch value lowers the metric.
QuestionWhy does the paper use sparse autoencoder features rather than neurons as the nodes of its circuits?Show answer
Neurons are usually polysemantic, so one neuron mixes many unrelated concepts. The sparse autoencoder splits the activation into directions that each track one concept more often, and the paper finds in its crowdworker study that those features are rated more interpretable than neurons. Neuron circuits also need far more units to explain the same behaviour.
QuestionA classifier learned to use gender as a shortcut for profession. Describe the steps of Shift and what you would check to see if it worked.Show answer
Find a feature circuit that explains the classifier's accuracy. A person reads each feature and marks the ones that are task-irrelevant. Ablate those features, optionally fine-tune the head on the same data, and check worst-group accuracy on a balanced set where gender and profession are not linked. A good result shows gender accuracy falling toward chance while profession accuracy and worst-group accuracy rise, as in the Pythia numbers in Example 3.

Sources

Read the full paper

Samuel Marks, Can Rager, Eric J. Michaud et al., 2024. arXiv:2403.19647