TL;DR
Are Large Language Models (LLMs) actually reasoning, or just regurgitating memorized training data? This paper uses influence functions to trace LLM outputs back to their pretraining data, revealing that models solve math problems by synthesizing "procedural knowledge" (like code and formulas) rather than retrieving exact answers. This suggests LLM reasoning is a genuine generalization strategy, heavily driven by code in the training corpus.
What Problem Does This Paper Address?
LLMs are currently saturating reasoning benchmarks, but they also exhibit brittle, unhuman-like failures that make researchers question if they possess genuine understanding. A major roadblock in answering this question is "data contamination"—because modern LLMs are trained on almost the entire internet, it is nearly impossible to separate their training data from test benchmarks.
Because we can't use traditional train/test splits to measure generalization, the authors tackle a different question: How do LLMs learn to reason from pretraining data? When an LLM solves a math problem, is it simply retrieving a memorized answer it saw during training, or is it applying a robust, generalized strategy learned from broader concepts?
Methods
To figure out which training documents cause an LLM to generate a specific answer, the authors use EK-FAC influence functions. Adapted from robust statistics for large-scale Transformers, this technique estimates the counterfactual: How much would the probability of the model's output change if we removed this specific document from the training set?
The authors took two trained models (Cohere’s Command R 7B and 35B) and a set of prompts (queries). For each query, they calculated an influence score across a massive sample of pretraining documents. They then contrasted the types of documents that were highly influential for reasoning questions versus factual questions.
Datasets
- Pretraining Data: A sample of 5 million documents (roughly 2.5 billion tokens) drawn directly from the models' actual pretraining distribution.
- Evaluation Queries: 80 distinct queries designed to test the models.
- 40 Reasoning Queries: Simple mathematical tasks including two-step arithmetic, calculating slopes, and solving linear equations.
- 40 Factual Queries: Trivia-style questions requiring parametric knowledge retrieval (e.g., "What is the tallest mountain in the world?").
- 20 Control Queries: Questions that look superficially similar to the reasoning/factual prompts but don't actually require reasoning or retrieval.
Key Insights and Ideas
- Reasoning relies on procedures, not memorization: When an LLM answers a factual question, it relies heavily on documents that contain the exact answer. But for reasoning questions, the exact answer is rarely in the influential documents. Instead, the model relies on documents containing procedural knowledge—like a JavaScript function for calculating a slope, or a general math theorem.
- Generalization across similar tasks: The authors found a massive correlation in influence scores between different reasoning queries of the same type. A document that helps the model solve the slope between points A and B is highly likely to help it solve the slope between points X and Y. This proves the model is extracting a generalizable procedure, not just memorizing specific numbers.
- Code is the secret engine of reasoning: Even when prompted in natural language, the documents that most strongly influence an LLM's mathematical reasoning are heavily skewed toward code datasets. This provides mechanistic evidence for the industry "rule of thumb" that including code in pretraining improves general reasoning.
- Diffuse vs. Specific Reliance: Factual recall relies on a narrow, highly specific set of documents. Reasoning, however, relies on a broader, less volatile set of documents. The model synthesizes its reasoning trace from a wider pool of general knowledge rather than leaning on a single "smoking gun" document.
Key Results
- Answer Presence: For the 7B model, the exact answer to a factual query appeared in the top 0.01% most influential documents 55% of the time. For reasoning queries, the exact answer appeared in the top documents only 7.4% of the time (and 0% for the 35B model).
- The Code Multiplier: Data from StackExchange was massively overrepresented in the top influential documents for reasoning tasks—up to 62 times more prevalent than its baseline frequency in the pretraining corpus.
- Influence Correlation: Influence scores across different reasoning queries of the same type (e.g., two different slope questions) showed strong positive Pearson correlations (up to ~0.96). Factual queries showed near-zero correlation with one another.
Limitations and Future Work
The authors acknowledge a few key limitations. First, computing influence functions is incredibly computationally expensive, so they only analyzed a 5-million-document subset (2.5B tokens), not the trillions of tokens in the full pretraining set. It is theoretically possible (though unlikely) that the exact answers to the reasoning questions exist as highly influential documents outside this sample. Second, they only analyzed mathematical reasoning, leaving open the question of whether logical, spatial, or inductive reasoning works the same way. Finally, they did not analyze the supervised fine-tuning (SFT) stage.
Future work will focus on identifying exactly what properties of code make it so influential for natural language reasoning, and investigating how this procedural knowledge interacts with the model's attention heads.
Summary updated