All for One: LLMs Solve Mental Math at the Last Token With Information Transferred From Other Tokens

Siddarth Mamidanna, Daking Rai, Ziyu Yao, Yilun Zhou

Abstract

Large language models (LLMs) demonstrate proficiency across numerous computational tasks, yet their inner workings remain unclear. In theory, the combination of causal self-attention and multilayer perceptron layers allows every token to access and compute information based on all preceding tokens. In practice, to what extent are such operations present? In this paper, on mental math tasks (i.e., direct math calculation via next-token prediction without explicit reasoning), we investigate this question in three steps: inhibiting input-specific token computations in the initial layers, restricting the routes of information transfer across token positions in the next few layers, and forcing all computation to happen at the last token in the remaining layers. With two proposed techniques, Context-Aware Mean Ablation (CAMA) and Attention-Based Peeking (ABP), we identify an All-for-One subgraph (AF1) with high accuracy on a wide variety of mental math tasks, where meaningful computation occurs very late (in terms of layer depth) and only at the last token, which receives information of other tokens in few specific middle layers. Experiments on a variety of models and arithmetic expressions show that this subgraph is sufficient and necessary for high model performance, transfers across different models, and works on a variety of input styles. Ablations on different CAMA and ABP alternatives reveal their unique advantages over other methods, which may be of independent interest.

Introduction

Transformers are theoretically capable of complex, distributed computation where every token interacts with every preceding token at every layer. However, in practice, the internal mechanisms for specific tasks like "mental math"—direct calculation without chain-of-thought reasoning—remain poorly understood. This paper investigates whether LLMs utilize their full quadratic connectivity or if they rely on a more efficient, localized circuit.

The All-for-One (AF1) Subgraph

The authors identify a highly sparse "All-for-One" (AF1) subgraph that is both necessary and sufficient for mental math tasks. This subgraph organizes computation into three distinct temporal and spatial stages:

  1. Waiting Stage ($L_{wait}$): Initial layers process the general task context but do not require specific operand values.
  2. Transfer Stage ($L_{transfer}$): A brief window in the middle layers where the last token "peeks" at preceding operand tokens to gather necessary data.
  3. Last-Token Computation Stage: The final layers where the last token performs the actual arithmetic operation using the gathered information.
The All-for-One (AF1) subgraph architecture, illustrating the Waiting ($L_{wait}$), Transfer ($L_{transfer}$), and Last-Token Computation stages.

Methodology

To isolate the AF1 subgraph, two novel intervention techniques were developed:

  • Context-Aware Mean Ablation (CAMA): This method replaces input-specific activations in early layers with mean activations calculated over the task context. If the model maintains accuracy, it indicates that those layers are only processing structural information rather than specific data points.
  • Attention-Based Peeking (ABP): This technique modifies attention masks to restrict information flow. It identifies the minimum set of layers and heads required for the last token to successfully retrieve operand values from the context.

Experimental Results

Experiments on Llama-3-8B reveal that the "Waiting" period is surprisingly long, spanning nearly half the model (up to 14 layers). The "Transfer" phase is conversely very brief, often requiring only two layers (e.g., layers 15 and 16).

Model accuracy as a function of the number of waiting layers ($L_{wait}$) and transfer layers ($L_{transfer}$), demonstrating the sharp transitions in performance.

The AF1 subgraph exhibits extreme sparsity. In Llama-3, the authors found that 60 out of 64 attention heads in the transfer layers could be ablated without significant loss in accuracy. Specific heads function as dedicated "data fetchers" for particular operands. Furthermore, the model does not appear to compute intermediate results (e.g., $A+B$) at intermediate tokens; instead, all raw data is funneled to the final token for a single, comprehensive calculation.

Discussion and Conclusion

The AF1 structure generalizes across various prompt styles, including symbolic math, verbal descriptions, and code snippets. However, its effectiveness is limited to tasks that do not require multi-step reasoning or complex tokenization (e.g., where numbers are split into multiple digits). The authors suggest that the "next-token prediction" objective naturally incentivizes this "All-for-One" behavior, as the model is optimized solely for the accuracy of the final output token. This research highlights a fundamental efficiency in how modern LLMs organize arithmetic tasks, suggesting that large portions of the model's depth are dedicated to structural preparation rather than active computation.

Summary updated

Abstract

Large language models (LLMs) demonstrate proficiency across numerous computational tasks, yet their inner workings remain unclear. In theory, the combination of causal self-attention and multilayer perceptron layers allows every token to access and compute information based on all preceding tokens. In practice, to what extent are such operations present? In this paper, on mental math tasks (i.e., direct math calculation via next-token prediction without explicit reasoning), we investigate this question in three steps: inhibiting input-specific token computations in the initial layers, restricting the routes of information transfer across token positions in the next few layers, and forcing all computation to happen at the last token in the remaining layers. With two proposed techniques, Context-Aware Mean Ablation (CAMA) and Attention-Based Peeking (ABP), we identify an All-for-One subgraph (AF1) with high accuracy on a wide variety of mental math tasks, where meaningful computation occurs very late (in terms of layer depth) and only at the last token, which receives information of other tokens in few specific middle layers. Experiments on a variety of models and arithmetic expressions show that this subgraph is sufficient and necessary for high model performance, transfers across different models, and works on a variety of input styles. Ablations on different CAMA and ABP alternatives reveal their unique advantages over other methods, which may be of independent interest.
BibTeX
@misc{mamidanna2025all,
  author = {Siddarth Mamidanna and Daking Rai and Ziyu Yao and Yilun Zhou},
  title = {{All for One: LLMs Solve Mental Math at the Last Token With Information Transferred From Other Tokens}},
  year = {2025},
  eprint = {2509.09650},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2509.09650},
}

Loading related content...

Figure