Skip to content

Interpretability, attribution, and explanation audits · Interpretability, explanations, and model-mechanism analysis · EXP009 · Algorithm

TracIn checkpoint gradient attribution

Approximate the influence of a training example through gradient alignment with a target example across selected training checkpoints.

Runs in CodeSplash (Experimental) Complete calculation CodeSplash's run and the reference's record

In CodeSplash

A CodeSplash method runs this entry in Python and R. Set it up from the method's page. The methods that run it are Experimental.

Do it in CodeSplash Run it on your own data. It's in the Experimental lane in the app.

Availability
Runs in CodeSplash (Experimental)
Code example
Complete calculation
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
Verified in Python and R through explain.tracin. The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review, on this exact code. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Approximate the influence of a training example through gradient alignment with a target example across selected training checkpoints.

Question / hypotheses

Which examples have gradients aligned with reductions in this target loss along the saved optimization trajectory?

Architecture / computational structure

Per-example gradients are computed at saved checkpoints. Inner products with a target gradient are weighted by learning-rate information and summed. A checkpoint approximation need not record every actual minibatch visit; state which variant is being used.

Assumptions

The loss, checkpoint sequence, parameter subset and optimization convention must be known. The first-order gradient interpretation is approximate for finite steps, momentum, adaptive optimizers, or sparse checkpoint sampling. Scores depend on loss and gradient scaling.

Formula / computational definition

TracInCP(i,t)=∑c∈Cηc ∇θℓi(θc)⊤∇θℓt(θc).\mathrm{TracInCP}(i,t)=\sum_{c\in\mathcal C}\eta_c\,\nabla_\theta\ell_i(\theta_c)^\top\nabla_\theta\ell_t(\theta_c).

Parameters and notation

Predictor checkpoints are fitted states. Explanation choices include checkpoint spacing, learning-rate weights η, gradient layers, loss reduction, projection approximations, and target loss. Positive alignment is commonly interpreted as helpful for reducing the target loss under the specified update convention. Here i identifies a training example, t a target example, C the selected checkpoints, theta_c checkpoint parameters, ell the declared loss, and eta_c the checkpoint learning-rate weight.

Fitting, fine-tuning, and adaptation

Save checkpoints during the original training and adaptation runs. Post-hoc final weights alone cannot recover the complete trajectory. Compare before/after adaptation using clearly defined trajectories rather than mixing checkpoints from different objectives without explanation.

How to use and calibrate

Rank candidate training cases, inspect representative positive and negative scores, and compare selected removals/refits under controlled budgets. Report stability across checkpoint subsets and whether gradient norms dominate the ranking.

Example application

Compare which training sentences support versus oppose a held-out classification decision through gradients of the task loss.

Interpretation / pitfalls

Watch out

A high score can reflect a large gradient, duplication or outlier loss. It is not a calibrated probability that an example caused a prediction. TracIn and inverse-Hessian influence functions approximate different objects.

Python and R code examples

Scope: Exact checkpoint-weighted dot-product calculation for supplied per-example gradients. Python: NumPy; R: base R.

Validation: Python executed successfully on the supplied fixture; R reviewed but unexecuted. Full implementations and supported operation details are provided in the linked primary/official sources.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Complete calculation — Exact checkpoint-weighted dot-product calculation for supplied per-example gradients. Python: NumPy; R: base R. · needs numpy

import numpy as np
gi=np.array([[1.,2.],[.5,1.]]);gt=np.array([[2.,-1.],[1.,.5]]);eta=np.array([.1,.05])
score=np.sum(eta*np.sum(gi*gt,axis=1));print(score)
assert np.isclose(score,.05)
R

Complete calculation — Exact checkpoint-weighted dot-product calculation for supplied per-example gradients. Python: NumPy; R: base R.

gi<-rbind(c(1,2),c(.5,1));gt<-rbind(c(2,-1),c(1,.5));eta<-c(.1,.05)
score<-sum(eta*rowSums(gi*gt));stopifnot(abs(score-.05)<1e-12);print(score)

Sources

From the CodeSplash reference, entry EXP009.