Papers › Focused Transformer: Contrastive Training for Context Scaling

Focused Transformer: Contrastive Training for Context Scaling

6 Jul 2023NeurIPS 2023 11arXiv:2307.03170archive 2025-07-28

Szymon Tworkowski, Konrad Staniszewski, Mikołaj Pacek, Yuhuai Wu, Henryk Michalewski, Piotr Miłoś

Large language models have an exceptional capability to incorporate new information in a contextual manner. However, the full potential of such an approach is often restrained due to a limitation in the effective context length. One solution to this issue is to endow an attention layer with access to an external memory, which comprises of (key, value) pairs. Yet, as the number of documents increases, the proportion of relevant keys to irrelevant ones decreases, leading the model to focus more on the irrelevant keys. We identify a significant challenge, dubbed the distraction issue, where keys linked to different semantic values might overlap, making them hard to distinguish. To tackle this problem, we introduce the Focused Transformer (FoT), a technique that employs a training process inspired by contrastive learning. This novel approach enhances the structure of the (key, value) space, enabling an extension of the context length. Our method allows for fine-tuning pre-existing, large-scale models to lengthen their effective context. This is demonstrated by our fine-tuning of 3B and 7B OpenLLaMA checkpoints. The resulting models, which we name LongLLaMA, exhibit advancements in tasks requiring a long context. We further illustrate that our LongLLaMA models adeptly manage a 256 k context length for passkey retrieval.

PaperPDFConference PDFCodeCode 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="2307.03170")

Code

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

By repository: official repository: 14 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.

cstankonrad/long_llama officialmentioned in paperpytorchApache-2.0 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

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

Licence: 0 of the 14 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 CStanKonrad/long_llama. “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.

match_keywords CStanKonrad/long_llama/fot_continued_pretraining/EasyLM/models/llama/convert_easylm_to_hf.py official repository ran Apache-2.0 (permissive) · cc2ba1b1b0c83f6c · report
mem_apply_update CStanKonrad/long_llama/src/longllama_utils.py official repository ran Apache-2.0 (permissive) · 43de84e441595b25 · report
metrics_assign_group CStanKonrad/long_llama/instruction_fine_tuning/utils.py official repository ran Apache-2.0 (permissive) · 3544c0f9d7c6110f · report
non_numeric_to_str CStanKonrad/long_llama/instruction_fine_tuning/utils.py official repository ran Apache-2.0 (permissive) · 5a004e0660382250 · report
precompute_freqs_cis CStanKonrad/long_llama/fot_continued_pretraining/EasyLM/models/llama/llama_model.py official repository ran Apache-2.0 (permissive) · 1d636c739a91d422 · report
read_json CStanKonrad/long_llama/fot_continued_pretraining/EasyLM/models/llama/convert_easylm_to_hf.py official repository ran · our draft was wrong Apache-2.0 (permissive) · c5bcf01d18bba63d · report
rotate_as_if_first cstankonrad/long_llama/src/modeling_longllama.py official repository ran · our draft was wrong Apache-2.0 (permissive) · a13c903093d13c1f · report
rotate_half CStanKonrad/long_llama/src/modeling_longllama.py official repository ran · our draft was wrong fingerprinted Apache-2.0 (permissive) · b99eea6376d1e212 · report
rotate_one cstankonrad/long_llama/src/modeling_longllama.py official repository ran · fixture could not drive it Apache-2.0 (permissive) · feba6513abb9fb9c · report
apply_rotary_emb CStanKonrad/long_llama/fot_continued_pretraining/EasyLM/models/llama/llama_model.py official repository unverified Apache-2.0 (permissive) · a305ca669a9cacf3 · report
apply_rotary_emb_as_fst CStanKonrad/long_llama/fot_continued_pretraining/EasyLM/models/llama/llama_model.py official repository unverified Apache-2.0 (permissive) · fd8c57f88ddcfa62 · report
get_padding_token CStanKonrad/long_llama/instruction_fine_tuning/data_processing.py official repository unverified Apache-2.0 (permissive) · 21a812da7fd6cdd2 · report
inverse_permute CStanKonrad/long_llama/fot_continued_pretraining/EasyLM/models/llama/convert_hf_to_easylm.py official repository unverified Apache-2.0 (permissive) · c2234099a81ca2e6 · report
tokenize_text_no_special_tokens CStanKonrad/long_llama/instruction_fine_tuning/data_processing.py official repository unverified Apache-2.0 (permissive) · 630a45cda4fbc26b · report

Tasks

Contrastive Learning

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Methods

Absolute Position EncodingsAdamAttentionBPEDense ConnectionsDropoutFocusLabel 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