Efficient Automated Circuit Discovery in Transformers using Contextual Decomposition

Aliyah R. Hsu, Georgia Zhou, Yeshwanth Cherapanamjeri, Yaxuan Huang, Anobel Odisho, Peter R. Carroll, Bin Yu

Abstract

Researchers have introduced Contextual Decomposition for Transformers (CD-T), a mathematical framework that reverse-engineers how specific tasks are performed inside large language models. By decomposing neural activations into "relevant" and "irrelevant" parts, CD-T identifies task-specific subgraphs (circuits) in seconds rather than hours, achieving an average of 97% accuracy in recovering known manual circuits.

Introduction

As Large Language Models (LLMs) become more integrated into high-stakes fields like medicine and science, understanding why they make specific predictions is crucial. This field, known as mechanistic interpretability, treats models not as black boxes but as complex computational graphs. The goal is to find "circuits"—small subgraphs of neurons or attention heads responsible for a specific behavior (like completing a code docstring or identifying the indirect object in a sentence).

Existing automated tools for finding these circuits, such as Automated Circuit DisCovery (ACDC) or Edge Attribution Patching (EAP), face significant hurdles:

  1. Speed: Some methods take hours of compute time to find a single circuit.
  2. Accuracy: Many rely on linear approximations that miss complex, non-linear interactions.
  3. Granularity: Most tools can identify which "attention head" is important, but they struggle to pinpoint which specific word position that head is looking at without becoming prohibitively slow.

Methodology

The authors introduce CD-T, an extension of Contextual Decomposition (originally designed for LSTMs and CNNs) tailored for the Transformer architecture.

The core idea is a mathematical "accounting" system. For any given activation in the model, CD-T splits the vector into two constituents:

  • $\beta$ (Relevant): The part of the signal contributing to the task at hand.
  • $\gamma$ (Irrelevant): The "background noise" or signals unrelated to the task.
Mathematical decomposition of attention mechanisms into relevant and irrelevant terms

By propagating these $\beta$ and $\gamma$ terms through the Transformer's linear layers, layer norms, and complex self-attention mechanisms using a set of newly derived equations, the researchers can precisely calculate the "relevance" of any node.

The discovery process is recursive: it starts at the model's output and works backward, greedily pruning nodes with low relevance scores until only the essential "circuit" remains. Unlike other methods, CD-T is purely analytical—it requires no additional model training and doesn't rely on gradients, which can often be noisy or zeroed out in deep networks.

Experimental Setup

The researchers evaluated CD-T on three gold-standard benchmarks used in the mechanistic interpretability community:

  1. Indirect Object Identification (IOI): Predicting the correct name in sentences like "When Mary and John went for a walk, John gave an apple to [Mary]."
  2. Greater-Than Comparisons: Predicting that a year following a range (e.g., 1700-1720) must be greater than the start year.
  3. Docstring Completion: Predicting the correct variable name in a Python function's docstring based on the function signature.

These datasets are valuable because "manual circuits" (human-verified subgraphs) already exist for them, providing a ground truth to measure against.

Key Insights

  • Sequence-Level Precision: CD-T is the first method to efficiently discover circuits at the granularity of specific sequence positions. It can specify that a head is important only when it processes a specific word in the sentence.
  • Finding "Negative" Contributors: CD-T successfully identified "Negative Name Mover" heads in the IOI task—heads that reduce the probability of the correct answer to help the model fine-tune its confidence. Previous automated methods often struggled to catch these subtle components.
  • Faithfulness vs. Size: The paper demonstrates a "less is more" result. CD-T circuits can perfectly replicate the full model's behavior (faithfulness = 1) using significantly fewer nodes than baseline methods.
  • Beyond Random Chance: By comparing CD-T circuits to thousands of random subgraphs of the same size, the authors proved that their discovered circuits are 80% more faithful than random chance, confirming they capture the model's actual logic.

Key Results

  • Massive Speedup: CD-T reduced circuit discovery runtime from hours to seconds compared to ACDC.
  • High Recovery Accuracy: On the three benchmark tasks, CD-T recovered manual circuits with an average ROC AUC of 97%, outperforming both ACDC and EAP.
Coarse Node-level Runtime vs ROC AUC comparing CD-T, EAP, and ACDC
  • Superior Faithfulness: In head-to-head comparisons, CD-T reached a faithfulness score of 1.0 (meaning the circuit performs exactly like the full model) much faster than EAP as more heads were added to the circuit.

Limitations and Future Work

While CD-T is a major step forward, the authors note several areas for growth:

  • Scope of Components: This paper focused primarily on attention heads. Future work is needed to integrate Multi-Layer Perceptrons (MLPs) into the automated discovery process.
  • Directionality: The current relevance metric measures the magnitude of a contribution but doesn't explicitly distinguish between positive and negative directions (though it successfully finds both).
  • Heuristic Tuning: The algorithm still requires some human-in-the-loop tuning, such as deciding the percentile threshold for pruning nodes in each iteration.
  • Scaling: While tested on models like GPT-2 Small, the next challenge is applying CD-T to frontier models with hundreds of billions of parameters.

Summary updated

BibTeX
@inproceedings{hsu2025efficient,
  author = {Aliyah R. Hsu and Georgia Zhou and Yeshwanth Cherapanamjeri and Yaxuan Huang and Anobel Odisho and Peter R. Carroll and Bin Yu},
  title = {{Efficient Automated Circuit Discovery in Transformers using Contextual Decomposition}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=41HlN8XYM5},
}
Figure