Why Can't Transformers Learn Multiplication? Reverse-Engineering Reveals Long-Range Dependency Pitfalls

Xiaoyan Bai, Itamar Pres, Yuntian Deng, Chenhao Tan, Stuart Shieber, Fernanda Viégas, Martin Wattenberg, Andrew Lee

TL;DR

Standard Transformers fail at multi-digit multiplication because gradient descent under an autoregressive loss gets trapped in local optima that lack necessary long-range dependencies. By reverse-engineering a model trained with Implicit Chain-of-Thought (ICoT), researchers uncovered that successful models construct "attention trees" to cache partial products using elegant Fourier geometries. Leveraging this insight, they show that adding a simple auxiliary loss allows standard models to learn multiplication perfectly without needing any step-by-step text tokens.

What Problem Does This Paper Address?

Despite their massive scale and impressive reasoning capabilities, large language models (LLMs) notoriously stumble on basic arithmetic like multi-digit multiplication. Even models with billions of parameters, like Llama-3 or GPT-4, fail at 4x4-digit multiplication when directly fine-tuned on the task.

While models can solve these problems using explicit Chain-of-Thought (CoT) scratchpads, they fail under standard fine-tuning (SFT) where they must output the answer directly from the operands. This paper tackles a fundamental question: Why do Transformers fail to learn multiplication under standard fine-tuning, and how do they manage to internalize it when trained with chain-of-thought?

Methods

The authors investigate this mystery by contrasting a failing SFT model with a successful Implicit Chain-of-Thought (ICoT) model. ICoT works by training a model with explicit step-by-step tokens but gradually truncating and removing them over training epochs. This forces the model to internalize the intermediate reasoning steps directly into its hidden states.

To understand how the ICoT model succeeds, the authors apply several mechanistic interpretability techniques:

  • Logit Attribution: Measuring how sensitive the output digit predictions are to perturbations in individual input digits.
  • Linear Regression Probing: Training simple linear models to see if intermediate mathematical values (like the running partial sums) can be decoded from the network's hidden layers.
  • Geometric Analysis: Using 3D Principal Component Analysis (PCA) to visualize the spatial structure of token embeddings and attention head outputs.

Finally, using the insights gained from reverse-engineering, they introduce a novel auxiliary loss function. This loss trains a lightweight linear probe to predict the "running partial sum" at each timestep, injecting a helpful inductive bias directly into standard fine-tuning.

Datasets

The authors use a synthetic dataset of 4x4-digit multiplication problems, which they identify as the simplest multiplication task where standard fine-tuning fails but ICoT succeeds.

  • Training Set: 80,800 samples.
  • Validation/Test Sets: 1,000 held-out samples each.
  • The operands are formatted least-significant-digit first (e.g., writing 1234 as 4321) to match standard algorithmic training setups.

Key Insights and Ideas

  • The Long-Range Dependency Pitfall: SFT models fail because they only learn the easiest parts of the problem first (the first and last digits of the product) and then get stuck. Because the middle digits require aggregating information from multiple digit pairs across long token distances, the standard autoregressive loss fails to provide a gradient path that encourages the model to build these long-range connections.
  • Attention Trees as Internal Caches: The successful ICoT model solves this by organizing its attention into a sparse, binary-tree-like directed acyclic graph. Layer 1 attention heads compute and "cache" pairwise partial products ($a_i \times b_j$) at early timesteps, which Layer 2 heads later "retrieve" to compute the final digits.
  • Elegant Internal Geometry: The ICoT model represents digits using a low-dimensional trigonometric subspace. Visualizing the hidden states reveals that the ten digits are arranged cleanly as the vertices of a pentagonal prism in activation space. Furthermore, the attention heads compute digit multiplications geometrically by forming Minkowski sums of these digit embeddings.

Key Results

  • SFT vs. ICoT Performance: Standard fine-tuning on a 2-layer Transformer yields less than 1% accuracy on 4x4 multiplication. Scaling up to a 12-layer model does not fix the issue. In contrast, the ICoT model achieves 100% accuracy.
  • Probing for Intermediate States: Linear probes show that the ICoT model maintains highly accurate representations of the intermediate running sums ($\hat{c}_k$) with an incredibly low Mean Absolute Error (MAE < 2.0). SFT models show completely unstructured, high-error plots, confirming they fail to track this information.
Figure 3: Linear regression probing results for ˆc. We probe from the middle of the last Trans- former block, after attention heads but before MLPs.
  • Success via Auxiliary Loss: By adding the proposed auxiliary loss to guide the model's long-range dependencies, a standard 2-layer Transformer achieves 99% accuracy on 4x4 multiplication without ever using a single chain-of-thought token during training.

Limitations and Future Work

The primary limitation acknowledged by the authors is that their proposed auxiliary loss is highly task-specific; it requires knowing the exact intermediate "running sums" unique to multi-digit multiplication.

However, the broader value of the work is diagnostic. By proving that the core limitation of Transformers in algorithmic tasks is a failure to learn long-range dependencies via standard gradient descent, it opens the door for future research into more general, task-agnostic inductive biases or architectural tweaks that can prevent models from getting stuck in these local optima.

Summary updated

BibTeX
@misc{bai2025why,
  author = {Xiaoyan Bai and Itamar Pres and Yuntian Deng and Chenhao Tan and Stuart Shieber and Fernanda Viégas and Martin Wattenberg and Andrew Lee},
  title = {{Why Can't Transformers Learn Multiplication? Reverse-Engineering Reveals Long-Range Dependency Pitfalls}},
  year = {2025},
  eprint = {2510.00184},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2510.00184},
}
Figure