Skip to main content
QUICK REVIEW

[论文解读] LongLoRA: Efficient Fine-tuning of Long-Context Large Language Models

Yukang Chen, Shengju Qian|arXiv (Cornell University)|Sep 21, 2023
Topic ModelingComputer Science被引用 39
一句话总结

LongLoRA 通过将 Shifted Sparse Attention (S2-Attn) 与可训练嵌入和归一化层结合,能在成本更低的情况下实现长上下文微调,同时保留原推理架构。

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.

研究动机与目标

  • 动机:在长文档任务中扩展预训练大语言模型的上下文窗口,避免高昂的计算成本。
  • 开发一种高效的微调方法,在推理阶段保持标准注意力架构。
  • 引入 Shifted Sparse Attention 以在训练期间以低开销近似完整自注意力。
  • 证明通过可训练的嵌入和归一化层可以缩小 LoRA 与全量微调在长上下文适配中的差距。
  • 在不同大小的 Llama2(7B/13B/70B)上提供经实证评估,展示扩展上下文、具竞争力的困惑度和实际效益。

提出的方法

  • 引入 Shifted Sparse Attention (S2-Attn),将上下文分成组,在组内执行注意力,同时跨半组大小进行 token 移位以实现组间信息流。
  • 使用 LoRA 加上可训练的嵌入和归一化层进行微调(LoRA+),实现有限额外参数的有效长上下文适配。
  • 推理阶段保持完整、未修改的自注意力,以保持与现有基础设施和优化(如 Flash-Attention2)兼容。
  • 通过 Position Interpolation 对位置嵌入进行重缩放,以支持极长的上下文。
  • 使用长指令跟随数据集(LongAlpaca)对监督微调,以提升对话能力。

实验结果

研究问题

  • RQ1是否能在不进行大规模微调的情况下高效扩展预训练 LLM 的上下文长度以应对长文档?
  • RQ2S2-Attn 在微调时是否能在降低计算量的同时提供与完整注意力相当的性能?
  • RQ3启用可训练的嵌入和归一化层是否能缩小 LoRA 与全量微调在长上下文扩展中的性能差距?
  • RQ4在不同模型尺寸(7B、13B、70B)上,在实际硬件条件下可实现的最大扩展上下文长度是多少?
  • RQ5在检索等长上下文任务(如 LongChat 的主题检索)上,LongLoRA 与现有的开放式长上下文 LLMs 相比表现如何?

主要发现

  • LongLoRA 在各种扩展上下文长度下,其困惑度与完整注意力或全量微调基线相当,同时降低了内存和训练成本。
  • S2-Attn 与 Flash-Attention2/DeepSpeed 结合时,扩展上下文可提供最多 1.8x 的内存节省和最多 1.8x 的训练加速。
  • 结合可训练嵌入和归一化(LoRA+),长上下文适配中 LoRA 与全量微调之间的差距显著缩小。
  • 在 Llama2 7B/13B/70B 上,LongLoRA 将上下文长度扩展至 100k(7B)、64k(13B)、32k(70B),在单台 8x A100 机器上实现。
  • 在检索基准中(使用 LongChat 的主题检索),LongLoRA 的表现与最先进的 LongChat-13B 相当,使用对 RedPajama 数据的高效微调。
  • 秘钥检索实验在微调至 32k 后,准确度维持在大约 33k–34k 的上下文范围内,超出该范围呈现温和下降。

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。