NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Finding Transformer Circuits with Edge Pruning

Adithya Bhaskar, Alexander Wettig, Dan Friedman, Danqi Chen · OpenReview

Abstract

The path to interpreting a language model often proceeds via analysis of circuits—sparse computational subgraphs that capture specific aspects of behavior. Recent automated discovery methods face limitations, relying on inefficient searches or inaccurate linear approximations. We frame circuit discovery as an optimization problem and propose Edge Pruning, a gradient-based method that prunes the connections (edges) between components. Edge Pruning identifies circuits in GPT-2 that are twice as sparse as those found by previous methods while maintaining equal faithfulness. It perfectly recovers ground-truth circuits in Tracr-compiled models and scales to CodeLlama-13B. A case study on CodeLlama reveals that instruction prompting and in-context learning share substantial underlying mechanisms, with discovered circuits achieving over 99.96% sparsity.

Introduction

Mechanistic interpretability seeks to "reverse engineer" neural networks, moving beyond treating Transformers as black boxes. Central to this effort is the identification of circuits: subgraphs of attention heads and MLP layers that perform specific logical tasks, such as Indirect Object Identification (IOI). However, identifying these circuits has historically presented a trade-off between the exhaustive but computationally expensive greedy searches (e.g., ACDC) and fast but often inaccurate linear approximations (e.g., EAP).

In "Finding Transformer Circuits with Edge Pruning" (NeurIPS 2024), researchers from Princeton University introduce a scalable, gradient-based optimization approach. By pruning the "wires" (edges) between components rather than the components themselves, Edge Pruning achieves high faithfulness and extreme sparsity at a scale previously considered unreachable.

Methodology: Circuit Discovery as Optimization

Edge Pruning conceptualizes circuit discovery as a differentiable optimization problem. The core innovation lies in its granularity and the way it handles information flow within the Transformer architecture.

Pruning Edges, Not Nodes

Traditional pruning methods often target entire neurons or attention heads. In contrast, Edge Pruning places learnable masks on the connections between components. This allows the method to identify specific paths of information flow, providing a much finer resolution of the model's internal logic.

Disentangled Residual Stream

Standard Transformers aggregate all component outputs into a single residual stream. To enable edge-specific pruning, the authors utilize a "disentangled" residual stream. In this setup, the outputs of every component are kept distinct, allowing the model to learn which specific prior outputs a subsequent component should "read."

Differentiable Masking and Interchange Ablation

The method employs the Hard Concrete distribution to make the discrete choice of keeping or pruning an edge differentiable, allowing for optimization via standard backpropagation. To evaluate the necessity of an edge, the authors use interchange ablation: when an edge is pruned, its activation is replaced with one derived from a "corrupted" version of the input. This ensures the model remains "in-distribution" and provides a rigorous test of whether a specific information path is essential for the task.

Experimental Results

The authors evaluated Edge Pruning across three distinct settings to test its accuracy, scalability, and ability to recover known structures.

GPT-2 Small and Tracr Benchmarks

On standard tasks like Indirect Object Identification (IOI) and Greater Than (GT) resolution in GPT-2 Small, Edge Pruning found circuits that were significantly more sparse—often using less than half the edges—than those identified by ACDC, while maintaining comparable faithfulness.

Crucially, when applied to models compiled with Tracr (a tool that translates human-readable code into Transformer weights), Edge Pruning perfectly recovered the ground-truth circuits. This provides strong empirical evidence that the method identifies the actual functional subgraphs rather than just statistical correlations.

Scaling to CodeLlama-13B

The efficiency of Edge Pruning allows it to scale to models like CodeLlama-13B, which is over 100 times larger than the models typically used in prior circuit-finding research. In a case study involving Boolean Expressions from the Big-Bench Hard suite, the method identified circuits with 99.96% sparsity (approximately 1,000 edges out of 3.8 million) that matched the full model's performance within 2-3%.

Insights: Instruction Prompting vs. In-Context Learning

A key contribution of the paper is the comparison of mechanisms behind different prompting styles. By analyzing the circuits found in CodeLlama-13B, the researchers discovered that the subgraphs for "instruction prompting" and "few-shot learning" overlap by more than 60%.

Furthermore, cross-evaluation showed that the "few-shot" circuit performed remarkably well when given "instruction" prompts. This suggests that Large Language Models (LLMs) utilize shared underlying logical machinery regardless of how the task is framed to the model.

Limitations and Future Directions

While Edge Pruning represents a significant advancement, it faces practical challenges:

  • Memory Requirements: The disentangled residual stream increases the GPU memory footprint during the discovery phase, as it requires storing a larger number of activations.
  • Computational Speed: While significantly faster than greedy search methods, Edge Pruning is still slower than simple first-order attribution methods like EAP.
  • The Interpretability Gap: Identifying a sparse, faithful circuit is only the first step. Human researchers must still manually analyze the discovered edges to understand the underlying logic—a task that remains labor-intensive even with highly sparse subgraphs.

Conclusion

Edge Pruning provides a robust framework for automated circuit discovery that balances efficiency with faithfulness. By framing the problem as gradient-based optimization, it enables the study of mechanistic interpretability in large-scale models, offering a clearer view of the "wires" that drive complex AI behavior.

Summary updated

BibTeX
@inproceedings{bhaskar2024finding,
  author = {Adithya Bhaskar and Alexander Wettig and Dan Friedman and Danqi Chen},
  title = {{Finding Transformer Circuits with Edge Pruning}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=8oSY3rA9jY},
}
Figure