LongLoRA: Efficiënte fine-tuning van Large Language Models met lange context
LongLoRA: Efficient Fine-tuning of Long-Context Large Language Models
September 21, 2023
Auteurs: Yukang Chen, Shengju Qian, Haotian Tang, Xin Lai, Zhijian Liu, Song Han, Jiaya Jia
cs.AI
Samenvatting
We presenteren LongLoRA, een efficiënte fine-tuning aanpak die de contextgroottes van vooraf getrainde grote taalmodellen (LLMs) uitbreidt, met beperkte rekenkosten. Normaal gesproken is het trainen van LLMs met lange contextgroottes rekenkundig duur, wat uitgebreide trainingsuren en GPU-bronnen vereist. Het trainen op een contextlengte van 8192 vereist bijvoorbeeld 16x zoveel rekenkosten in de self-attention lagen als bij een contextlengte van 2048. In dit artikel versnellen we de contextuitbreiding van LLMs op twee manieren. Enerzijds, hoewel tijdens de inferentie dichte globale aandacht nodig is, kan het fine-tunen van het model effectief en efficiënt worden uitgevoerd met behulp van sparse lokale aandacht. De voorgestelde shift short attention maakt contextuitbreiding effectief mogelijk, wat leidt tot aanzienlijke rekenbesparingen met vergelijkbare prestaties als fine-tuning met standaard aandacht. Het kan met name worden geïmplementeerd met slechts twee regels code tijdens het trainen, terwijl het optioneel is tijdens de inferentie. Anderzijds herzien we het parameter-efficiënte fine-tuning regime voor contextuitbreiding. Opmerkelijk is dat we ontdekken dat LoRA voor contextuitbreiding goed werkt onder de voorwaarde van trainbare embedding en normalisatie. LongLoRA toont sterke empirische resultaten op verschillende taken op LLaMA2 modellen van 7B/13B tot 70B. LongLoRA breidt LLaMA2 7B uit van 4k context naar 100k, of LLaMA2 70B naar 32k op een enkele 8x A100 machine. LongLoRA breidt de context van modellen uit terwijl hun oorspronkelijke architectuur behouden blijft, en is compatibel met de meeste bestaande technieken, zoals FlashAttention-2. Daarnaast hebben we, om LongLoRA praktisch te maken, een dataset, LongQA, verzameld voor supervised fine-tuning. Deze bevat meer dan 3k lange context vraag-antwoord paren.
English
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 shift short 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 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.