When we think of Transformers, we often imagine a massive, homogeneous web of parameters where representations are slowly massaged across layers. However, mechanistic interpretability reveals a highly structured internal reality. The Transformer architecture enforces a strict division of labor between its two primary components: Multi-Head Attention (MHA) and Multilayer Perceptrons (MLPs).
Instead of acting as a uniform statistical engine, a trained Transformer operates more like a collection of specialized computer programs. Individual attention heads spontaneously carve out discrete algorithmic roles, wiring themselves together with MLP layers to form functional "circuits."
The Macro View: A Structural Division of Labor
To understand why attention heads specialize, we must first look at the macro-level separation between attention and feed-forward layers.
Think of the attention mechanism as an information router. Its structural job is to look across a sequence, identify relevant tokens, and copy or move their representations to the current token position. Conversely, think of the MLP layers as execution units or factual databases. Their job is to take the routed information, apply non-linear transformations, or retrieve abstract concepts from pretraining memory.
This structural split provides a powerful inductive bias for compositionality. As Ramesh et al. demonstrate, attention mechanisms serve as routers to select relevant instructions, while feed-forward networks act as execution units for specific operations. This division of labor allows the model to handle varied sequences of operations by dynamically reconfiguring which components are active.
In fact, Eickhoff shows that systematically ablating these components reveals a clean functional split: MLPs are primarily responsible for retrieving abstract facts from pretraining memory, whereas attention heads facilitate extractive tasks by copying information directly from the local prompt context. Similarly, Roig et al. find that self-attention layers provide compositional updates in the early stages of a network, while MLP layers act as the primary drivers of categorical refinement in later blocks.
The Micro View: Spontaneous Head Specialization
If the macro architecture separates routing from execution, how does the routing itself stay organized? In a standard multi-head attention layer, we might expect every head to contribute a small, distributed piece to the overall attention pattern. Instead, gradient descent drives individual attention heads to spontaneously specialize into highly precise, narrow roles.
Why does this happen? When a model faces complex, multi-step tasks, distributing a sub-task across all heads creates interference. It is computationally cleaner and more stable for the network to dedicate specific heads to specific sub-problems.
This specialization manifests across diverse domains:
- Algorithmic and Numerical Tasks: In structured grid or matrix tasks, Gopalani observed that after reaching a performance threshold, attention heads specialize into distinct functional roles like row/column alignment, tracking query identity, and excluding mask tokens. Similarly, when solving arithmetic, Cho et al. found that structuring positional encodings to match task logic causes individual attention heads to spontaneously specialize into digit-wise operations and carry propagation.
- Linguistic and Semantic Relations: In translation and language modeling, heads are not uniform. Zhang et al. show that attention heads can be functionally categorized into tracking positional offsets, identifying syntactic dependencies, or mapping cross-lingual alignments. Cui et al. further demonstrate that specific heads specialize in distinct commonsense relations, such as spatial locations or functional capabilities.
- Vision and Multimodal Models: This phenomenon isn't unique to text. In vision models, Gandelsman discovered that individual attention heads act as experts for specific attributes like geometric shapes, object counts, or geographic locations. Kulkarni et al. similarly found that heads specialize in either core causal features (like shape) or non-causal features (like background style).
From Specialization to Circuits
An isolated expert head is useful, but true reasoning requires coordination. Specialized attention heads and MLP layers compose themselves into circuits—modular sub-networks that execute multi-stage algorithms by passing information sequentially.
To understand why this works, consider how a Transformer solves a relational or logical task. The process is typically broken down into a pipeline where information flows from early layers to late layers, with each stage performing a discrete computational step.
For example, in the classic Indirect Object Identification task, Wang et al. reverse-engineered a precise circuit of 28 attention heads. Early components detect specific patterns and pass signals to intermediate layers, which then inhibit or promote specific information before passing it to the final output layer.
We see the same pipeline structure in mathematical reasoning. Hanna et al. show that the "greater-than" operation is executed through a multi-stage pipeline where specific attention heads isolate reference values and subsequent MLP layers apply logical transformations. Ferrara et al. confirm this structured flow via causal mediation analysis: early layers process numerical operands, middle layers manage sequence-level attention, and final layers execute the concluding computation. When expressions become more complex, Li shows that individual heads specialize in operator identification or parenthesis parsing, allowing the model to decompose mixed arithmetic expressions across its architecture.
This circuit view also explains the mystery of In-Context Learning (ICL). Instead of learning new weights on the fly, the model uses its existing specialized heads as an inference engine. Yang et al. show that during ICL, specific attention heads cluster representations by label, while induction heads rotate those clusters into alignment with the output space. Cho synthesizes this into a three-stage inference circuit—encoding, merging, and retrieving—where specialized heads project information into task-specific subspaces to prevent cross-task interference.
Exploiting Modularity for Efficiency and Control
Understanding that Transformers are collections of specialized circuits completely changes how we approach fine-tuning, pruning, and steering. If a task only relies on a small subset of parameters, we don't need to modify or maintain the entire network.
Li et al. demonstrate that because multi-head attention naturally organizes into task-specific sub-networks, we can focus training exclusively on these important heads. This reduces interference between tasks under multi-task learning settings. For model adaptation, Chen et al. introduce a strategy that identifies task-critical attention heads by measuring shifts in weight distributions; updating only the top 10% of these heads yields better performance than full fine-tuning while preventing the catastrophic forgetting of general knowledge.
Finally, this modularity enables precise control. Instead of stuffing long, expensive examples into a prompt to trigger a behavior, we can target the specialized heads directly. Park et al. show that by identifying and weighting these specialized heads differently, we can inject task configurations directly into the model's internal activations, outperforming traditional prompt-based in-context learning.