arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2309.12307cs.CLcs.AIcs.LG
收藏

LongLoRA:长上下文大语言模型的高效微调

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

CUHK(香港中文大学);MIT(麻省理工学院);NVIDIA(英伟达公司)

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

AI总结:

本研究提出LongLoRA高效微调方法,通过移位稀疏注意力与改进的LoRA结合,在低计算成本下扩展大语言模型上下文长度,在Llama2系列模型上取得优异效果。

摘要:

我们提出了LongLoRA,这是一种高效的微调方法,能够在有限的计算成本下扩展预训练大语言模型(LLM)的上下文长度。通常,训练具有长上下文的大语言模型计算成本极高,需要大量的训练时间和GPU资源。例如,在上下文长度为8192的情况下进行训练,自注意力层的计算成本是上下文长度为2048时的16倍。在本文中,我们从两个方面加快了大语言模型的上下文扩展速度。一方面,尽管推理阶段需要密集的全局注意力,但模型的微调可以通过稀疏局部注意力高效完成。我们提出的移位稀疏注意力(shifted sparse attention)能够有效实现上下文扩展,在节省大量计算资源的同时,性能与使用普通注意力的微调效果相当。特别值得一提的是,它在训练阶段仅需两行代码即可实现,而在推理阶段是可选的。另一方面,我们重新审视了用于上下文扩展的参数高效微调机制。值得注意的是,我们发现在嵌入层和归一化层可训练的前提下,用于上下文扩展的LoRA(低秩适配)效果良好。LongLoRA将这种改进后的LoRA与S^2-Attn相结合。LongLoRA在Llama2模型(从7B、13B到70B)的各类任务上展现出了优异的实证结果。在单台8x A100机器上,LongLoRA可将Llama2 7B的上下文从4k扩展到100k,或将Llama2 70B的上下文扩展到32k。LongLoRA在扩展模型上下文的同时保留了其原始架构,并且与大多数现有技术(如Flash-Attention2)兼容。此外,我们还使用LongLoRA和我们构建的长指令跟随LongAlpaca数据集进一步开展了监督微调。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑