Skip to main content
QUICK REVIEW

[Paper Review] LLM Maybe LongLM: Self-Extend LLM Context Window Without Tuning

Hongye Jin, Xiaotian Han|arXiv (Cornell University)|Jan 2, 2024
Handwritten Text Recognition TechniquesComputer Science13 citations
TL;DR

SelfExtend extends an LLM’s context window at inference without fine-tuning by combining grouped attention for distant tokens and standard neighbor attention for nearby tokens, via a floor-based relpos mapping.

ABSTRACT

It is well known that LLMs cannot generalize well to long contexts whose lengths are larger than the training sequence length. This poses challenges when employing LLMs for processing long input sequences during inference. In this work, we argue that LLMs themselves have inherent capabilities to handle long contexts without fine-tuning. To achieve this goal, we propose SelfExtend to extend the context window of LLMs by constructing bi-level attention information: the grouped attention and the neighbor attention. The grouped attention captures the dependencies among tokens that are far apart, while neighbor attention captures dependencies among adjacent tokens within a specified range. The two-level attentions are computed based on the original model's self-attention mechanism during inference. With minor code modification, our SelfExtend can effortlessly extend existing LLMs' context window without any fine-tuning. We conduct comprehensive experiments on multiple benchmarks and the results show that our SelfExtend can effectively extend existing LLMs' context window length. The code can be found at \url{https://github.com/datamllab/LongLM}.

Motivation & Objective

  • Motivate that LLMs have inherent long-context capabilities despite pretraining limits.
  • Address positional out-of-distribution issues in relative position encodings during long-context inference.
  • Propose a tuning-free mechanism to extend context length during inference.
  • Evaluate SelfExtend across language modeling, synthetic long-context, and real-world long-context tasks.

Proposed method

  • Introduce grouped attention that applies a floor-divided position mapping to distant tokens.
  • Preserve standard attention for neighbor tokens within a defined window.
  • Merge grouped and neighboring attentions before the softmax to form SelfExtend attention.
  • Provide a gradient-free, plug-in inference-time modification that does not require fine-tuning.
  • Derive an extended context length formula to quantify the maximum achievable length under SelfExtend.
Figure 1: Illustration of grouped attention. We suppose that the LLM’s pretraining context window length is $5$ and the length of the inference sequence is $8$ . On the left figure, we show the positional Out-of-Distribution (O.O.D.) issue while the input length is out of the pretraining context win
Figure 1: Illustration of grouped attention. We suppose that the LLM’s pretraining context window length is $5$ and the length of the inference sequence is $8$ . On the left figure, we show the positional Out-of-Distribution (O.O.D.) issue while the input length is out of the pretraining context win

Experimental results

Research questions

  • RQ1Can LLMs inherently handle longer contexts beyond pretraining without fine-tuning?
  • RQ2How can unseen large relative positions be mapped to known positions to maintain coherence?
  • RQ3Does SelfExtend improve long-context performance across multiple models and tasks without degrading short-context performance?

Key findings

  • SelfExtend maintains low perplexity beyond the pretraining context window when using grouped attention.
  • Passkey retrieval tasks show 100% accuracy with SelfExtend across depths and contexts, indicating true long-context access.
  • On real-world long-context benchmarks, SelfExtend achieves competitive or superior results versus fine-tuning-based extensions.
  • SelfExtend preserves short-context task performance while enhancing long-context capabilities, allowing plug-in adoption with no training.
  • Experiments across diverse models (Llama-2, Mistral, SOLAR, Phi-2) demonstrate broad applicability of the method.
Figure 2: Perplexity (PPL) using grouped attention with different group sizes under different sequence lengths on PG-19 dataset. The original Llama-2-7b-chat PPL is stable at 4k (4096) sequences (red dotted line) but explodes at 6k (6144) sequences (purple dotted line). The results show the LLMs kee
Figure 2: Perplexity (PPL) using grouped attention with different group sizes under different sequence lengths on PG-19 dataset. The original Llama-2-7b-chat PPL is stable at 4k (4096) sequences (red dotted line) but explodes at 6k (6144) sequences (purple dotted line). The results show the LLMs kee

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.