Length generalization, the ability to generalize from small training context sizes to larger ones, is a critical challenge in the development of Transformer-based language models. Positional encoding (PE) has been identified as a major factor influencing length generalization, but the exact impact of different PE schemes on extrapolation in downstream tasks remains unclear. In this paper, we conduct a systematic empirical study comparing the length generalization performance of decoder-only Transformers with five different position encoding approaches including Absolute Position Embedding (APE), T5's Relative PE, ALiBi, and Rotary, in addition to Transformers without positional encoding (NoPE). Our evaluation encompasses a battery of reasoning and mathematical tasks. Our findings reveal that the most commonly used positional encoding methods, such as ALiBi, Rotary, and APE, are not well suited for length generalization in downstream tasks. More importantly, NoPE outperforms other explicit positional encoding methods while requiring no additional computation. We theoretically demonstrate that NoPE can represent both absolute and relative PEs, but when trained with SGD, it mostly resembles T5's relative PE attention patterns. Finally, we find that scratchpad is not always helpful to solve length generalization and its format highly impacts the model's performance. Overall, our work suggests that explicit position embeddings are not essential for decoder-only Transformers to generalize well to longer sequences.
翻译:长度泛化,即从较小的训练上下文规模泛化到更大规模的能力,是基于Transformer的语言模型发展中的一个关键挑战。位置编码已被识别为影响长度泛化的主要因素,但不同位置编码方案对下游任务外推能力的具体影响仍不明确。本文通过系统性实证研究,比较了仅解码器Transformer在五种不同位置编码方法下的长度泛化性能,包括绝对位置嵌入(APE)、T5的相对位置编码、ALiBi、旋转位置编码,以及不含位置编码的Transformer(NoPE)。我们的评估涵盖了一系列推理与数学任务。研究结果表明,最常用的位置编码方法(如ALiBi、旋转编码和APE)并不适用于下游任务的长度泛化。更重要的是,NoPE在无需额外计算的情况下优于其他显式位置编码方法。我们从理论上证明,NoPE既可以表示绝对位置编码也可以表示相对位置编码,但通过随机梯度下降训练后,其注意力模式与T5的相对位置编码最为相似。最后,我们发现草稿本并非总能帮助解决长度泛化问题,其格式对模型性能有显著影响。总体而言,我们的研究表明,显式位置嵌入并非仅解码器Transformer实现良好长序列泛化的必要条件。