Causal tracing is a method for locating where specific factual associations are stored in a transformer model by running three distinct forward passes: a clean run, a corrupted run where subject embeddings are noised, and a series of restoration runs. In each restoration run, the clean hidden state from a single layer and token position is patched into the corrupted computation, and the causal effect on the output probability is measured.
Glossary
Causal Tracing

What is Causal Tracing?
A causal intervention method for locating where factual knowledge is stored within a transformer's computational graph by systematically restoring clean states during a corrupted forward pass.
By quantifying the indirect effect of each layer on restoring the correct factual completion, causal tracing produces a trace that pinpoints the specific MLP layers and attention heads mediating recall. This technique provided the foundational evidence for the knowledge neuron hypothesis and directly informs model editing methods like ROME, which surgically update weights at the identified causal site.
Key Characteristics of Causal Tracing
Causal tracing identifies where specific facts are stored in a transformer by systematically restoring clean hidden states after corrupting the input, measuring the causal effect on the model's output at each layer.
Three-Run Protocol
Causal tracing relies on three distinct forward passes to isolate factual storage:
- Clean Run: The model processes the original, uncorrupted prompt to establish a baseline output distribution
- Corrupted Run: The subject entity in the input embeddings is obfuscated (e.g., adding Gaussian noise), causing the model to fail at recalling the target fact
- Corrupted-with-Restoration Run: The corrupted run is repeated, but a specific hidden state from the clean run is patched back in at a single layer and token position
The causal effect is measured as the increase in probability of the correct answer between the corrupted and restoration runs.
Localizing the Knowledge Neuron
By iterating the restoration process across every layer and token position, causal tracing produces a causal effect map that reveals precisely where factual recall occurs:
- Early sites (layers 0-5): Restoring here has minimal effect, as the model is still processing syntax and entity recognition
- Middle sites (layers 5-15): The peak causal effect typically appears in the MLP layers of middle transformer blocks, identifying the specific neurons that encode the fact
- Late sites (layers 15+): Effect diminishes as the model transitions to generating the output token This gradient of influence demonstrates that factual knowledge is not uniformly distributed but concentrated in specific knowledge neurons within MLP modules.
Subject Token Dependency
Causal tracing reveals a critical architectural insight: the restoration effect is strongest when applied to the last subject token in the prompt. For example, in the prompt 'The Eiffel Tower is located in', restoring the hidden state at the token 'Tower' yields the highest causal effect on predicting 'Paris'.
This occurs because:
- The model pools information about the subject entity into the representation of its final token
- Attention heads in earlier layers copy subject-attribute bindings to this token position
- The MLP at the peak causal layer then reads from this enriched representation to retrieve the stored fact This finding directly informed the design of Rank-One Model Editing (ROME), which surgically modifies the MLP weights at the identified layer.
Distinction from Gradient Methods
Causal tracing differs fundamentally from gradient-based attribution techniques:
- Gradient-based methods (e.g., integrated gradients, saliency maps) measure input sensitivity—how much changing an input feature affects the output—but do not reveal internal storage mechanisms
- Causal tracing performs structural interventions on internal activations, directly testing counterfactual scenarios: 'Would the model still know this fact if this specific state were corrupted?'
- The method draws from the potential outcomes framework in causal inference, treating each hidden state as a mediator variable and measuring the indirect effect through that mediator This interventionist approach provides stronger evidence for functional localization than purely observational methods.
Limitations and Edge Cases
Causal tracing has several known constraints that researchers must account for:
- Subject-relation specificity: The method works best for subject-relation-object triples (e.g., 'Paris is the capital of France'). Performance degrades on facts requiring multi-hop reasoning or temporal context
- Self-repair effects: When a knowledge neuron is ablated, the model may dynamically recruit redundant pathways in later layers, causing causal tracing to underestimate the distributed nature of some facts
- Prompt sensitivity: The measured causal effect varies with prompt phrasing; a fact stored in multiple locations may show different peak layers depending on how the subject is introduced
- Computational cost: Tracing a single fact requires O(n) forward passes where n is the number of layers, making large-scale analysis expensive These limitations motivate complementary techniques like causal scrubbing and dictionary learning for more complete mechanistic pictures.
Relationship to Model Editing
Causal tracing provides the foundational localization step for surgical model editing techniques:
- ROME (Rank-One Model Editing) uses causal tracing to identify the specific MLP layer where a fact is stored, then treats that layer as a linear associative memory and performs a rank-one update to insert a new fact
- MEMIT (Mass-Editing Memory in a Transformer) extends this to edit thousands of facts simultaneously by spreading updates across multiple layers identified through causal tracing
- The causal trace map serves as a surgical map—editing at the wrong layer can corrupt unrelated knowledge, while editing at the peak causal layer maximizes specificity This pipeline from localization to intervention demonstrates how mechanistic interpretability directly enables practical model control.
Causal Tracing vs. Related Localization Methods
A comparison of causal intervention techniques used to locate where factual associations are stored within transformer model components.
| Feature | Causal Tracing | Activation Patching | Causal Mediation Analysis |
|---|---|---|---|
Primary Objective | Locate layers critical for fact recall by restoring clean states | Isolate specific components (heads, MLPs) in a circuit | Quantify indirect effect of a mediator on output |
Intervention Type | Corrupted input, then restore individual layer states | Replace specific activation with cached clean/corrupted value | Set mediator to counterfactual value while holding others |
Granularity | Layer-level (residual stream) | Component-level (attention head, MLP neuron) | Variable-level (any intermediate representation) |
Output Metric | Indirect Effect (IE) per layer | Logit difference or probability delta | Average Indirect Effect (AIE) or Total Effect (TE) |
Corruption Method | Gaussian noise added to subject token embeddings | Activation from a corrupted forward pass | Do-calculus intervention on mediator variable |
Typical Target | MLP layers in middle-to-late transformer blocks | Attention heads and MLP sublayers | Any causal graph node in the computation |
Requires Counterfactual Dataset | |||
Identifies Knowledge Neurons |
Frequently Asked Questions
Explore the core concepts behind causal tracing, the primary methodology for locating and validating where factual knowledge is stored within the hidden states of transformer models.
Causal tracing is a causal intervention method for locating where specific factual knowledge is stored within a transformer model's computations. It works by running the model through three distinct forward passes: a clean run with the original factual prompt, a corrupted run where the subject entity's input embeddings are obfuscated (usually by adding Gaussian noise), and a restoration run where clean hidden states from the clean run are patched back into the corrupted run one layer at a time. By measuring the degree to which each restored layer recovers the model's ability to predict the correct factual answer, causal tracing quantifies the causal effect of each layer's hidden state on the final output. This produces a trace graph showing a distinct peak in the middle-to-late MLP layers, identifying the specific site where factual recall occurs.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Core concepts for understanding how causal tracing fits into the broader toolkit for reverse-engineering transformer models.
Activation Patching
A foundational causal intervention technique that replaces a model's internal activation at a specific layer and token position with a cached activation from a different forward pass. By observing how the output changes, researchers can isolate which components are necessary for a behavior. Causal tracing is a specific, systematic form of activation patching that restores clean states from a corrupted run to measure the indirect causal effect of each layer on factual recall.
Knowledge Neuron
A specific neuron within an MLP layer identified through causal tracing that is primarily responsible for expressing a particular piece of factual knowledge. Causal tracing often reveals that factual recall is localized to a small set of neurons in the early-to-middle MLP layers of a transformer. These neurons act as key-value memory slots, firing when the model needs to retrieve a stored fact like 'The Eiffel Tower is in Paris'.
Rank-One Model Editing (ROME)
A precise model editing technique that treats an MLP layer as a linear associative memory. ROME uses causal tracing to first locate the specific layer where a fact is stored, then inserts a new fact by performing a rank-one update to the weight matrix of that layer. This surgically alters the stored knowledge without affecting unrelated capabilities, demonstrating the practical application of causal tracing for targeted model modification.
Causal Mediation Analysis
A statistical framework adapted from the social sciences for neural networks. It quantifies the contribution of a specific intermediate variable—such as a neuron or attention head—to a model's output by measuring the natural indirect effect through that mediator. Causal tracing operationalizes this by corrupting the input and then restoring clean states at a single mediator to isolate its causal role in the total effect.
Circuit Analysis
The process of identifying and validating the minimal subgraph of a neural network's computational graph that is necessary and sufficient to perform a specific behavior. Causal tracing is often the first step in circuit discovery, highlighting which layers and components are causally implicated. Subsequent analysis then maps the precise QK and OV circuits within attention heads and the downstream MLP neurons that form the complete functional pathway.
Logit Lens
A direct probing method that applies the unembedding matrix to intermediate residual stream states to interpret the model's next-token predictions before the final layer norm is applied. While causal tracing measures causal necessity through intervention, the logit lens measures representational content by decoding hidden states. Using both techniques together provides a complete picture: what information is present at each layer and whether that information is actually used.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us