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

Circuit Compositions: Exploring Modular Structures in Transformer-Based Language Models

Philipp Mondorf, Sondre Wold, Barbara Plank · Submission to ICLR 2025 · Desk rejected

TL;DR

Researchers have developed an automated method to "unmask" specific sub-networks (circuits) within a Transformer that handle modular tasks, such as reversing or swapping strings. By applying set operations to these identified circuits, they demonstrate that neural networks are not monolithic "black boxes" but contain modular, reusable components that can be composed to perform complex, multi-step operations.

The Challenge of Circuit Compositionality

In the field of mechanistic interpretability, a primary goal is to identify circuits: the minimal subgraphs of a neural network responsible for a specific behavior. While the community has successfully found circuits for isolated tasks (like identifying indirect objects in a sentence), the relationships between these circuits remain largely unexplored.

Do functionally similar tasks share underlying circuitry?

Are these circuits siloed, or do they share underlying "hardware"? If two tasks are functionally similar, do their corresponding circuits overlap? Most importantly, can we combine simple circuits to explain how a model handles complex, compositional tasks? This paper moves beyond single-task analysis to explore the modularity and compositionality of Transformer-based models, investigating whether complex behaviors can be explained as combinations of simpler, foundational circuits.

Methodology: Automated Circuit Discovery

To identify these sub-networks, the authors introduce a technique called activation pruning through continuous sparsification.

  1. Automated Discovery: Instead of manually "patching" neurons to observe behavioral changes—a computationally expensive process—they learn a continuous mask over the model's activations. This mask is optimized to satisfy two competing goals: faithfulness (the sub-network must produce the same output as the full model) and minimality (the sub-network should be as small as possible).
  2. Temperature Annealing: The optimization uses a sigmoid function with a "temperature" parameter. Over time, this parameter is annealed, gradually pushing the mask values toward either 0 or 1, ultimately yielding a discrete binary mask of "active" versus "pruned" neurons.
  3. Circuit Composition: Once individual circuits (e.g., a "reverse" circuit and a "repeat" circuit) are identified, the authors apply basic set theory. By taking the union of the binary masks, they create composite sub-networks and test their capabilities on new, more complex tasks.

Datasets and Validation

The study relies on two primary tools for evaluation:

  • PCFG SET: A benchmark consisting of ten string-edit operations (e.g., copy, reverse, shift, append) generated by a probabilistic context-free grammar. These tasks are highly compositional; for instance, the repeat task is essentially the copy operation performed twice.
  • TRACR: A "ground truth" validation tool that compiles human-readable code (RASP) directly into Transformer weights. This provides a known, ground-truth circuit structure, allowing the authors to verify that their automated pruning method accurately recovers the correct neurons.

Key Insights: Modularity in Action

The analysis of the discovered circuits reveals several compelling properties about how Transformers organize computation:

  • Functional Similarity Predicts Structural Overlap: Circuits for tasks that are functionally related (such as reverse, swap, and shift) exhibit significant node overlap. This suggests the model reuses specific computational "primitives" across different but related operations.
  • The "Copy" Foundation: The copy circuit emerged as the smallest and most efficient. Interestingly, it often acts as a structural subset of more complex circuits like echo or swap, reinforcing the idea that the model builds complex logic on top of simpler "copying" mechanisms.
Cross-task faithfulness shows how well one task's circuit performs on another task.
  • Emergent Capabilities via Union: Taking the union of two circuits can grant the model new functional capabilities. For instance, neither the repeat nor the reverse circuit can solve the echo task alone. However, their union achieves 78% accuracy on echo. This provides strong evidence for a modular architecture where the whole is indeed the sum of its parts.
  • Local Sparsity Patterns: In the encoder-decoder architecture studied, the decoder's cross-attention is almost always vital, while its self-attention and feed-forward layers are often heavily pruned for these specific string manipulation tasks.

Key Results

  • Validation Success: On TRACR-compiled models, the automated method achieved 100% recovery of the ground-truth neurons for the copy, reverse, and swap tasks, validating the continuous sparsification approach.
  • High Faithfulness, Low Footprint: The identified circuits maintained high faithfulness (often >0.94 $F_T$) while utilizing only a fraction of the full model. For example, the copy circuit required only ~13% of the model's activations, whereas the more complex prepend task required ~39%.
  • Asymmetric Generalization: The remove_first circuit demonstrated strong performance on the remove_second task, but the reverse was not true. This suggests a hierarchy of circuits, where some are more "general" and encapsulate the logic of others.

Limitations and Future Directions

While promising, the approach has limitations. The authors note that while their method finds a minimal faithful circuit, it does not guarantee completeness—it may miss neurons that are involved but not strictly necessary for the specific test cases evaluated. Additionally, the choice of "ablation value" (whether a pruned neuron is replaced with zero or a mean value) significantly impacts which neurons are identified, highlighting a broader challenge in defining "inactivity" within neural networks.

Finally, this study was performed on a relatively small encoder-decoder model (58M parameters) using a controlled, synthetic dataset (PCFG SET). Real-world natural language is significantly noisier. Scaling these techniques to discover clean, modular "LEGO-like" structures in massive Large Language Models (like GPT-4 or Llama-3) operating on natural text remains a critical frontier for mechanistic interpretability.

Summary updated

BibTeX
@misc{mondorf2024circuit,
  author = {Philipp Mondorf and Sondre Wold and Barbara Plank},
  title = {{Circuit Compositions: Exploring Modular Structures in Transformer-Based Language Models}},
  year = {2024},
  eprint = {2410.01434},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2410.01434},
}
Figure