Influence Functions & Data Attribution
Tracing a prediction back to the training examples that caused it.
A model misclassifies a test image. Which training examples are responsible? The honest answer, retraining without each example in turn, costs one training run per example. Influence functions replace those retrainings with a single inverse-Hessian–vector product, built from the last two lessons' machinery: implicit differentiation and Hessian–vector products. For convex models they work beautifully. For deep networks, what they compute is subtler, and the field has learned to say exactly what.
What you’ll learn
- Derive the influence of upweighting a training example on the learned parameters and on a test loss from first-order optimality, and state the assumptions behind it.
- Compute inverse-Hessian–vector products at scale with conjugate gradients, LiSSA's Neumann recursion and Kronecker-factored (EK-FAC) curvature, and explain why one solve per test point suffices.
- Explain why influence functions are fragile in deep networks, and what they approximate instead of leave-one-out retraining (the proximal Bregman response function).
- Compare TracIn, datamodels, TRAK and data Shapley, evaluate attributions with the linear datamodeling score, and name the main uses and open problems.
Leave-one-out without retraining
In this lesson denotes a training example, not a pre-activation. Training finds with . To ask what one example contributed, upweight it by and follow the solution: . Setting removes entirely. Robust statistics has studied this derivative since Hampel's influence curve (1974) and Cook's regression diagnostics (Cook, 1977; Cook & Weisberg, 1982); Koh and Liang (2017) brought it to modern machine learning.
The perturbed optimum satisfies the first-order condition . At , is invertible and :
The test loss depends on only through the parameters, so the chain rule finishes the job. Removing () changes the test loss by about :
So a training example helped a test prediction (removing it raises the test loss) when its gradient is aligned with the test gradient in the inner product weighted by . Raw gradient alignment is not enough: discounts directions in which the loss is sharply curved, where the parameters are already pinned down by many examples, and amplifies flat directions, where one example can move them.
How good is the linearization? For least squares it can be compared with the exact answer. With , residual and leverage , the Sherman–Morrison formula gives the exact leave-one-out change, while the influence function drops one factor:
In a least-squares fit, a training point has leverage . The true leave-one-out parameter change is how many times the influence-function estimate?
Show the answer
1.25
: the estimate is 20% short, in the right direction. At the factor is , and as (a point that alone determines part of the fit) the linearization fails completely.
Inverse-Hessian–vector products at scale
For a network with parameters, is : never formed, let alone inverted. The trick is to group the computation around the test point: solve once for , then every training example's influence is a dot product, , costing one gradient per example. The solve itself needs only Hessian–vector products, each about the cost of a couple of gradients (Pearlmutter, 1994):
| Method | Idea | Caveats |
|---|---|---|
| Conjugate gradients | Minimize using exact HVPs on the full training set | needs (add damping ); many full passes over the data |
| LiSSA (Agarwal, Bullins & Hazan, 2017) | Neumann recursion , with each HVP on a random mini-batch; scaled so that | stochastic, slow when is ill-conditioned; one of the two solvers Koh and Liang used |
| Arnoldi (Schioppa et al., 2022) | Find the top eigenvectors of once and invert within that subspace | ignores the many small eigenvalues |
| K-FAC / EK-FAC | Replace by a Kronecker-factored Gauss–Newton matrix, invertible layer by layer in closed form | a structured approximation; used to reach 52-billion-parameter language models (Grosse et al., 2023) |
Replace by the Gauss–Newton matrix , where is the Jacobian of the network's outputs and the Hessian of the loss in the outputs. even where has negative eigenvalues; with damping it is positive definite. For one linear layer , the per-example gradient is an outer product, with , so in vectorized form:
K-FAC (Martens & Grosse, 2015) approximates the expectation of the product by the product of expectations. The inverse of a Kronecker product is the Kronecker product of the inverses, so a inverse becomes two small ones, applied to a gradient-shaped matrix as a sandwich:
EK-FAC (George et al., 2018) keeps the Kronecker eigenbasis of but refits the eigenvalues to the actual second moments of the gradients in that basis, a provably better approximation in their analysis. The same machinery powers the curvature-aware optimizers of Curvature-Aware Optimizers: K-FAC & Shampoo.
You want the influence of all training examples on one test prediction. How many inverse-Hessian–vector products do you need?
- , one per training example
- One, , followed by a dot product with each training gradient
- None: the influence is just the dot product of the raw gradients
- , one per parameter, to form
Show the answer
B. One, , followed by a dot product with each training gradient
because is symmetric. One solve per test point, then one gradient per training point. Attributing many test points at once batches the training-gradient pass.
What influence functions compute in deep networks
Every assumption of the theorem fails for a deep network. The loss is nonconvex, so the Hessian at the trained weights usually has negative eigenvalues; training stops before convergence, so is not a minimizer; and retraining from scratch without , from a new random initialization, lands in a different basin altogether. Koh and Liang added a damping term to the Hessian, which amounts to a convex quadratic model of the loss around . Empirically the results are mixed: Basu, Pope and Feizi (2021) found influence estimates fairly accurate for shallow networks but often wrong for deep, wide ones such as ResNet-50, and highly imprecise on ImageNet, with the accuracy depending on depth, width, parameterization and regularization.
Bae et al. split the gap between practical influence estimates and leave-one-out retraining into five parts: the warm-start gap (retraining from the trained weights instead of from scratch), the proximity gap (the damping), the non-convergence gap, the linearization error and the error of the iterative solver. On several architectures, influence estimates computed with a damped Gauss–Newton Hessian matched the PBRF well even where they matched leave-one-out retraining poorly. So influence functions answer a well-defined question, a local, warm-started counterfactual, which is still useful for finding influential or mislabeled examples. It is just not the question "what if this example had never existed".
Groups. Removing a whole group of examples (a data source, a demographic, a labeling function) is far from infinitesimal. Koh, Ang, Teo and Liang (2019) nevertheless found that influence predictions of group effects correlated strongly with the actual effects in rank (Spearman correlations of 0.8 to 1.0 in their experiments) while systematically underestimating their size, and gave a theoretical account of when such correlation should hold.
In a deep network, a damped influence estimate disagrees badly with leave-one-out retraining from scratch. According to Bae et al. (2022), what does it still approximate well?
- Nothing: in nonconvex models influence estimates are uninformative
- The exact leave-one-out change, once enough LiSSA iterations are run
- The response of the trained network to downweighting the example while staying close to its current outputs and weights (the PBRF)
- The gradient of the test loss with respect to the training example's input pixels
Show the answer
C. The response of the trained network to downweighting the example while staying close to its current outputs and weights (the PBRF)
The PBRF is a warm-started, proximal counterfactual. Influence estimates with a damped Gauss–Newton Hessian track it closely, which is why they remain useful for detecting influential and mislabeled examples even though they do not predict cold-start retraining.
Other ways to attribute, and how to grade them
Data attribution asks how training examples shape a model's behavior. Influence functions are one answer among several:
| Method | Estimate | Cost |
|---|---|---|
| TracIn (Pruthi et al., 2020) | over saved checkpoints : the first-order effect of the gradient steps on along the actual training run | gradients at a few checkpoints; no Hessian |
| Datamodels (Ilyas et al., 2022) | a linear model of a test output as a function of which examples are in the training set | fit by regression on very many models trained on random subsets (millions of networks in their study) |
| TRAK (Park et al., 2023) | linearize the network around each trained model, randomly project per-example gradients, and apply the one-step Newton (leave-one-out) estimator of logistic regression; average over a handful of models | a few trained models and projected gradients |
| Data Shapley (Ghorbani & Zou, 2019) | an example's average marginal contribution to performance over random orderings of the data, the Shapley value of a cooperative game | many retrainings; truncated Monte Carlo sampling |
How do you know an attribution is right? The linear datamodeling score (Park et al., 2023) tests whether attribution scores predict what actually happens when the training set changes. Train models on random subsets , each a fraction of the data (100 subsets of half the data in their experiments), and compare their actual outputs with the additive predictions:
Uses. Ranking training examples by self-influence surfaces mislabeled and atypical examples first, which Koh and Liang used, in a logistic-regression spam filter with 10% of its labels flipped, to find the corrupted labels with far fewer inspections than checking at random or by training loss; TracIn's self-influence does the same. Attribution also explains individual predictions, guides data cleaning and selection, and measures memorization: Feldman and Zhang (2020) estimated per-example memorization and influence by subsampling, as Memorization & the Long Tail discusses.
Key takeaways
- Upweighting a training example by moves a strict minimum by ; its influence on a test loss is , and removal is . For least squares this misses exactly the factor .
- One inverse-Hessian–vector product per test point, by conjugate gradients, LiSSA, Arnoldi or a Kronecker-factored Gauss–Newton approximation, plus one gradient per training example, gives every training example's influence.
- In deep networks influence estimates are fragile as predictors of leave-one-out retraining, but with a damped Gauss–Newton Hessian they approximate the proximal Bregman response function, a warm-started local counterfactual that is still useful.
- TracIn, datamodels, TRAK and data Shapley trade cost against fidelity to retraining; the linear datamodeling score grades how well attributions predict models trained on random subsets.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Which expression is the influence of upweighting training example on the loss at , at a strict minimum with Hessian ?
Show the answer
D.
Upweighting moves the optimum by (implicit function theorem), and the test loss changes by its gradient dotted with that move.
LiSSA estimates with the recursion . What does it need, and when does it converge?
- The full Hessian; it converges for any
- Only Hessian–vector products (on mini-batches); it converges when the scaled has eigenvalues in , for instance after scaling so that
- Only gradients; it converges after exactly steps
- Second derivatives of every example separately; it converges when is diagonal
Show the answer
B. Only Hessian–vector products (on mini-batches); it converges when the scaled has eigenvalues in , for instance after scaling so that
It is the Neumann series , which converges when the spectral radius of is below . Scaling the loss (or the Hessian) by a constant and damping enforce this; each step costs one HVP.
Attribution method A has a higher linear datamodeling score than method B on a test set. What does that mean?
- A's top-ranked examples are more often mislabeled
- A is cheaper to compute
- A's scores, summed over a random training subset, rank the outputs of models actually trained on those subsets more accurately
- A's scores have a larger magnitude
Show the answer
C. A's scores, summed over a random training subset, rank the outputs of models actually trained on those subsets more accurately
The LDS is the Spearman correlation between the true outputs of models retrained on random subsets and the additive predictions . It grades counterfactual prediction, not cost or label quality.
Further reading
- P. W. Koh & P. Liang, "Understanding black-box predictions via influence functions," ICML (2017).
- F. R. Hampel, "The influence curve and its role in robust estimation," Journal of the American Statistical Association 69 (1974).
- J. Bae, N. Ng, A. Lo, M. Ghassemi & R. Grosse, "If influence functions are the answer, then what is the question?," NeurIPS (2022).
- R. Grosse, J. Bae, C. Anil, N. Elhage, A. Tamkin, A. Tajdini, B. Steiner, D. Li, E. Durmus, E. Perez, E. Hubinger, K. Lukošiūtė, K. Nguyen, N. Joseph, S. McCandlish, J. Kaplan & S. R. Bowman, "Studying large language model generalization with influence functions," arXiv:2308.03296 (2023).
- S. M. Park, K. Georgiev, A. Ilyas, G. Leclerc & A. Madry, "TRAK: Attributing model behavior at scale," ICML (2023).