QLoRA: 4-bit quantized model with Low Rank Adapters (LoRA)

The QLoRA paper describes backpropagating gradients through a frozen, 4-bit quantized pretrained language model into Low Rank Adapters (LoRA).

Verified

On this page

Definition

The QLoRA paper describes backpropagating gradients through a frozen, 4-bit quantized pretrained language model into Low Rank Adapters (LoRA). The paper says QLoRA uses a new high-precision technique to quantize a pretrained model to 4-bit. The paper reports enough memory savings to finetune a 65B parameter model on a single 48GB GPU; its limitations also state that matching full 16-bit finetuning performance at 33B and 65B scales was not established.

The paper states that regular 16-bit finetuning of a LLaMA 65B parameter model requires more than 780 GB of GPU memory. It adds that recent quantization methods can reduce the memory footprint of LLMs, but such techniques only work for inference and break down during training.

At a glance

The paper says QLoRA achieves high-fidelity 4-bit finetuning via two techniques it proposes, 4-bit NormalFloat (NF4) quantization and Double Quantization. The paper also introduces Paged Optimizers to prevent memory spikes during gradient checkpointing from causing out-of-memory errors that have traditionally made finetuning on a single machine difficult for large models.

  • Gradients are backpropagated through a frozen, 4-bit quantized pretrained language model.
  • The adapter receives gradients passed through the fixed pretrained model weights and is updated to optimize the loss function.
  • QLoRA has one low-precision storage data type, usually 4-bit, and one computation data type, usually BFloat16.
  • Paged Optimizers use NVIDIA unified memory to avoid the gradient checkpointing memory spikes that occur when processing a mini-batch with a long sequence length.

The source does not state the order of these points, so they are listed without arrows.

How it works

The paper defines quantization as the process of discretizing an input from a representation that holds more information to a representation with less information. The paper describes Low-rank Adapter (LoRA) finetuning as a method that reduces memory requirements by using a small set of trainable parameters, often termed adapters, while not updating the full model parameters, which remain fixed. The paper terms the data type that has an equal expected number of values in each quantization bin k-bit NormalFloat (NFk), since the data type is information-theoretically optimal for zero-centered normally distributed data.

The paper introduces Double Quantization (DQ), the process of quantizing the quantization constants for additional memory savings. For the second quantization in Double Quantization, the paper uses 8-bit Floats with a blocksize of 256, because no performance degradation is observed for 8-bit quantization, in line with results from Dettmers and Zettlemoyer. The paper says Double Quantization saves an average of about 0.37 bits per parameter, approximately 3 GB for a 65B model.

In the paper’s Paged Optimizers, optimizer states receive paged memory: they are automatically moved to CPU RAM when GPU memory runs out, and back to GPU memory when needed for an optimizer update. According to the paper, whenever a QLoRA weight tensor is used, the tensor is dequantized to BFloat16 and a matrix multiplication is then performed in 16-bit. The paper says QLoRA dequantizes the storage data type to the computation data type to perform the forward and backward pass, but only computes weight gradients for the LoRA parameters, which use 16-bit BrainFloat.

The paper says that applying LoRA to query and value attention projection matrices, the standard practice it cites, is not able to replicate full finetuning performance for large base models. In the paper’s Figure 2 RougeL experiment with LLaMA 7B on Alpaca, the authors improve the Stanford Alpaca full-finetuning defaults to build a strong 16-bit baseline; they report that using LoRA on all Transformer layers is critical to match that baseline.

Example

In the paper's chatbot finetuning setup, multiple responses are available for OASST1 and HH-RLHF, and the paper then selects the top response at every level of the conversation tree and finetunes on the full selected conversation, including the instructions. In that training setup, the paper uses NF4 QLoRA with double quantization and paged optimizers to prevent memory spikes during gradient checkpointing. The paper performs QLoRA finetuning with cross-entropy loss (supervised learning) without reinforcement learning, even for datasets that include human judgments of different responses.

For evaluation, the paper uses the Vicuna prompts, a set of 80 prompts from a diverse set of categories, without modifications. In the paper's automated evaluation, given a query along with ChatGPT's and a model's responses, GPT-4 is prompted to assign a score out of ten to both responses and provide an explanation. A model's overall performance is then calculated as a percentage of the score that ChatGPT achieved.

The paper finds a significant ordering effect with GPT-4 increasing the score of the response occurring earlier in the prompt. The paper reports that its Guanaco model family reaches 99.3% of the performance level of ChatGPT on the Vicuna benchmark while only requiring 24 hours of finetuning on a single GPU. In a separate experiment, the paper finetunes LLaMA 7B through 65B on two instruction following datasets, Alpaca and FLAN v2, and evaluates on the MMLU benchmark via 5-shot accuracy.

The paper says that in this experiment NF4 with double quantization fully recovers the 16-bit LoRA MMLU performance. The paper says it did not establish that QLoRA can match full 16-bit finetuning performance at 33B and 65B scales. The paper also did not evaluate other bit precisions, such as 3-bit base models, or other adapter methods.

The paper provides evaluations on MMLU, the Vicuna benchmark, and the OA benchmark, but did not evaluate on other benchmarks such as BigBench, RAFT, and HELM, and it is not ensured that its evaluations generalize to these benchmarks. For Paged Optimizers, the paper does not provide hard measurements, since the paging only occurs when processing mini-batches with long sequence lengths, which is rare. The paper analyzes the runtime of paged optimizers for 65B models on 48GB GPUs and finds that with a batch size of 16, paged optimizers provide the same training speed as regular optimizers.

In the paper’s Appendix G training-memory analysis, batch size is 1, sequence length is 512, and gradient checkpointing is used; under those conditions, the 33B model does not quite fit in a 24 GB GPU and the paper says paged optimizers are needed to train it.

Sources

This page is written from the official sources below. Open them to check the original text.

Verified ·

This page is written by AI from the official sources above and checked automatically. This site has not tested it. Found a mistake? Tell us.