PEPE: Long-context Extension for Large Language Models via Periodic Extrapolation Positional Encodings

Jianling Hu, Dongsheng Guo, Yuli Liu, Qingyao Ai, Lixuan Wang, Xuebing Sun, Qilei Zhang, Quan Zhou, Cheng Luo2025

Abstract

Long-context extension seeks to expand the contextual window in pre-trained large language models (LLMs), allowing them to handle several multiples of their original training context lengths. The primary method for extending the window length involves expanding the initial positional encodings, such as interpolating and extrapolation new positions based on Rotary Position Embedding (RoPE). This expansion inevitably disrupts the positional encodings learned during pre-training, thereby affecting the attention allotment and introducing unseen positional encoding distributions. To address this issue, we propose a new extension strategy based on RoPE, namely Periodic Extrapolation Positional Encodings (PEPE). This strategy expands pre-trained high-dimensional components of positional encodings by replicating them in a periodic manner, thereby neither altering the learned positional encoding spaces nor introducing new positional encoding distributions. Experiments demonstrate that PEPE-based approaches can significantly improve long-context extension capabilities using just one-fourth the fine-tuning steps required by state-of-the-art methods. In addition, we analyze the characteristics of PEPE-based methods and the key parameters that contribute to their effectiveness.

Introduction: The Context Window Bottleneck

Most Large Language Models (LLMs) are pre-trained with a fixed context window, typically around 4,096 tokens. When these models are tasked with processing longer documents, their performance often collapses. This failure is primarily attributed to the Rotary Position Embedding (RoPE) mechanism.

When a model encounters a position index beyond its training horizon (e.g., token 5,000 in a 4,000-token model), it faces an Out-of-Distribution (OOD) problem. Standard extrapolation introduces novel encoding values that the model cannot interpret. Conversely, "interpolation" methods squash long sequences into the original training space, which "crowds" the positional encodings and makes it difficult for the model to distinguish between adjacent tokens. The challenge lies in extending the context window without introducing unseen distributions or degrading the resolution of existing encodings.

Methodology: Recycling Positional Patterns

The PEPE approach is based on the observation that RoPE components behave differently across dimensions. Low-dimensional components rotate quickly, completing many cycles during pre-training, while high-dimensional components rotate slowly and may not complete a single cycle.

PEPE introduces a "periodic" approach to handle these differences:

  1. Low-dimensional components: These continue to use standard extrapolation, as the model has already learned to generalize across multiple complete cycles.
  2. High-dimensional components: Instead of extending into unknown territory, PEPE "recycles" the learned portion of the wave.
Comparison of positional encoding extension methods: Extrapolation, Interpolation, and the proposed PEPE (PSE and mPSE modes).

The paper proposes two variants of this recycling strategy:

  • PSE (Periodic Shift Extrapolation): When the context exceeds the training length $L$, the position index effectively resets ($m \mod L$). This ensures encodings remain strictly within the pre-trained distribution.
  • mPSE (Mirrored PSE): To prevent discontinuities at the boundary where the reset occurs, this version mirrors the pattern, creating a smoother transition for the model's attention mechanism.

Experimental Results

The effectiveness of PEPE was evaluated using the Llama2-7B architecture. Models were fine-tuned on the PG19 dataset and evaluated for perplexity on Proof-pile, a standard benchmark for long-range dependency.

Extreme Stability and Efficiency

A key breakthrough of PEPE is its convergence speed. It achieves state-of-the-art performance in just 100 training steps, whereas competing methods like YaRN typically require 400 or more. This efficiency stems from the fact that the model does not need to learn entirely new positional distributions.

Perplexity comparison across varying context windows. PEPE-based models maintain stability up to 80k tokens, significantly outperforming existing methods.

As shown in the results, when trained on a 32k context, PEPE maintains stable perplexity up to 80k tokens. In contrast, NTK-aware and YaRN methods exhibit significant performance degradation much earlier. Furthermore, in the Passkey Retrieval task, mPSE achieved nearly 100% accuracy at context lengths of 70k tokens with 250 fine-tuning steps.

General Intelligence Preservation

Importantly, PEPE does not impose a "short-term tax." Evaluation on standard benchmarks like ARC, HellaSwag, MMLU, and TruthfulQA showed minimal regression, and in some cases slight improvements, compared to the base Llama2-7B model. This indicates that extending the context window via periodic recycling does not compromise the model's core reasoning capabilities.

Conclusion and Future Work

PEPE offers a highly efficient and stable method for extending the context window of LLMs by leveraging existing positional knowledge. While hardware constraints limited testing to 80k tokens, the theoretical scalability of the method is promising. Future work may involve testing PEPE across a wider variety of model architectures and combining it with external memory mechanisms to push context limits even further.

Summary updated

BibTeX
@misc{hu2025pepe,
  author = {Jianling Hu and Dongsheng Guo and Yuli Liu and Qingyao Ai and Lixuan Wang and Xuebing Sun and Qilei Zhang and Quan Zhou and Cheng Luo},
  title = {{PEPE: Long-context Extension for Large Language Models via Periodic Extrapolation Positional Encodings}},
  year = {2025},
  doi = {10.18653/v1/2025.findings-emnlp.1149},
}
Figure