The Impact of Positional Encoding on Length Generalization in Transformers
By Amirhossein Kazemnejad, Inkit Padhi, Karthikeyan Natesan Ramamurthy, Payel Das, Siva Reddy. 2023
396 citations recorded by the source corpus.
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.
Subfields: Artificial Intelligence, Computer Vision and Pattern Recognition, Model Architectures
How researchers see this paper
The researchers whose trusted networks rank it highest, strongest advocate first. Every researcher gets a different order.
In Artificial Intelligence
- Gabriel Synnaeve
- Jianfeng Gao
- Yossi Adi
- Quoc V. Le
- Ji-rong Wen
- Wayne Xin Zhao
- Jade Copet
- Nicolas Usunier
In Computer Vision and Pattern Recognition
- Luc Van Gool
- Dacheng Tao
- Jiashi Feng
- Chunhua Shen
- Quoc V. Le
- Alan L. Yuille
- Xiaogang Wang
- Ming-Hsuan Yang
In Model Architectures
Citations in the corpus
- Code Llama: Open Foundation Models for Code (2023, background): “Recent work suggests that causal models do not require an explicit encoding of position information (Haviv et al., 2022; Kazemnejad et al., 2023), a hypothesis we did not test in this work as we demonstrated that starting from pretrained Llama 2 models is significantly more efficient than training…”
- A Comprehensive Overview of Large Language Models (2023, neutral): “Self-Attention [44]: The self-attention is also known as intra-attention since all the queries, keys, and values come from the same block (encoder or decoder).”
- SANA: Efficient High-Resolution Image Synthesis with Linear Diffusion Transformers (2024, positive): “Recent cutting-edge research in the LLM field (Kazemnejad et al., 2024; Haviv et al., 2022) has also indicated that NoPE may offer better length generalization ability.”
- Pre-Trained Language Models for Text Generation: A Survey (2022, background): “Certain position embeddings have shown the capacity to generalize to text beyond the training length, referred to as extrapolation capability , including ALiBi [188], xPos [228], and even NoPE [109].”
- Quantifying Positional Biases in Text Embedding Models (2024, unknown): “Positional encoding methods have been studied to address these challenges from both decreasing the effect of content position within training context length[36], and generalizing to longer contexts from itself[13].”