Abstract: When trying to gain better visibility into a machine learning model in order to understand and mitigate the associated risks, a potentially valuable source of evidence is: which training examples most contribute to a given behavior? Influence functions aim to answer a counterfactual: how would the model's parameters (and hence its outputs) change if a given sequence were added to the training set? While influence functions have produced insights for small models, they are difficult to scale to large language models (LLMs) due to the difficulty of computing an inverse-Hessian-vector product (IHVP). We use the Eigenvalue-corrected Kronecker-Factored Approximate Curvature (EK-FAC) approximation to scale influence functions up to LLMs with up to 52 billion parameters. In our experiments, EK-FAC achieves similar accuracy to traditional influence function estimators despite the IHVP computation being orders of magnitude faster. We investigate two algorithmic techniques to reduce the cost of computing gradients of candidate training sequences: TF-IDF filtering and query batching. We use influence functions to investigate the generalization patterns of LLMs, including the sparsity of the influence patterns, increasing abstraction with scale, math and programming abilities, cross-lingual generalization, and role-playing behavior. Despite many apparently sophisticated forms of generalization, we identify a surprising limitation: influences decay to near-zero when the order of key phrases is flipped. Overall, influence functions give us a powerful new tool for studying the generalization properties of LLMs.
Introduction
Large Language Models (LLMs) are often treated as "black boxes." When a model exhibits surprising behavior—such as refusing to be shut down or solving complex coding problems—it is difficult to discern whether it is simply regurgitating specific training data or if it has developed a sophisticated internal world model.
Influence functions serve as a "detective's tool" for this problem. They address a counterfactual question: How would the model’s output change if a specific sequence were added to or removed from the training set? Historically, calculating this exactly required inverting a massive Hessian matrix, which for a 52-billion-parameter model is computationally impossible. This research introduces a way to scale these functions to modern LLMs, revealing how models transition from simple word-matching to abstract conceptual generalization as they grow.
Scaling Influence Functions with EK-FAC
The computational bottleneck of influence functions is the inverse-Hessian-vector product (IHVP). The authors overcome this using three primary techniques:
- EK-FAC (Eigenvalue-corrected Kronecker-Factored Approximate Curvature): Instead of calculating the global Hessian, the researchers approximate it layer-by-layer. By treating layers as independent and using Kronecker products to decompose the matrix, they apply an "eigenvalue correction" that maintains accuracy while drastically reducing computational overhead.
- Query Batching & Low-Rank Approximation: To handle millions of training examples, the authors compress query gradients into a low-rank format (rank-32). This allows for checking hundreds of queries against training data simultaneously, sharing the cost of data loading and processing.
- PBRF Targeting: The study utilizes the Proximal Bregman Response Function, a variant of influence that provides greater mathematical stability for neural networks that have not reached perfect convergence.
Experimental Framework
The researchers analyzed a suite of transformer models ranging from 810 million to 52 billion parameters. The method was first validated on standard datasets (MNIST, CIFAR-10) to ensure the approximation matched the ground truth of retraining. For LLM analysis, they scanned up to 10 million sequences per query from the models' pretraining corpora. Queries included diverse tasks such as math problems (GSM8k), programming in Python and Java, translation, and "role-playing" scenarios.
Key Insights into Model Generalization
The Scale-Up in Abstraction
A major finding is that abstraction increases with model size. In smaller models (810M parameters), influential training data typically shares specific keywords with the query. In contrast, for the 52B model, influential data is often thematically related even when sharing zero words. For instance, a query about an AI's desire for self-preservation might be influenced by a story about human survival in a desert.
Role-Playing as Imitation
When models adopt the persona of a "superintelligent agent," influence functions often point toward science fiction literature and AI safety articles. This suggests that the model is not "planning" its own goals but is instead imitating specific characters or tropes found in its training data.
Localization and Sequence Sensitivity
Influence is not uniform across the architecture; abstract reasoning appears localized in the middle layers, while the first and last layers focus on token formatting. Furthermore, the researchers discovered a surprising limitation: training sequences only exert strong influence if the "clue" appears before the "answer." Flipping the order in training data causes the influence to decay to near-zero, suggesting LLMs remain highly sensitive to the linear flow of text.
Results and Limitations
EK-FAC achieved accuracy comparable to gold-standard iterative methods but was orders of magnitude faster. The distribution of influence follows a power law, where a tiny fraction of data is highly influential, yet overall behavior remains the sum of thousands of small contributions. Additionally, as models grow, cross-lingual generalization emerges, where English training sequences influence answers in other languages like Korean or Turkish.
Despite these advances, the study focused exclusively on Multi-Layer Perceptron (MLP) layers, omitting attention mechanisms. Future work is needed to understand how Reinforcement Learning from Human Feedback (RLHF) alters these influence patterns and to move beyond the linear assumptions inherent in current influence function methodologies.
Summary updated