Addition is perhaps one of the simplest arithmetic tasks one can think of and is usually performed using the carrying over algorithm. This algorithm consists of two tasks: adding digits in the same position and carrying over a one whenever necessary. We study how transformer models implement this algorithm and how the two aforementioned tasks are allocated to different parts of the network. We first focus on two-layer encoder-only models and show that the carrying over algorithm is implemented in a modular fashion. The first layer is mostly responsible for adding digits in the same position. The second layer first decides, in the attention, which positions need a carried one or not, and then performs the carrying of the one in the final MLP. We provide a simple way of precisely identifying which neurons are responsible for that task. This implementation of the carrying over algorithm occurs across a range of hyperparameters for two as well as three-layer models. For small decoder-only models, we observe the same implementation and provide suggestive evidence for its existence in three 7B large language models.
翻译:加法或许是最简单的算术任务之一,通常通过进位算法完成。该算法包含两个子任务:对相同数位上的数字相加,以及在必要时执行进位操作。我们研究了Transformer模型如何实现该算法,以及上述两个子任务如何被分配至网络的不同部分。我们首先聚焦于仅含编码器的两层模型,发现进位算法以模块化方式实现:第一层主要负责相同数位数字的相加;第二层首先通过注意力机制判断哪些位置需要进位,随后在最终的多层感知机中执行进位操作。我们提供了一种精确定位该任务相关神经元的简易方法。这种进位算法实现在两层及三层模型的超参数范围内普遍存在。对于小型仅含解码器模型,我们观察到相同的实现机制,并在三个70亿参数的大语言模型中找到了其存在的佐证。