Context Length Extension via Generalized Extrapolation Scale

Linhan Li, Huaping ZhangACL 2024

Abstract

Researchers have introduced GeNE (Generalized extrapolatioN scalE), a simple yet powerful method to extend the context window of Large Language Models (LLMs) without requiring massive compute. By randomly scaling the extrapolation ratio during fine-tuning, GeNE allows a model trained on 16k-token sequences to maintain high performance on contexts as long as 64k tokens, outperforming or matching state-of-the-art techniques like CLEX and YaRN.

1. Introduction

Most LLMs are built on the Transformer architecture, which uses a fixed context window defined during pre-training. When these models encounter sequences longer than their training limit, their performance collapses—a phenomenon known as the "train short, test long" challenge.

The root of the problem lies in Rotary Position Embeddings (RoPE). While RoPE is excellent at capturing relative positions, extending it to longer sequences often results in "out-of-distribution" positional data that the model doesn't know how to interpret. Previous solutions like Position Interpolation (PI) or NTK-aware scaling manually "squish" the positions to fit the original range, but these often struggle with "density"—the model isn't used to seeing so many tokens packed into the same relative positional space.

2. Methodology

The authors propose two primary innovations under the GeNE framework:

2.1 Batch-wise Random Scaling (BRS)

Instead of fine-tuning the model on a single, fixed target length (like 64k), the researchers randomly vary the "extrapolation ratio" in every training batch. This forces the model to adapt to a wide variety of positional "densities," effectively simulating the patterns of much longer contexts even when training on shorter sequences (e.g., 16k).

2.2 Generalized Interpolation Function

GeNE adopts an "NTK-by-parts" approach. It identifies a critical dimension—the point where the wavelength of the positional embedding exceeds the original context length. Dimensions below this threshold are extrapolated directly, while those above are interpolated.

Figure 1: Visualization of Random Scaling and the comparison of interpolation methods across dimensions.

Additionally, the authors experimented with GeNE-Param, making the extrapolation scale trainable to allow each attention head to independently learn how to best adjust its positional angular velocity.

3. Experimental Setup

The researchers used a variety of datasets for training and evaluation:

  • Training: A subset of RedPajama-arxiv and RedPajama-book, truncated to 16k tokens.
  • Evaluation: The test splits of Proof-pile and PG19 to measure perplexity across lengths from 4k to 64k. Downstream performance was assessed using LongBench and synthetic passkey retrieval tasks.

4. Key Results and Analysis

GeNE demonstrates that density adaptation is key to successful context extension. By using BRS, the model learns to remain robust even when the "distance" between tokens in the embedding space becomes very small.

4.1 Performance Benchmarks

A Llama2-7B model fine-tuned with GeNE on 16k sequences maintained stable perplexity up to 64k tokens. On the PG19 dataset at 64k length, GeNE achieved a perplexity of 7.53, significantly better than YaRN (8.42) and PI (12.30).

Table 1: Perplexity results on the Proof-pile dataset comparing GeNE with state-of-the-art methods across various context lengths.

On LongBench, GeNE-llama2-7b-4k performed competitively with specialized long-context models like LongChat-v1.5-32k, particularly in Few-shot and Summarization tasks. In passkey retrieval, GeNE maintained over 90% accuracy up to its target 64k length.

5. Conclusion

GeNE offers a simple yet effective alternative to complex methods like CLEX. While it achieves state-of-the-art results, future work is needed to explore its generalizability to other positional embedding types and to reduce the fine-tuning data requirements, which currently stand at roughly 0.6 billion tokens.

Summary updated

BibTeX
@inproceedings{li2024context,
  author = {Linhan Li and Huaping Zhang},
  title = {{Context Length Extension via Generalized Extrapolation Scale}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.findings-acl.249},
}
Figure