Mechanistic Training Data Attribution
This is an explainer and reimplementation of the 2026 paper by Chen et al.
Note: This post is currently incomplete!
In this post, I attempt to explain and walk through this recent paper on training data attribution.
Objective
We want to perform a kind of training data attribution. Specifically, we want to trace internal mechanisms exhibited by interpretable units of a language model (such as induction heads) back to specific training examples. We can do this through influence functions.
Background on Influence Functions
Definition. Let be an element of a dataset , and let be the weighting of . Then the response function is the optimal solution that minimizes the loss :
Definition. The influence function is a function that measures the influence of a specific training example on the perturbed model parameters .
This influence is exactly equal to the difference between the perturbed and unperturbed optima, which can be found through a first-order Taylor expansion at 0:
We can easily obtain the expression for this partial as:
where
However, this expression alone is not very useful for our purposes. Instead, we would like to find the influence of the training example on the test loss . Let's call this function for simplicity. Then the influence of on is given by:
Substituting:
Problem. is a huge matrix. Indeed, for a layer of dimensions , the Hessian is of size . This is computationally infeasible to invert.
Solution. We approximate the Hessian as the Kronecker product of two smaller matrices using a clever method called EKFAC:
where and are the eigenvector matrices obtained from eigendecomposing the two K-FAC covariance factors separately: the input-activation covariance (computed from that layer's input activations ) and the output-gradient covariance (computed from the gradients flowing into that layer's outputs). The Kronecker product of the two eigenvector matrices, , then gives the eigenbasis of the full K-FAC approximation , since diagonalizes exactly whenever diagonalizes and diagonalizes .
is a diagonal matrix of corrected eigenvalues. Rather than naively taking as in KFAC, EK-FAC re-estimates the true eigenvalues by projecting actual per-example gradients onto the fixed eigenbasis and computing their variance in that basis.
Mechanistic Data Attribution
Definition. The MDA framework is characterized by the 3-tuple :
-
The monitoring metric measures when the behaviour of a certain head shows variation, e.g. prefix-matching score for induction heads
-
The subspace projection identifies a parameter subspace corresponding to an interpretable unit of the model, i.e.
-
measures the performance of the interpretable unit in question on a test dataset (and thus we may have ).
To measure the influence of training examples on specific interpretable units, we modify the expression for as follows:
Here is the EKFAC-approximated Hessian restricted to the relevant parameter subspace .
Implementation
I train a toy 2-layer Transformer in PyTorch on a very simple synthetic induction dataset (with each example constructed as [prefix, prefix]) with the following config:
| Hyperparameter | Value |
|---|---|
| Layers | 2 |
| Heads per layer | 4 |
| d_model | 64 |
| Steps | 1000 |
Note that there are no MLPs in the model.
I use the standard prefix matching score as my , as , and the summed log-probability of the correct induction target over synthetic sequences as . Note that there are certain changes in my implementation:
- I don't use LayerNorm, so in my code you'll see that use
hook_resid_pre, i.e. hook the pre-norm residual stream. - is log probs instead of the raw logit dot unembedding formulation in A.3. This is easier to get exactly right here since I know the ground-truth match position in closed form.
- Because is maximized rather than minimized, I drop the leading negative sign in , . Positive score still means "promotes the mechanism."