NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Understanding the RoPE Extensions of Long-Context LLMs: An Attention Perspective

Meizhi Zhong, Chen Zhang, Yikun Lei, Xikai Liu, Yan Gao, Yao Hu, Kehai Chen, Min Zhang

TL;DR

This paper provides an in-depth look at why Rotary Position Embedding (RoPE) extensions successfully scale up LLM context windows, analyzing them through the lens of attention mechanics. The authors discover that successful extensions work by preserving the model's original short-context attention patterns, whereas long-context retrieval failures are driven by high "attention uncertainty" (entropy). Crucially, they demonstrate that taming this uncertainty requires continual pretraining on longer sequence lengths, rather than simply exposing the model to more tokens.

What Problem Does This Paper Address?

Modern Large Language Models (LLMs) are typically pretrained on relatively short text sequences (e.g., 2K or 4K tokens). When deployed, users frequently want them to process much longer documents, such as entire codebases or long books. Because standard Rotary Position Embeddings (RoPE) fail catastrophically when forced to extrapolate beyond their training length, researchers developed various RoPE extensions—like Position Interpolation (PI), YaRN, and NTK-Aware interpolation—to stretch the context window.

While these extensions work well in practice, their inner workings have largely remained a black box. This paper addresses that gap by investigating why these methods succeed or fail, evaluating them from an attention perspective to understand how they impact the model's internal representations during long-context tasks.

Methods

The authors systematically analyze three widely used RoPE extension methods:

  1. Position Interpolation (PI): Proportionally downscales position indices to fit within the original pretraining window.
  2. NTK-Aware Interpolation: A non-linear interpolation strategy that modifies the base frequency of RoPE to prevent the loss of high-frequency positional information.
  3. YaRN: Combines PI and NTK-Aware methods using a ramp function across different hidden dimensions, adding a temperature factor to handle attention distribution shifts.

To evaluate these extensions, the authors use three target architectures: LLaMA-2-7B, LLaMA-2-13B, and MiniMA-2-3B. They analyze the models using language modeling perplexity (PPL) and visualize attention score distributions. Crucially, they introduce Attention Entropy (a measure of how dispersed or uncertain a model's attention is) and use Jensen-Shannon (JS) divergence to quantify how much an extension distorts the model's original attention patterns.

Datasets

The methods are evaluated on two standard long-context benchmarks:

  • Proof-pile: A dataset used to measure long-context perplexity (PPL), testing the model's ability to maintain coherent language modeling up to 250K tokens.
  • Needle-in-a-Haystack (Needle): A challenging retrieval test where a specific target sentence (the "needle") is embedded at various depths within a long document (the "haystack"). This tests the model's ability to locate and extract specific information across long contexts.

Key Insights and Ideas

  • Preserving the Attention Blueprint: RoPE extensions succeed because they force the model to maintain the same attention patterns it developed during short-context pretraining. When standard RoPE is pushed past its limits, its attention scores fluctuate wildly. Extensions like NTK and YaRN smoothly map long contexts back to the original attention structure.
  • The Entropy Trap: Long-context retrieval errors are not random. The authors show that retrieval failures perfectly align with regions of high attention entropy. When an LLM's attention becomes too dispersed (uncertain) across a massive context window, it loses the ability to pinpoint the "needle."
  • Length Mismatch Matters More Than Token Count: High attention entropy stems from a mismatch between training and inference context lengths. The authors reveal that simply training a model on more tokens at a short context length does not fix long-context degradation. Instead, models must be continually pretrained on longer sequences to actively compress attention entropy and unlock true long-context retrieval.

Key Results

  • Perplexity Extrapolation: On the Proof-pile dataset, the NTK-Aware extension successfully extrapolates up to 32× beyond the pretrained length (stretching from 4K to 128K tokens), outperforming PI and YaRN, which degrade around 62K tokens.
Perplexity comparison across different models and context windows.
  • Attention Pattern Fidelity: JS divergence calculations reveal that NTK and YaRN have an almost zero impact on attention distributions within the original pretrained length (2K), whereas PI significantly distorts them. When scaled to 8K, the extensions successfully revert the attention distribution back to its original 2K shape.
Attention distributions showing how extensions preserve the original 2K pattern at 8K lengths.
  • Taming Uncertainty via Continual Pretraining: In Needle-in-a-Haystack testing, models trained on short contexts suffer severe retrieval errors as context length scales up. However, by continually pretraining the NTK extension on 32K sequence lengths, the authors successfully drop the attention entropy below 5 at a 64K testing length, drastically improving retrieval accuracy.
Needle-in-a-Haystack performance showing that 32K continual pretraining reduces attention entropy and eliminates retrieval errors.

Limitations and Future Work

The primary limitation acknowledged by the authors is scope: this study focuses exclusively on decoder-only language models (specifically the LLaMA architecture). The paper does not validate whether these attention insights and entropy dynamics hold true for encoder-decoder (e.g., T5) or encoder-only (e.g., BERT) architectures. Future work could explore if attention entropy behaves similarly in these alternative setups, or investigate architectural modifications that inherently minimize attention dispersion without requiring expensive long-context continual pretraining.

Summary updated

BibTeX
@inproceedings{zhong2025understanding,
  author = {Meizhi Zhong and Chen Zhang and Yikun Lei and Xikai Liu and Yan Gao and Yao Hu and Kehai Chen and Min Zhang},
  title = {{Understanding the RoPE Extensions of Long-Context LLMs: An Attention Perspective}},
  booktitle = {International Conference on Computational Linguistics},
  year = {2025},
  url = {https://openreview.net/forum?id=beNTbglGFE},
}
Figure