LM-Infinite: Zero-Shot Extreme Length Generalization for Large Language Models

Chi Han, Qifan Wang, Hao Peng, Wenhan Xiong, Yu Chen +2 more
8/30/2023
162 citations
cs.CLcs.AI

Official code: Glaciohound/LM-Infinite (152 stars, Python, MIT, last commit 2025-03-13).

Abstract

Today's large language models (LLMs) typically train on short text segments (e.g., <4K tokens) due to the quadratic complexity of their Transformer architectures. As a result, their performance suffers drastically on inputs longer than those encountered during training, substantially limiting their applications in real-world tasks involving long contexts such as encoding scientific articles, code repositories, or long dialogues.

Show full abstract

Through theoretical analysis and empirical investigation, this work identifies three major factors contributing to this length generalization failure. Our theoretical analysis further reveals that commonly used techniques like truncating the attention window or relative positional encodings are inadequate to address them. Answering these challenges, we propose LM-Infinite, a simple and effective method for enhancing LLMs' capabilities of handling long contexts. LM-Infinite is highly flexible and can be used with most modern LLMs off-the-shelf. Without any parameter updates, it allows LLMs pre-trained with 2K or 4K-long segments to generalize to up to 200M length inputs while retaining perplexity. It also improves performance on downstream tasks such as Passkey Retrieval and Qasper in the zero-shot setting. LM-Infinite brings substantial efficiency improvements: it achieves 2.7x decoding speed up and 7.5x memory saving over the original model. Our codes are released at \url{https://github.com/Glaciohound/LM-Infinite}.

View on arXivView PDF

Code Implementations(1)

MIT

Implementation of NAACL 2024 Outstanding Paper "LM-Infinite: Simple On-the-Fly Length Generalization for Large Language Models"

15213Python, ShellMay 31, 20231 years agoMIT
language-modellong-contextmodel-diagnostics

Similar Papers

Cite this paper

@article{han2023lminfinite,
  title  = {LM-Infinite: Zero-Shot Extreme Length Generalization for Large Language Models},
  author = {Chi Han and Qifan Wang and Hao Peng and Wenhan Xiong and Yu Chen and Heng Ji and Sinong Wang},
  year   = {2023},
  eprint = {2308.16137},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2308.16137v7}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2308.16137.svg)](https://codeofpaper.com/paper/2308.16137)

Discussion