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

Algorithmic Phase Transitions in Language Models: A Mechanistic Case Study of Arithmetic

Alan Sun, Ethan Sun, Warren ShepardarXiv 2024 · DOI

Abstract

Large Language Models (LLMs) demonstrate remarkable capabilities but often fail on simple logical tasks like multi-digit arithmetic when the input size changes. This study investigates the internal mechanisms of Gemma-2-2b during addition tasks to understand this brittleness. By identifying the specific subcircuits used for different operand lengths, we find that the model does not employ a single, stable algorithm. Instead, it undergoes "algorithmic phase transitions," switching between distinct computational strategies categorized as Symmetric, Boundary, and Interior phases. This lack of algorithmic stability explains the poor generalization observed in LLMs.

Introduction

While LLMs can perform zero-shot arithmetic, their performance is notoriously sensitive to task specifications. A model might succeed on 4-digit addition but fail on 8-digit addition. This research seeks to determine if LLMs utilize a consistent "strong learner" strategy or a "patchwork" of specialized heuristics. We formalize this through the concept of algorithmic stability—the property of maintaining a consistent problem-solving strategy across related tasks.

Methods

The researchers analyzed Gemma-2-2b's performance on a synthetic dataset of two-operand addition problems (1 to 8 digits). They employed mechanistic interpretability techniques, including:

  • Activation Patching: A causal intervention to identify attention heads responsible for correct outputs by swapping activations between "clean" and "corrupted" prompts.
  • Subcircuit Identification: Mapping the minimal set of attention heads used for each of the 64 possible digit-length combinations.
  • Quantitative Comparison: Using t-SNE dimensionality reduction and Pearson correlation to analyze the similarity of these subcircuits across the task space.

Results and Discussion

The study reveals that Gemma-2-2b's internal logic is highly fragmented. Accuracy drops significantly as complexity increases, falling to approximately 32% for 8-digit addition.

Figure 1: (a) Accuracy heatmap across operand lengths. (b) t-SNE visualization showing distinct clusters for Symmetric, Interior, and Boundary phases. (c) Visual representation of subcircuits for each phase.

As illustrated in Figure 1, the model's strategies cluster into three distinct phases. The Symmetric phase occurs when operands have equal digits, the Boundary phase when one operand is a single digit, and the Interior phase covers all other cases. The t-SNE plot (Figure 1b) confirms that these phases represent fundamentally different internal "wiring." For example, Symmetric tasks rely heavily on later layers (14-17), whereas Boundary tasks show activation peaks in both early and late layers.

The "Patchwork" Nature of LLM Logic

The most significant finding is the absence of a universal addition algorithm. The model implements substantially different computational models depending on the input's digit count.

Figure 2: Similarity matrix of subcircuits across 64 task classes. The high variance in correlation scores highlights the lack of a stable, universal algorithm.

Figure 2 demonstrates the quantitative differences between these subcircuits. These sharp "phase transitions" between task classes are a primary reason for generalization failure. Instead of learning a robust rule, the model learns specialized "hacks." Furthermore, the model exhibits asymmetry; adding a large number to a small one uses a different circuit than the reverse, leading to inconsistent reasoning and performance.

Conclusion

This mechanistic case study suggests that algorithmic instability is a core barrier to robust reasoning in LLMs. The discovery of phase transitions provides a new lens through which to evaluate model generalization. Future research should explore whether larger models or different training objectives can foster greater algorithmic stability, moving beyond patchwork heuristics toward universal logic.

Summary updated

BibTeX
@misc{sun2024algorithmic,
  author = {Alan Sun and Ethan Sun and Warren Shepard},
  title = {{Algorithmic Phase Transitions in Language Models: A Mechanistic Case Study of Arithmetic}},
  year = {2024},
  eprint = {2412.07386},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2412.07386},
}
Figure