Abstract
Enabling LLMs to handle lengthy context is currently a research hotspot. Most LLMs are built upon rotary position embedding (RoPE), a popular position encoding method. Therefore, a prominent path is to extrapolate the RoPE trained on comparably short texts to far longer texts. A heavy bunch of efforts have been dedicated to boosting the extrapolation via extending the formulations of the RoPE, however, few of them have attempted to showcase their inner workings comprehensively. In this paper, we are driven to offer a straightforward yet in-depth understanding of RoPE extensions from an attention perspective and on two benchmarking tasks. A broad array of experiments reveals several valuable findings: 1) Maintaining attention patterns to those at the pretrained length improves extrapolation; 2) Large attention uncertainty leads to retrieval errors; 3) Using longer continual pretraining lengths for RoPE extensions could reduce attention uncertainty and significantly enhance extrapolation.
Introduction
Large Language Models (LLMs) are typically pretrained on relatively short sequences (e.g., 2,048 or 4,096 tokens). When processing much longer documents, performance usually collapses because the model's Rotary Position Embedding (RoPE)—the mechanism that encodes positional information—cannot naturally extrapolate to unseen distances. While several mathematical extensions like Position Interpolation (PI), NTK-Aware, and YaRN have been proposed to mitigate this, the underlying mechanics of why they work or eventually fail have remained under-explored.
The Attention Perspective on RoPE Extensions
This study investigates three primary RoPE extensions through the lens of attention patterns:
- Position Interpolation (PI): Linearly downscales position indices to fit within the original trained range.
- NTK-Aware Interpolation: Uses a non-linear scaling strategy to preserve high-frequency information.
- YaRN (Yet another RoPE extensioN): A hybrid approach combining PI and NTK with a "temperature" factor to manage attention distribution shifts.
The researchers found that the success of these extensions is rooted in Pattern Preservation. Standard RoPE fails because its attention patterns fluctuate wildly when pushed beyond the training limit. In contrast, effective extensions force the model to maintain attention distributions similar to those seen during short-context training.
Performance and Extrapolation Limits
The study evaluates these methods using Perplexity (PPL) on the Proof-pile dataset and the Needle-in-a-Haystack retrieval test.
Key findings include:
- NTK's Superiority: NTK-Aware interpolation showed the strongest extrapolation for perplexity, reaching up to 32× beyond the pretrained length (e.g., from 4K to 128K) before performance degraded.
- The Entropy-Error Link: There is a direct correlation between attention entropy (uncertainty) and retrieval errors. When a model's attention becomes too dispersed across too many tokens, it loses the ability to locate specific information, leading to retrieval failures.
The Role of Continual Pretraining
While mathematical extensions provide a temporary fix, the most robust solution for reducing attention uncertainty is increasing the context length during continual pretraining. Finetuning a model on 32K tokens rather than 4K drastically reduced attention entropy during inference. For instance, at a test length of ~64K tokens, a 32K-trained model maintained low entropy and passed nearly all retrieval tests, whereas 4K-trained models failed significantly despite using RoPE extensions.
Conclusion
RoPE extensions succeed by preserving pretrained attention patterns, but they are ultimately limited by attention uncertainty as context grows. Reducing this uncertainty through longer continual pretraining remains the most effective strategy for enhancing long-context extrapolation in LLMs.
Summary updated