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

Code

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

By repository: official repository: 11 samples from 1 repository, 9 ran; community (archive-listed): 2 samples from 1 repository, 2 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

dvlab-research/longlora officialmentioned in papermentioned on GitHubpytorchApache-2.0 report
dexter-gt-86/sinklora mentioned on GitHubpytorch report
jzhang38/longmamba mentioned on GitHubpytorch report
openaccess-ai-collective/axolotl mentioned on GitHubpytorchApache-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

13 samples harvested; 11 ran; 0 honoured the contract we drafted; 2 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.

5ran · our draft was wrong
6ran
2unverified

Licence: 0 of the 13 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 2 repositories linked to this paper, official or community; each sample names its own and says which. “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 dvlab-research/longlora/gptneox_attn_replace.py official repository ran Apache-2.0 (permissive) · 69a0f4765d90c784 · report
build_generator dvlab-research/longlora/inference-qlora.py official repository ran Apache-2.0 (permissive) · 6825ff72a7589319 · report
build_generator dvlab-research/longlora/inference.py official repository ran Apache-2.0 (permissive) · ac1119ee1865680d · report
generate_prompt_landmark dvlab-research/longlora/passkey_retrivial.py official repository ran Apache-2.0 (permissive) · 7a94ab5fa9fb06b7 · report
greedy_generate dvlab-research/longlora/run_streaming_llama_longalpaca.py official repository ran · our draft was wrong Apache-2.0 (permissive) · 0a11ee057df336ca · report
jload dvlab-research/longlora/supervised-fine-tune-qlora.py official repository ran · our draft was wrong Apache-2.0 (permissive) · d07d04439cd1d44f · report
passkey_retrieval_test dvlab-research/longlora/passkey_retrivial.py official repository ran Apache-2.0 (permissive) · 34957aa45775f8d7 · report
preprocess dvlab-research/longlora/supervised-fine-tune-qlora.py official repository ran Apache-2.0 (permissive) · 817d5f759487007d · report
rotate_half dvlab-research/longlora/gptneox_attn_replace.py official repository ran · our draft was wrong fingerprinted Apache-2.0 (permissive) · e03d53ba9d4f9ae5 · report
forward_noflashattn dvlab-research/longlora/llama_attn_replace.py official repository unverified Apache-2.0 (permissive) · 16874ed1d391bd65 · report
make_supervised_data_module dvlab-research/longlora/supervised-fine-tune-qlora.py official repository unverified Apache-2.0 (permissive) · fa5531158d53f0a8 · report
read_txt_file dexter-gt-86/sinklora/inference.py community (archive-listed) ran · our draft was wrong Apache-2.0 (permissive) · fd83f4f62a5a7d95 · report
tokenize_fn dexter-gt-86/sinklora/fine-tune.py community (archive-listed) ran · our draft was wrong Apache-2.0 (permissive) · ad4c52b7c7083143 · report

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