Research map / Architectures and efficiency / Attention and transformers
Understanding Addition in Transformers
Read the paperCheck your idea against 108,967 papers
AI-extracted summary. Written by AI from the paper's full text. Numbers and claims can be wrong or missing context, so check the paper before you cite or build on it.
Reverse-engineers a one-layer, three-head Transformer trained on n-digit integer addition, showing it processes digits in parallel streams with left-to-right staging and explaining its failure on rare carry-cascade cases.
Problem
Mechanistic understanding of how a small Transformer performs multi-digit integer addition, including why it is accurate on most questions but fails on rare carry-cascade cases.
Approach
Introduces a mathematical framework of necessary addition subtasks (BaseAdd, MakeCarry, MakeSum, UseCarry, UseSum) used only for analysis, and combines training-loss decomposition, attention-pattern inspection, and ablation to reverse-engineer the model's left-to-right, digit-parallel algorithm.
Key results
- Final training loss of 0.009 for 5-digit, 0.011 for 10-digit and 0.031 for 15-digit addition models.
- The model computes each answer in 6 steps (rows 11 to 16) for 5-digit addition, with three attention heads giving a double-staircase pattern.
- Mean-ablating head 1 raises BaseAdd loss from about 0.05 to 4.7 (or 3.7 in the text), identifying it as the BaseAdd head; the model fails on cascading UseSum cases such as 445+555.
Measured effects reported in the paper
| What was changed | Where | Measured | Effect |
|---|---|---|---|
| Add the Base Add computation performed by Head 1 (ablation) | 1-layer Transformer · 5-digit addition, Base Add questions | average loss: 4.712 -> 0.021 | Helped |
| Add the function of Head 0 (ablation) | 1-layer Transformer · 5-digit addition, Base Add questions | average loss: 0.016 -> 0.021 | Helped |
| Add the function of Head 2 (ablation) | 1-layer Transformer · 5-digit addition, Base Add questions | average loss: 0.062 -> 0.021 | Helped |
| Use the calculations at token positions 11–16 (ablation) | 1-layer Transformer · 5-digit addition | average loss: 0.322, 0.497, 0.604, 0.921, 1.181, 1.021 when ablated | Helped |
| Avoid relying on token positions 0–10 and 17 for the addition calculation (ablation) | 1-layer Transformer · 5-digit addition | average loss: 0.070 | No clear effect |
| Use three attention heads rather than two or four (ablation) | 1-layer Transformer · 5-digit addition | attention-task separation | Helped |
| Use 2 or 4 attention heads instead of 3 (ablation) | 1-layer Transformer · 5-digit addition | interpretability | Hurt |
| Implement the cascading Use Sum 9 cases accurately | 1-layer Transformer · addition with Use Sum 9 cascades | answer correctness | Helped |
| Change the random seed, optimization algorithm, and answer format while retaining a 1-layer model | 1-layer Transformer · 5-digit addition | algorithm behavior | No clear effect |
Surprising findings
- The model starts computing answers later than it could, and it processes digits left to right, which is the opposite of the human right-to-left carry procedure, causing failures on carry cascades.
- Digit 4 and the leading answer digits are learned faster than middle digits, using more attention-head compute than the other digits.
Limitations
- Analysis is limited to a one-layer, small Transformer and does not establish the mechanisms in larger multi-layer models.
- The MLP key-value memory claim is not proven experimentally, and the paper admits some details (such as A5/A4 algorithm) are unresolved.
- Failure on rare cases such as 999,999,999 + 1 is noted but not explained.
Experimental setup
Datasets: synthetic n-digit addition questions (5, 10, 15 digit)
Benchmarks: 5-digit addition test questions 10- and 15-digit addition
Metrics: negative log likelihood loss answer accuracy loss after ablation
Builds on: TransformerLens mathematical framework for transformer circuits
Closest papers by meaning
- Transformers Can Do Arithmetic with the Right Embeddings (NeurIPS 2024 · similarity 0.88)
- Position Coupling: Improving Length Generalization of Arithmetic Transformers Using Task Structure (NeurIPS 2024 · similarity 0.88)
- Algorithmic Capabilities of Random Transformers (NeurIPS 2024 · similarity 0.87)
- Arithmetic Transformers Can Length-Generalize in Both Operand Length and Count (ICLR 2025 · similarity 0.86)
- Assign and Add: A Mechanistic Study of Compositional Arithmetic (NeurIPS 2026 · similarity 0.85)
- Self-Improving Transformers Overcome Easy-to-Hard and Length Generalization Challenges (ICML 2025 · similarity 0.85)
Writing a paper in this area? scime draft is a free LaTeX editor with AI included, real-time co-authors and a check of your references and venue rules before you submit. It also imports OpenAI Prism projects.
