[Paper Review] LLM Maybe LongLM: Self-Extend LLM Context Window Without Tuning
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.
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.

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.

Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.