Mechanistic Interpretability of Large-Scale Counting in LLMs through a System-2 Strategy

Hosein Hasani, Mohammadali Banayeeanzade, Ali Nafisi, Sadegh Mohammadian, Fatemeh Askari, Mobin Bagherian, Ahmad Izadi, Mahdieh Soleymani Baghshah

Abstract

Large language models (LLMs), despite strong performance on complex mathematical problems, exhibit systematic limitations in counting tasks. This issue arises from architectural limits of transformers, where counting is performed across layers, leading to degraded precision for larger counting problems due to depth constraints. To address this limitation, we propose a simple test-time strategy inspired by System-2 cognitive processes that decomposes large counting tasks into smaller, independent sub-problems that the model can reliably solve. We evaluate this approach using observational and causal mediation analyses to understand the underlying mechanism of this System-2-like strategy. Our mechanistic analysis identifies key components: latent counts are computed and stored in the final item representations of each part, transferred to intermediate steps via dedicated attention heads, and aggregated in the final stage to produce the total count. Experimental results demonstrate that this strategy enables LLMs to surpass architectural limitations and achieve high accuracy on large-scale counting tasks. This work provides mechanistic insight into System-2 counting in LLMs and presents a generalizable approach for improving and understanding their reasoning behavior.

Introduction

Large Language Models (LLMs) often struggle with basic counting tasks when the number of items exceeds a specific threshold, typically between 10 and 30 items. This failure is not merely a data deficiency but a fundamental architectural constraint. Transformers perform counting "progressively" by accumulating numerical information across layers. Because models have a finite depth, this internal "System-1" counter eventually saturates, leading to precision loss for larger sets.

This paper explores a "System-2" prompting strategy to bypass these architectural limits. By restructuring inputs into manageable partitions and employing Chain-of-Thought (CoT) reasoning, we enable models to count significantly larger quantities. Furthermore, we apply mechanistic interpretability techniques to reverse-engineer the neural circuitry responsible for this deliberate counting process.

Methodology

The proposed approach combines behavioral prompting with rigorous internal analysis:

  • System-2 Prompting: Long lists are divided into smaller partitions using separator tokens (e.g., |). The model is prompted to count each partition individually before calculating the final sum.
  • Mechanistic Analysis: We utilize CountScope, a causal probing method, to decode latent counts within the model's internal representations.
  • Causal Mediation Analysis: Through activation patching and attention knockout, we identify the specific attention heads and layers responsible for transferring and aggregating partial counts.

Mechanistic Insights: The Three-Stage Pipeline

Our analysis reveals that the model does not simply "guess" the total; it follows a structured neural pipeline across its layers.

Figure 2: Schematic of the three-stage neural pipeline for System-2 counting.
  1. Local Counting: Early to middle layers compute the count of items within a single partition. Probing shows these latent counts are stored with high confidence in the final item and the trailing separator of each partition.
  2. Information Transfer: Specific attention heads in middle-to-late layers (e.g., layers 19–23 in Qwen2.5 7B) read these latent counts and write them into the generated CoT text.
  3. Aggregation: A separate set of heads reads the generated intermediate numbers and performs the final summation.

Results

The System-2 strategy yields dramatic improvements in accuracy across various models. For instance, GPT-4o's accuracy on 91–100 items increased from 24% to 86%. In open-weight models like Qwen2.5 7B, the strategy effectively eliminated the catastrophic failure seen in standard prompting for large item counts.

Figure 1: Comparison of counting accuracy between System-1 and System-2 strategies.

Beyond behavioral gains, we successfully localized the critical logic to specific components. In Qwen2.5 7B, Layer 22 was identified as a critical junction, with Head 13 handling intermediate steps and Head 1 managing final aggregation.

Conclusion

This work demonstrates that the limitations of transformer-based counting can be overcome by shifting from implicit System-1 processing to explicit System-2 reasoning. By providing both a practical prompting strategy and a mechanistic explanation of its success, we offer a blueprint for enhancing and understanding complex reasoning in LLMs. Future research will focus on extending these techniques to more diverse and non-synthetic reasoning tasks.

Summary updated

Abstract

Large language models (LLMs), despite strong performance on complex mathematical problems, exhibit systematic limitations in counting tasks. This issue arises from architectural limits of transformers, where counting is performed across layers, leading to degraded precision for larger counting problems due to depth constraints. To address this limitation, we propose a simple test-time strategy inspired by System-2 cognitive processes that decomposes large counting tasks into smaller, independent sub-problems that the model can reliably solve. We evaluate this approach using observational and causal mediation analyses to understand the underlying mechanism of this System-2-like strategy. Our mechanistic analysis identifies key components: latent counts are computed and stored in the final item representations of each part, transferred to intermediate steps via dedicated attention heads, and aggregated in the final stage to produce the total count. Experimental results demonstrate that this strategy enables LLMs to surpass architectural limitations and achieve high accuracy on large-scale counting tasks. This work provides mechanistic insight into System-2 counting in LLMs and presents a generalizable approach for improving and understanding their reasoning behavior.
BibTeX
@inproceedings{hasani2026mechanistic,
  author = {Hosein Hasani and Mohammadali Banayeeanzade and Ali Nafisi and Sadegh Mohammadian and Fatemeh Askari and Mobin Bagherian and Ahmad Izadi and Mahdieh Soleymani Baghshah},
  title = {{Mechanistic Interpretability of Large-Scale Counting in LLMs through a System-2 Strategy}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2026},
  doi = {10.18653/v1/2026.findings-acl.2031},
}
Figure