Papers › LongLoRA: Efficient Fine-tuning of Long-Context Large Language Models

LongLoRA: Efficient Fine-tuning of Long-Context Large Language Models

21 Sep 2023arXiv:2309.12307archive 2025-07-28

Yukang Chen, Shengju Qian, Haotian Tang, Xin Lai, Zhijian Liu, Song Han, Jiaya Jia

We present LongLoRA, an efficient fine-tuning approach that extends the context sizes of pre-trained large language models (LLMs), with limited computation cost. Typically, training LLMs with long context sizes is computationally expensive, requiring extensive training hours and GPU resources. For example, training on the context length of 8192 needs 16x computational costs in self-attention layers as that of 2048. In this paper, we speed up the context extension of LLMs in two aspects. On the one hand, although dense global attention is needed during inference, fine-tuning the model can be effectively and efficiently done by sparse local attention. The proposed shifted sparse attention effectively enables context extension, leading to non-trivial computation saving with similar performance to fine-tuning with vanilla attention. Particularly, it can be implemented with only two lines of code in training, while being optional in inference. On the other hand, we revisit the parameter-efficient fine-tuning regime for context expansion. Notably, we find that LoRA for context extension works well under the premise of trainable embedding and normalization. LongLoRA combines this improved LoRA with S^2-Attn. LongLoRA demonstrates strong empirical results on various tasks on Llama2 models from 7B/13B to 70B. LongLoRA extends Llama2 7B from 4k context to 100k, or Llama2 70B to 32k on a single 8x A100 machine. LongLoRA extends models' context while retaining their original architectures, and is compatible with most existing techniques, like Flash-Attention2. In addition, we further conduct supervised fine-tuning with LongLoRA and our long instruction-following LongAlpaca dataset.

PaperPDFCodeCode Syntology ran

In Syntology View this paper on Syntology, its page in Syntology's graph. That page adds which of its functions are also present in other papers' code Syntology holds, with dates, and its dated run record as JSON and a README badge. It also lists the repositories linked to the paper, the abstract and the calls for agents.

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

For agents, on Syntology's MCP service (how to connect):

Code

Syntology 13 code samples harvested from 2 repositories linked to this paper: 11 ran (of which 0 constructed an object rather than computing a result; 5 with no instrument failure: 0 honoured, 0 violated, 5 with no contract checked; 6 where Syntology's instrument failed) · 2 unverified. Where Syntology's instrument failed: 6 where our contract draft was wrong; failures of Syntology's instrument, not of the code.

By repository: official repository: 11 samples from 1 repository, 9 ran (5 with no instrument failure; 4 where Syntology's instrument failed); community (archive-listed): 2 samples from 1 repository, 2 ran (0 with no instrument failure; 2 where Syntology's instrument failed). The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

No sample is linked to this paper from 2 of its repositories that Syntology harvested for other papers:

Levels written between 2026-09-22 and 2026-09-24 (UTC): the dates Syntology's graph wrote each sample's verification level, not when the code executed. 3 of the 11 samples that ran have no recorded date.

dvlab-research/longlora officialmentioned in papermentioned on GitHubpytorchApache-2.0Syntology: 11 samples, 9 ran (4 instrument-failed) · 2 unverified report
dexter-gt-86/sinklora mentioned on GitHubpytorchSyntology: 2 samples, 2 ran (2 instrument-failed) · 0 unverified report
jzhang38/longmamba mentioned on GitHubpytorchSyntology: no sample linked to this paper (harvested for another paper). Syntology's graph links these samples to Lost in the Middle: How Language Models Use Long Contexts (arXiv:2307.03172; that paper's own run record: 2 ran (of which 0 constructed an object rather than computing a result; 0 with no instrument failure: 0 honoured, 0 violated, 0 with no contract checked; 2 where Syntology's instrument failed) · 2 unverified); nothing checks that they implement this paper's method. report
openaccess-ai-collective/axolotl mentioned on GitHubpytorchApache-2.0Syntology: no sample linked to this paper (harvested for another paper). Syntology's graph links these samples to ACL Anthology id 2025.naacl-long.489 (that paper's own run record: 2 ran (of which 0 constructed an object rather than computing a result; 2 with no instrument failure: 0 honoured, 0 violated, 2 with no contract checked; 0 where Syntology's instrument failed) · 0 unverified); nothing checks that they implement this paper's method. 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.

A paper named beside a repository with no sample linked to this paper is shown with that paper's own run record, not this paper's: “ran” means executed on a synthesized input, not that the code is correct, and “where Syntology's instrument failed” counts failures of Syntology's instrument, not of the code. Papers are listed in arXiv-id order, at most three per repository.

Code Syntology ran Syntology

13 samples harvested: 11 ran (of which 0 constructed an object rather than computing a result; 5 with no instrument failure: 0 honoured, 0 violated, 5 with no contract checked; 6 where Syntology's instrument failed) · 2 unverified. “Where Syntology's instrument failed” counts failures of Syntology's instrument, not of the code. Syntology's record for this page last changed ; when this build read Syntology's graph is in the build record. That date is not when the samples ran.

6ran · our draft was wrong
5ran
2unverified

Licence: 1 of the 13 samples is pointer only, meaning Syntology does not serve that copy's text. For that sample, this paper's copy is under a permissive licence and cleared, but the stored copy of the same code that Syntology serves is not; the licence label's tooltip gives Syntology's recorded reason. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from 2 repositories linked to this paper, official or community; the list below is grouped by repository, each group headed by its name and what it is to the paper. “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. A line beginning “fixture:” under a sample that ran gives the arguments Syntology's fixture called the sample with, each as name:type/rank/element kind (? where none was recorded), and the type of what the fixture's run returned, exactly as the harness recorded them; the arguments and the returned type were recorded by two separate runs of the same fixture. No output value is shown, and a returned type says nothing about whether the output was right. “Level recorded” gives the UTC date when Syntology's graph wrote the sample's verification level, not when the code executed; where the level was written before Syntology's graph kept that date, the row says “level recorded, date not recorded”. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself. “Our draft was wrong” and “the contract check could not run” are failures of Syntology's instrument, not of the code: the sample ran on Syntology's synthesized input, and then the drafted contract did not describe it, or the check itself raised an error (RAISES), lacked a dependency (DEP_MISSING) or ran out of time (TIMEOUT); hover the label for which. A metamorphic tier, where shown, is evidence of the output's shape, not that the sample implements the method.

Each sample ends with its code_sha256. A sample's code_sha256 is Syntology's identity for that exact code. It is printed in full (16 hexadecimal characters for every sample in this build), and get_code(code_sha256="…") takes it exactly as printed. An agent calls it on Syntology's MCP service (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 are grouped by repository: a repository marked official first, then by how directly the repository is tied to the paper, then in the archive's order; never by how many ran. 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 six 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; the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar); this paper's copy was not located, so its licence is not recorded; or this paper's copy is cleared, but the stored copy of the same code that Syntology serves is not. 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.

A function or class name links to its page when the name occurs in the harvested code of at least 5 papers; the name is a string, not an identity. A census tag appears when Syntology's census ran implementations with that name on one shared input per bucket: it gives how many were compared, from how many papers, and how many distinct outputs they produced, and names this sample's bucket when this sample was one of them.

dvlab-research/longlora official repository 11 samples, 9 ran (4 instrument-failed) · 2 unverified
apply_rotary_pos_emb in 393 papers
census: 14 implementations from 15 papers, 8 distinct outputs across 7 buckets, one shared input per bucket
gptneox_attn_replace.py ran Apache-2.0 (permissive) · 69a0f4765d90c784 · report fixture: signature q:Tensor/4/float, k:Tensor/4/float, cos:Tensor/4/float, sin:Tensor/4/float, position_ids:Tensor/2/int · returned tuple · level recorded 2026-09-24
build_generator in 10 papers inference-qlora.py ran Apache-2.0 (permissive) · 6825ff72a7589319 · report fixture: signature model:callable/0/?, tokenizer:callable/0/?, temperature:float/0/float, top_p:float/0/float, max_gen_len:int/0/int, use_cache:bool/0/bool · returned function · level recorded 2026-09-24
build_generator in 10 papers inference.py ran Apache-2.0 (permissive) · ac1119ee1865680d · report fixture: signature model:callable/0/?, tokenizer:callable/0/?, temperature:float/0/float, top_p:float/0/float, max_gen_len:int/0/int, use_cache:bool/0/bool · returned function · level recorded 2026-09-24
generate_prompt_landmark in 8 papers passkey_retrivial.py ran Apache-2.0 (permissive) · 7a94ab5fa9fb06b7 · report fixture: signature n_garbage:int/0/int, seed:int/0/int · returned tuple · level recorded 2026-09-24
greedy_generate run_streaming_llama_longalpaca.py ran · our draft was wrong Apache-2.0 (permissive) · 0a11ee057df336ca · report fixture: signature model:callable/0/?, tokenizer:MinimalTokenizer/0/?, input_ids:Tensor/2/int, past_key_values:NoneType/0/?, max_gen_len:int/0/int · returned list · level recorded, date not recorded
jload in 59 papers supervised-fine-tune-qlora.py ran · our draft was wrong Apache-2.0 (permissive) · d07d04439cd1d44f · report fixture: signature f:str/0/str, mode:str/0/str · returned dict · level recorded, date not recorded
passkey_retrieval_test in 7 papers passkey_retrivial.py ran Apache-2.0 (permissive) · 34957aa45775f8d7 · report fixture: signature model:callable/0/?, tokenizer:callable/0/?, device:str/0/str, use_cache:bool/0/bool, n_garbage:int/0/int, seed:int/0/int · returned tuple · level recorded 2026-09-24
preprocess in 284 papers
census: 11 implementations from 13 papers, 10 distinct outputs across 5 buckets, one shared input per bucket
supervised-fine-tune-qlora.py ran · our draft was wrong Apache-2.0 (permissive) here; the stored copy is pointer only · 817d5f759487007d · report fixture: returned dict · level recorded 2026-09-24
rotate_half in 424 papers
census: 24 implementations from 96 papers, 4 distinct outputs across 2 buckets, one shared input per bucket this sample: bucket 1 of 2, arg 1: rank 2, kind float, dtype float32
gptneox_attn_replace.py ran · our draft was wrong fingerprinted Apache-2.0 (permissive) · e03d53ba9d4f9ae5 · report fixture: signature x:Tensor/2/float · returned Tensor · level recorded, date not recorded
forward_noflashattn llama_attn_replace.py unverified Apache-2.0 (permissive) · 16874ed1d391bd65 · report
make_supervised_data_module in 15 papers supervised-fine-tune-qlora.py unverified Apache-2.0 (permissive) · fa5531158d53f0a8 · report
dexter-gt-86/sinklora community (archive-listed) 2 samples, 2 ran (2 instrument-failed) · 0 unverified
read_txt_file in 9 papers inference.py ran · our draft was wrong Apache-2.0 (permissive) · fd83f4f62a5a7d95 · report fixture: signature material_txt:str/0/str · returned str · level recorded 2026-09-22
tokenize_fn in 9 papers fine-tune.py ran · our draft was wrong Apache-2.0 (permissive) · ad4c52b7c7083143 · report fixture: signature tokenizer:callable/0/?, example:dict/0/? · returned dict · level recorded 2026-09-22

Tasks

4kInstruction FollowingQuestion AnsweringText Summarizationparameter-efficient fine-tuning

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

SPEED

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