QLoRA is a fine-tuning method that adds small trainable matrices (LoRA) to a language model that has been quantized to 4 bits and frozen, and trains only those matrices. It was proposed in 2023 by Dettmers, Pagnoni, Holtzman, and Zettlemoyer.
Fine-tuning a large language model uses a great deal of GPU memory. According to the paper, regular 16-bit fine-tuning of LLaMA 65B requires more than 780GB of GPU memory. Earlier quantization methods worked for inference but not for training.
QLoRA greatly reduces memory while keeping the same accuracy as 16-bit training through the following techniques.
- 4-bit NormalFloat (NF4): A 4-bit data type that exploits the fact that trained weights are close to normally distributed.
- Double quantization: Quantizes the quantization constants themselves to reduce memory further.
- Paged optimizers: Move optimizer states to CPU memory only when GPU memory runs out, preventing training from stopping due to out-of-memory errors.
- LoRA: Leaves the original weights unchanged and trains only small low-rank matrices.
This makes it possible to fine-tune a 65B-parameter model on a single 48GB GPU. In the paper, Guanaco 65B, a chat model trained this way, reaches 99.3% of ChatGPT's performance on the Vicuna benchmark (24 hours of training on a single GPU).

