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

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

30 Aug 2023arXiv:2308.16137archive 2025-07-28

Chi Han, Qifan Wang, Hao Peng, Wenhan Xiong, Yu Chen, Heng Ji, Sinong Wang

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. 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}.

PaperPDFCodeCode Syntology ran

In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2308.16137")

Code

Syntology Ran 7 of 11 code samples harvested from 1 repository linked to this paper; 4 have no recorded run. Of those that ran: 2 ran · our draft was wrong; 5 ran with no contract checked.

By repository: official repository: 11 samples from 1 repository, 7 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

Glaciohound/LM-Infinite officialmentioned in papermentioned on GitHubpytorchMIT report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

11 samples harvested; 7 ran; 0 honoured the contract we drafted; 4 have no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.

2ran · our draft was wrong
5ran
4unverified

Licence: 0 of the 11 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from Glaciohound/LM-Infinite. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

apply_rotary_pos_emb Glaciohound/LM-Infinite/models/llama.py official repository ran MIT (permissive) · 105fcf1b36112115 · report
blockwise_sequence Glaciohound/LM-Infinite/models/lambda_attention.py official repository ran fingerprinted MIT (permissive) · 18e07933cf1ab714 · report
compute_intermediate_size Glaciohound/LM-Infinite/models/get_llama2/convert_llama_weights_to_hf.py official repository ran fingerprinted MIT (permissive) · 507f475feb734647 · report
pad_sequence_to_length Glaciohound/LM-Infinite/models/lambda_attention.py official repository ran fingerprinted MIT (permissive) · 7018cec6ba82fa30 · report
read_json Glaciohound/LM-Infinite/models/get_llama2/convert_llama_weights_to_hf.py official repository ran · our draft was wrong MIT (permissive) · c5bcf01d18bba63d · report
rotate_half Glaciohound/LM-Infinite/models/llama.py official repository ran · our draft was wrong fingerprinted MIT (permissive) · e03d53ba9d4f9ae5 · report
shift_and_pair Glaciohound/LM-Infinite/models/lambda_attention.py official repository ran fingerprinted MIT (permissive) · b616f600e17afc58 · report
attn_forward_factory Glaciohound/LM-Infinite/models/gpt_j.py official repository unverified MIT (permissive) · 5f0747c4fe665871 · report
detailed_lambda_attention Glaciohound/LM-Infinite/models/llama.py official repository unverified MIT (permissive) · 34f3413b19988369 · report
get_model Glaciohound/LM-Infinite/models/get_model.py official repository unverified MIT (permissive) · 2210e387a48111ec · report
write_model Glaciohound/LM-Infinite/models/get_llama2/convert_llama_weights_to_hf.py official repository unverified MIT (permissive) · 25ab7cdc2eb3c237 · report

Tasks

2k4kArticlesText Generation

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Methods

Absolute Position EncodingsAdamAttentionBPEDense ConnectionsDropoutLabel SmoothingLayer NormalizationLinear LayerMulti-Head AttentionPosition-Wise Feed-Forward LayerResidual ConnectionSPEEDSoftmaxTransformerfail

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections