{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/longlora-efficient-fine-tuning-of-long","title":"LongLoRA: Efficient Fine-tuning of Long-Context Large Language Models","arxiv_id":"2309.12307","date":"2023-09-21","proceeding":null,"authors":["Yukang Chen","Shengju Qian","Haotian Tang","Xin Lai","Zhijian Liu","Song Han","Jiaya Jia"],"abstract":"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.","url_abs":"https://arxiv.org/abs/2309.12307v3","url_pdf":"https://arxiv.org/pdf/2309.12307v3.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"longlora-efficient-fine-tuning-of-long","repo_url":"https://github.com/dvlab-research/longlora","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"Apache-2.0"}},{"paper_slug":"longlora-efficient-fine-tuning-of-long","repo_url":"https://github.com/dexter-gt-86/sinklora","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"longlora-efficient-fine-tuning-of-long","repo_url":"https://github.com/jzhang38/longmamba","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"longlora-efficient-fine-tuning-of-long","repo_url":"https://github.com/openaccess-ai-collective/axolotl","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"Apache-2.0"}}],"tasks":[{"task_slug":"4k","task_name":"4k"},{"task_slug":null,"task_name":"GPU"},{"task_slug":"instruction-following","task_name":"Instruction Following"},{"task_slug":"question-answering","task_name":"Question Answering"},{"task_slug":"text-summarization","task_name":"Text Summarization"},{"task_slug":"parameter-efficient-fine-tuning","task_name":"parameter-efficient fine-tuning"}],"methods":[{"method_slug":"speed","method_name":"SPEED"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2309.12307","atlas_url":"https://app.syntology.ai/?focus=2309.12307","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2309.12307"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-25T09:33:49+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/openaccess-ai-collective/axolotl","reach":{"status":"ok","spdx":"Apache-2.0"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/dvlab-research/longlora","reach":{"status":"ok","spdx":"Apache-2.0"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/dexter-gt-86/sinklora","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/jzhang38/longmamba","reach":null}],"summary":{"ran":6,"ran_draft_wrong":5,"unverified":2},"by_repo_kind":{"official":{"samples":11,"ran":9,"repositories":1},"listed":{"samples":2,"ran":2,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"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"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"69a0f4765d90c784","entry":"apply_rotary_pos_emb","repo":"dvlab-research/longlora","repo_kind":"official","path":"gptneox_attn_replace.py","file_url":"https://github.com/dvlab-research/longlora/blob/HEAD/gptneox_attn_replace.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"69a0f4765d90c784"}},{"code_sha256_prefix":"6825ff72a7589319","entry":"build_generator","repo":"dvlab-research/longlora","repo_kind":"official","path":"inference-qlora.py","file_url":"https://github.com/dvlab-research/longlora/blob/HEAD/inference-qlora.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"6825ff72a7589319"}},{"code_sha256_prefix":"ac1119ee1865680d","entry":"build_generator","repo":"dvlab-research/longlora","repo_kind":"official","path":"inference.py","file_url":"https://github.com/dvlab-research/longlora/blob/HEAD/inference.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"ac1119ee1865680d"}},{"code_sha256_prefix":"7a94ab5fa9fb06b7","entry":"generate_prompt_landmark","repo":"dvlab-research/longlora","repo_kind":"official","path":"passkey_retrivial.py","file_url":"https://github.com/dvlab-research/longlora/blob/HEAD/passkey_retrivial.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"7a94ab5fa9fb06b7"}},{"code_sha256_prefix":"0a11ee057df336ca","entry":"greedy_generate","repo":"dvlab-research/longlora","repo_kind":"official","path":"run_streaming_llama_longalpaca.py","file_url":"https://github.com/dvlab-research/longlora/blob/HEAD/run_streaming_llama_longalpaca.py","link_basis":"plan_row","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"0a11ee057df336ca"}},{"code_sha256_prefix":"d07d04439cd1d44f","entry":"jload","repo":"dvlab-research/longlora","repo_kind":"official","path":"supervised-fine-tune-qlora.py","file_url":"https://github.com/dvlab-research/longlora/blob/HEAD/supervised-fine-tune-qlora.py","link_basis":"plan_row","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"d07d04439cd1d44f"}},{"code_sha256_prefix":"34957aa45775f8d7","entry":"passkey_retrieval_test","repo":"dvlab-research/longlora","repo_kind":"official","path":"passkey_retrivial.py","file_url":"https://github.com/dvlab-research/longlora/blob/HEAD/passkey_retrivial.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"34957aa45775f8d7"}},{"code_sha256_prefix":"817d5f759487007d","entry":"preprocess","repo":"dvlab-research/longlora","repo_kind":"official","path":"supervised-fine-tune-qlora.py","file_url":"https://github.com/dvlab-research/longlora/blob/HEAD/supervised-fine-tune-qlora.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"817d5f759487007d"}},{"code_sha256_prefix":"fd83f4f62a5a7d95","entry":"read_txt_file","repo":"dexter-gt-86/sinklora","repo_kind":"listed","path":"inference.py","file_url":"https://github.com/dexter-gt-86/sinklora/blob/HEAD/inference.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"fd83f4f62a5a7d95"}},{"code_sha256_prefix":"e03d53ba9d4f9ae5","entry":"rotate_half","repo":"dvlab-research/longlora","repo_kind":"official","path":"gptneox_attn_replace.py","file_url":"https://github.com/dvlab-research/longlora/blob/HEAD/gptneox_attn_replace.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"e03d53ba9d4f9ae5"}},{"code_sha256_prefix":"ad4c52b7c7083143","entry":"tokenize_fn","repo":"dexter-gt-86/sinklora","repo_kind":"listed","path":"fine-tune.py","file_url":"https://github.com/dexter-gt-86/sinklora/blob/HEAD/fine-tune.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"ad4c52b7c7083143"}},{"code_sha256_prefix":"16874ed1d391bd65","entry":"forward_noflashattn","repo":"dvlab-research/longlora","repo_kind":"official","path":"llama_attn_replace.py","file_url":"https://github.com/dvlab-research/longlora/blob/HEAD/llama_attn_replace.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"16874ed1d391bd65"}},{"code_sha256_prefix":"fa5531158d53f0a8","entry":"make_supervised_data_module","repo":"dvlab-research/longlora","repo_kind":"official","path":"supervised-fine-tune-qlora.py","file_url":"https://github.com/dvlab-research/longlora/blob/HEAD/supervised-fine-tune-qlora.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"fa5531158d53f0a8"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}