TL;DR
Data Shapley is a gold standard for figuring out which training data points actually help a machine learning model. However, it traditionally requires retraining the model thousands of times—an impossible task for modern Large Language Models (LLMs). This paper introduces In-Run Data Shapley, a method that calculates data attribution on the fly during a single training run with almost zero computational overhead. This breakthrough allows researchers to apply principled data valuation to massive foundation models, revealing fresh insights into data curation, training dynamics, and AI copyright.
The Challenge of Data Attribution
Foundation models are trained on massive, internet-scraped datasets that inevitably contain low-quality, biased, or copyrighted material. To curate better datasets and fairly compensate data creators, we need a way to measure the exact contribution of individual data points to a model's final performance.
The mathematically ideal framework for this is the Shapley value (borrowed from cooperative game theory). However, traditional "Data Shapley" requires retraining the model from scratch on many different subsets of the data to see how the absence of a specific data point affects performance. For large-scale models, this is computationally infeasible. Furthermore, traditional Data Shapley evaluates the learning algorithm in general, rather than telling you how data contributed to the specific model checkpoint you just finished training.
Introducing In-Run Data Shapley
To bypass the need for retraining, the authors propose In-Run Data Shapley. Instead of evaluating data contribution over the entire training process at once, they break it down step-by-step.
- Per-Iteration Valuation: The method calculates the Shapley value for the loss reduction achieved in a single gradient update step, and then simply accumulates these scores over the entire training run.
- Taylor Approximations: To make the math tractable, they use 1st- and 2nd-order Taylor expansions to approximate the change in validation loss. The 1st-order approximation relies on the dot product between the training data's gradient and the validation data's gradient. The 2nd-order adds a Hessian matrix term to capture interactions between data points in the same batch.
- "Ghost" Techniques: Naively computing pairwise gradient dot-products requires instantiating per-sample gradients, which destroys GPU batch efficiency and causes massive memory overhead. Inspired by differential privacy techniques, the authors invent a "ghost dot-product" and "ghost gradient-Hessian-gradient product". These clever tricks reuse intermediate tensors already present during standard backpropagation to compute the exact pairwise dot products in just 1 or 2 backward passes, without ever materializing the massive per-sample gradient vectors.
Key Insights and Ideas
The researchers applied this method to models trained on datasets like The Pile (for GPT-2 and Pythia models) and CIFAR10 (with ResNet18), yielding several fascinating observations:
- Curated datasets are still surprisingly dirty: Even highly curated datasets like The Pile contain actively harmful data. In-Run Data Shapley assigned negative contribution values to ~16% of a Pile subset, which included empty documents and web-crawling errors.
- Data value is a matter of timing: A data point's contribution isn't static; it depends on the training stage. General text (like basic web crawls) is highly valuable in the first few thousand steps to teach the model basic grammar and structure. However, its value quickly drops to zero, while domain-specific data (like ArXiv math papers) becomes the dominant driver of performance later in training.
- Copyright implications beyond verbatim memorization: The authors found that a training document can have a massive contribution score for a specific validation output even if the output is completely paraphrased. This challenges the current legal focus on "verbatim memorization" for copyright infringement, proving mathematically that models extract deep, structural value from copyrighted text without necessarily copying it word-for-word.
Key Results
Negligible Overhead
Thanks to the "ghost" techniques, the 1st-order In-Run Data Shapley processes 70.5 samples/sec, nearly matching the 76.2 samples/sec of standard training. A naive direct implementation is ~18x slower (4.2 samples/sec).
Faster Convergence
By using In-Run Data Shapley to identify and filter out the 16% of negative-value data from a Pile subset, the authors trained a GPT-2 model that reached the target validation loss in 25% fewer training iterations.
High Fidelity
The Taylor approximations closely match the computationally impossible ground-truth Shapley values, achieving a Spearman rank correlation of >0.94.
Limitations and Future Work
While a massive leap forward, the method has a few constraints:
- Validation Data Timing: Because scores are accumulated during the training run, you must define your validation set before training begins. If a new validation use-case arises after training, you would have to rely on saved intermediate checkpoints to approximate the scores.
- Optimizer Compatibility: The mathematical derivations for the "ghost" techniques are currently tailored for standard Stochastic Gradient Descent (SGD). Extending these tricks to adaptive optimizers like Adam—which have complex, stateful normalization terms—is an open technical challenge (though the authors successfully used SGD as a proxy for Adam in their experiments).
- Memory Constraints: While highly optimized, extremely large batch sizes might still hit GPU memory limits, requiring future work into gradient accumulation workarounds.
Summary updated