Edit model card
YAML Metadata Warning: empty or missing yaml metadata in repo card (https://huggingface.co/docs/hub/model-cards#model-card-metadata)

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

LongLoRA: Efficient Fine-tuning of Long-Context Large Language Models [Paper]
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. 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 shift short attention effectively enables context extension, leading to non-trivial computation saving with similar performance to fine-tuning with vanilla attention. On the other hand, we find that LoRA for context extension works well under the premise of trainable embedding and normalization. LongLoRA demonstrates strong empirical results on various tasks on LLaMA2 models from 7B/13B to 70B. LongLoRA adopts 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 FlashAttention-2. In addition, to make LongLoRA practical, we collect a dataset, LongQA, for supervised fine-tuning. It contains more than 3k long context question-answer pairs. For more details, please refer to the paper.

Highlights

LongLoRA speed up the context extension of pre-trained large language models in both attention-level and weight-level.

  1. The proposed shifted short attention is easy to implement, compatible with Flash-Attention, and not required during inference.
  2. We release all our models, including models from 7B to 70B, context length from 8k to 100k, including LLaMA2-LongLoRA-7B-100k, LLaMA2-LongLoRA-13B-64k, and LLaMA2-LongLoRA-70B-32k.
  3. We build up a long-context QA dataset, LongQA, for supervised fine-tuning (SFT). We release 13B and 70B 32k models with SFT, Llama-2-13b-chat-longlora-32k-sft and Llama-2-70b-chat-longlora-32k-sft. We will further release the dataset next week.

Released models

Models with supervised fine-tuning

Model Size Context Train Link
Llama-2-13b-chat-longlora-32k-sft 13B 32768 LoRA+ link
Llama-2-70b-chat-longlora-32k-sft 70B 32768 LoRA+ link

Models with context extension via fully fine-tuning

Model Size Context Train Link
Llama-2-7b-longlora-8k-ft 7B 8192 Full FT link
Llama-2-7b-longlora-16k-ft 7B 16384 Full FT link
Llama-2-7b-longlora-32k-ft 7B 32768 Full FT link
Llama-2-7b-longlora-100k-ft 7B 100000 Full FT link
Llama-2-13b-longlora-8k-ft 13B 8192 Full FT link
Llama-2-13b-longlora-16k-ft 13B 16384 Full FT link
Llama-2-13b-longlora-32k-ft 13B 32768 Full FT link

Models with context extension via improved LoRA fine-tuning

Model Size Context Train Link
Llama-2-7b-longlora-8k 7B 8192 LoRA+ link
Llama-2-7b-longlora-16k 7B 16384 LoRA+ link
Llama-2-7b-longlora-32k 7B 32768 LoRA+ link
Llama-2-13b-longlora-8k 13B 8192 LoRA+ link
Llama-2-13b-longlora-16k 13B 16384 LoRA+ link
Llama-2-13b-longlora-32k 13B 32768 LoRA+ link
Llama-2-13b-longlora-64k 13B 65536 LoRA+ link
Llama-2-70b-longlora-32k 70B 32768 LoRA+ link
Llama-2-70b-chat-longlora-32k 70B 32768 LoRA+ link

Citation

If you find this project useful in your research, please consider citing:

@article{longlora,
  title={LongLoRA: Efficient Fine-tuning of Long-Context Large Language Models},
  author={Yukang Chen and Shengju Qian and Haotian Tang and Xin Lai and Zhijian Liu and Song Han and Jiaya Jia},
  journal={arXiv:2309.12307},
  year={2023}
}

Acknowledgement

Downloads last month
12
Inference Examples
This model does not have enough activity to be deployed to Inference API (serverless) yet. Increase its social visibility and check back later, or deploy to Inference Endpoints (dedicated) instead.