Papers › CLEX: Continuous Length Extrapolation for Large Language Models

CLEX: Continuous Length Extrapolation for Large Language Models

25 Oct 2023arXiv:2310.16450archive 2025-07-28

Guanzheng Chen, Xin Li, Zaiqiao Meng, Shangsong Liang, Lidong Bing

Transformer-based Large Language Models (LLMs) are pioneering advances in many natural language processing tasks, however, their exceptional capabilities are restricted within the preset context window of Transformer. Position Embedding (PE) scaling methods, while effective in extending the context window to a specific length, demonstrate either notable limitations in their extrapolation abilities or sacrificing partial performance within the context window. Length extrapolation methods, although theoretically capable of extending the context window beyond the training sequence length, often underperform in practical long-context applications. To address these challenges, we propose Continuous Length EXtrapolation (CLEX) for LLMs. We generalise the PE scaling approaches to model the continuous dynamics by ordinary differential equations over the length scaling factor, thereby overcoming the constraints of current PE scaling methods designed for specific lengths. Moreover, by extending the dynamics to desired context lengths beyond the training sequence length, CLEX facilitates the length extrapolation with impressive performance in practical tasks. We demonstrate that CLEX can be seamlessly incorporated into LLMs equipped with Rotary Position Embedding, such as LLaMA and GPT-NeoX, with negligible impact on training and inference latency. Experimental results reveal that CLEX can effectively extend the context window to over 4x or almost 8x training length, with no deterioration in performance. Furthermore, when evaluated on the practical LongBench benchmark, our model trained on a 4k length exhibits competitive performance against state-of-the-art open-source models trained on context lengths up to 32k. Our code is available at https://github.com/DAMO-NLP-SG/CLEX.

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="2310.16450")

Code

Syntology Ran 9 of 10 code samples harvested from 1 repository linked to this paper; 1 has no recorded run. Of those that ran: 2 ran · our draft was wrong; 1 ran · fixture could not drive it; 6 ran with no contract checked.

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

damo-nlp-sg/clex 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

10 samples harvested; 9 ran; 0 honoured the contract we drafted; 1 has 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
1ran · fixture could not drive it
6ran
1unverified

Licence: 0 of the 10 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 DAMO-NLP-SG/CLEX. “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.

repeat_kv DAMO-NLP-SG/CLEX/CLEX/llama/modeling_llama_clex.py official repository ran · fixture could not drive it fingerprinted MIT (permissive) · 30d7eec482ebf6b1 · report
CLEXScalingRotaryEmbedding damo-nlp-sg/clex/CLEX/clex_layer.py official repository ran MIT (permissive) · 7dc80fb53e148af4 · report
ODELinear damo-nlp-sg/clex/CLEX/clex_layer.py official repository ran MIT (permissive) · 5c1563103cfedd3b · report
apply_rotary_pos_emb DAMO-NLP-SG/CLEX/CLEX/llama/modeling_llama_clex.py official repository ran MIT (permissive) · 24a346e190e492a8 · report
chars_token_ratio DAMO-NLP-SG/CLEX/train/dataset.py official repository ran MIT (permissive) · e5aab3f05887f82f · report
get_context_length DAMO-NLP-SG/CLEX/serve/inference.py official repository ran MIT (permissive) · ee7e8c78ac9624ed · report
load_balancing_loss_func DAMO-NLP-SG/CLEX/CLEX/mixtral/modeling_mixtral_clex.py official repository ran MIT (permissive) · 74f2d25c8432bf82 · report
prepare_logits_processor DAMO-NLP-SG/CLEX/serve/inference.py official repository ran · our draft was wrong fingerprinted MIT (permissive) · 93c25411cf60d992 · report
rotate_half DAMO-NLP-SG/CLEX/CLEX/llama/modeling_llama_clex.py official repository ran · our draft was wrong fingerprinted MIT (permissive) · b99eea6376d1e212 · report
create_datasets DAMO-NLP-SG/CLEX/train/dataset.py official repository unverified MIT (permissive) · b8f03a1ab044bb33 · report

Tasks

4k

1 archive task tag without a task page not shown.

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Methods

Absolute Position EncodingsAdamAttentionBPEDense ConnectionsDropoutGPT-NeoXLabel SmoothingLayer NormalizationLinear LayerMulti-Head AttentionPosition-Wise Feed-Forward LayerResidual ConnectionSoftmaxTransformer

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