NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Interpreting and Improving Large Language Models in Arithmetic Calculation

Wei Zhang, Chaoqun Wan, Yonggang Zhang, Yiu-ming Cheung, Xinmei Tian, Xu Shen, Jieping Ye

Abstract

Large Language Models (LLMs) demonstrate significant arithmetic capabilities, yet the internal mechanisms driving these computations remain poorly understood. This paper investigates the internal "arithmetic circuit" of LLMs, revealing that a sparse subset of attention heads—less than 5%—is responsible for numerical processing. By introducing Precise SFT, a surgical fine-tuning method targeting these specific components, we demonstrate that mathematical performance can be significantly enhanced without the "catastrophic forgetting" of general knowledge typical of full-parameter fine-tuning. Our results show a 15% performance boost in math tasks while maintaining 99.8% of general knowledge performance.

Introduction

While LLMs like LLaMA and GPT exhibit emergent abilities to solve complex mathematical problems, their internal logic is often viewed as a "black box." This lack of transparency poses a challenge for reliability: without understanding how a model calculates, it is difficult to diagnose errors or improve efficiency. Furthermore, traditional fine-tuning—which updates all model parameters—often leads to a performance trade-off. As models become more specialized in mathematics, they frequently lose their "common sense" or general linguistic capabilities, a phenomenon known as catastrophic forgetting.

This research seeks to map the internal "math hardware" of LLMs and provide a methodology to upgrade these specific circuits without compromising the rest of the system's functionality.

Methodology

The researchers proposed a three-step pipeline—Identify, Analyze, and Fine-tune—to isolate and improve the arithmetic capabilities of the model.

1. Identify (Path Patching)

Using causal intervention, researchers systematically "knocked out" specific attention heads and Multi-Layer Perceptrons (MLPs) to observe their impact on the model's ability to predict numerical answers. To isolate calculation logic from general sentence structure, they utilized counterfactual sentences (e.g., changing "3 plus 5" to "3 nothing 5"). This allowed them to pinpoint the exact components responsible for the arithmetic operation itself.

2. Analyze (Pattern Analysis)

The identified components were examined for behavioral patterns. For attention heads, the focus was on which tokens the model prioritized during calculation. For MLPs, "unembedding" probes were used to visualize how numerical information was processed and refined at each layer of the network.

3. Fine-tune (Precise SFT)

Rather than updating billions of parameters, the researchers applied Precise SFT. This method involves fine-tuning only the parameters of the approximately 32 "key" attention heads identified in the first step, leaving the rest of the model's weights frozen.

The Architecture of the Arithmetic Circuit

The study revealed several key insights into how LLMs process numbers:

  • Extreme Sparsity: The "arithmetic circuit" is remarkably small, consisting of less than 5% of the model's attention heads. These heads are primarily concentrated in the middle layers (specifically layers 12–17 in LLaMA2-7B).
  • Division of Labor: The model employs a two-stage process. First, "operand heads" identify the numbers and operators within the text. Subsequently, the MLPs perform a layer-by-layer calculation.
  • Coarse-to-Fine Convergence: Probing the MLPs showed that the model does not jump to the correct answer immediately. Instead, the internal representation first moves toward a general "numerical neighborhood" before converging on the exact digit in the final layers.
  • Transferability: The key heads identified on simple addition tasks were found to be the same components used for complex word problems (GSM8K) and various data formats (decimals, multi-digit integers). This suggests the existence of a universal arithmetic circuit within the model architecture.

Experimental Results

The researchers evaluated their approach using a mix of synthetic arithmetic datasets and real-world benchmarks like GSM8K, AddSub, and SVAMP. General knowledge was tracked using MMLU and CSQA.

  • Performance and Efficiency: Precise SFT achieved an average 15% increase in accuracy across four mathematical datasets. Because only a fraction of parameters were updated, training was 3x faster than standard full-model fine-tuning.
  • Preserving General Knowledge: While full fine-tuning caused a ~5% drop in general benchmarks (MMLU/CSQA), Precise SFT resulted in a negligible impact (often <0.2%). This effectively solves the trade-off between specialization and general utility.
  • Circuit Faithfulness: To verify the importance of the identified heads, researchers performed a knockout test. Disabling only the identified arithmetic circuit caused the model's accuracy to plummet by approximately 70%, proving these components are indeed the primary "engine" of calculation.

Conclusion

This study demonstrates that mathematical reasoning in LLMs is localized within a sparse, identifiable circuit. By targeting these specific components through Precise SFT, it is possible to significantly improve mathematical accuracy while preserving the model's broader knowledge base. Future research may extend this surgical fine-tuning approach to other specialized domains, such as symbolic logic, coding, or factual recall, potentially leading to more efficient and reliable AI systems.

Summary updated

BibTeX
@inproceedings{zhang2024interpreting,
  author = {Wei Zhang and Chaoqun Wan and Yonggang Zhang and Yiu-ming Cheung and Xinmei Tian and Xu Shen and Jieping Ye},
  title = {{Interpreting and Improving Large Language Models in Arithmetic Calculation}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=CfOtiepP8s},
}
Figure