Papers › Long-Context Language Modeling with Parallel Context Encoding

Long-Context Language Modeling with Parallel Context Encoding

26 Feb 2024arXiv:2402.16617archive 2025-07-28

Howard Yen, Tianyu Gao, Danqi Chen

Extending large language models (LLMs) to process longer inputs is crucial for a wide range of applications. However, the substantial computational cost of transformers and limited generalization of positional encoding restrict the size of their context window. We introduce Context Expansion with Parallel Encoding (CEPE), a framework that can be applied to any existing decoder-only LLMs to extend their context window. CEPE employs a small encoder to process long inputs chunk by chunk, enabling the frozen decoder to utilize additional contexts via cross-attention. CEPE is efficient, generalizable, and versatile: trained with 8K-token documents, it extends the context window of LLAMA-2 to 128K tokens, offering 10x the throughput with only 1/6 of the memory. CEPE yields strong performance on language modeling and in-context learning. CEPE also excels in retrieval-augmented applications, while existing long-context models degenerate with retrieved contexts. We further introduce a CEPE variant that can extend the context window of instruction-tuned models using only unlabeled data, and showcase its effectiveness on LLAMA-2-CHAT, leading to a strong instruction-following model that can leverage very long contexts on downstream tasks.

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

Code

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

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

princeton-nlp/cepe 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

12 samples harvested; 8 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.

3ran · our draft was wrong
2ran · fixture could not drive it
3ran
4unverified

Licence: 0 of the 12 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 princeton-nlp/cepe. “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 princeton-nlp/cepe/modeling_llama_flash.py official repository ran · fixture could not drive it fingerprinted MIT (permissive) · 30d7eec482ebf6b1 · report
apply_rotary_pos_emb princeton-nlp/cepe/modeling_llama_flash.py official repository ran · fixture could not drive it MIT (permissive) · f725bc2d76076485 · report
calibrate_nll princeton-nlp/cepe/eval_downstream.py official repository ran MIT (permissive) · e2d9698be9ebfc0b · report
normalize_answer princeton-nlp/cepe/utils.py official repository ran · our draft was wrong fingerprinted MIT (permissive) · 6c668580324cfd97 · report
preprocess_demos princeton-nlp/cepe/eval_downstream.py official repository ran MIT (permissive) · 251deacd01d3875f · report
remove_citations princeton-nlp/cepe/utils.py official repository ran · our draft was wrong fingerprinted MIT (permissive) · 5df8b525aada9853 · report
rotate_half princeton-nlp/cepe/modeling_llama_flash.py official repository ran · our draft was wrong fingerprinted MIT (permissive) · b99eea6376d1e212 · report
sample_demos princeton-nlp/cepe/eval_downstream.py official repository ran MIT (permissive) · 268c530f5ecad1f4 · report
f1_score princeton-nlp/cepe/utils.py official repository unverified MIT (permissive) · 27f9fcd2b79fea52 · report
load_data princeton-nlp/cepe/dataset_utils.py official repository unverified MIT (permissive) · 45d38779c4dcf77e · report
load_qa_templates princeton-nlp/cepe/dataset_utils.py official repository unverified MIT (permissive) · c1dc7ad8978154d9 · report
preprocess_alce princeton-nlp/cepe/dataset_utils.py official repository unverified MIT (permissive) · 6ec1f8f1d608c575 · report

Tasks

In-Context LearningInstruction FollowingLanguage ModelingLanguage Modelling

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

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