Understanding Addition in Transformers
Philip Quirke, Fazl Barez
TL;DR
This work probes how a deliberately small Transformer learns to perform $n$-digit addition, revealing that the model decomposes the problem into digit-specific, parallel sub-tasks and employs distinct algorithms for different digit positions. By combining a formal mathematical framework with training and prediction analyses and targeted ablations, the authors show how Base Add, Make Carry 1, and Make Sum 9 underlie the computation, with Use Carry 1 and Use Sum 9 propagating carries in a time-ordered fashion; a rare US9 cascade explains high-loss edge cases. The study demonstrates a robust, reusable digit-wise addition circuit that emerges across seeds and training regimes, contributing to mechanistic interpretability and providing a blueprint for analyzing more complex tasks in shallow and deeper transformers. The findings have implications for safety, reliability, and the deliberate construction of interpretable, modular computations within neural networks, and point toward extending the framework to subtraction, multiplication, and other symbolic domains.
Abstract
Understanding the inner workings of machine learning models like Transformers is vital for their safe and ethical use. This paper provides a comprehensive analysis of a one-layer Transformer model trained to perform n-digit integer addition. Our findings suggest that the model dissects the task into parallel streams dedicated to individual digits, employing varied algorithms tailored to different positions within the digits. Furthermore, we identify a rare scenario characterized by high loss, which we explain. By thoroughly elucidating the model's algorithm, we provide new insights into its functioning. These findings are validated through rigorous testing and mathematical modeling, thereby contributing to the broader fields of model understanding and interpretability. Our approach opens the door for analyzing more complex tasks and multi-layer Transformer models.
