QLoRA: Efficient Finetuning of Quantized LLMs
Dettmers et al., 2023, QLoRA (Advances in Neural Information Processing Systems 36 (NeurIPS 2023))
Subscriber deck — free during early access
15 cards
1 Introduction
- What does QLoRA make possible?Fine-tuning a 65B-parameter model on a single 48 GB GPU (instead of more than 780 GB for 16-bit fine-tuning) without losing 16-bit fine-tuning performance, by backpropagating through a frozen 4-bit quantized model into LoRA adapters.
- Dettmers et al., 2023, QLoRA (Advances in Neural Information Processing Systems 36 (NeurIPS 2023)), §1
- Why was fine-tuning quantized models an open problem before QLoRA?Quantization methods had reduced memory only for inference; they broke down during training. QLoRA was the first to fine-tune a 4-bit model without performance degradation.
- Dettmers et al., 2023, QLoRA (Advances in Neural Information Processing Systems 36 (NeurIPS 2023)), §1
- What three innovations does QLoRA introduce to save memory?4-bit NormalFloat (NF4), a data type suited to normally distributed weights; Double Quantization, which quantizes the quantization constants; and Paged Optimizers, which move optimizer states between GPU and CPU memory to survive memory spikes.
- Dettmers et al., 2023, QLoRA (Advances in Neural Information Processing Systems 36 (NeurIPS 2023)), §1
2 Background
- What is block-wise quantization, and why is it used?Scaling a tensor by its absolute maximum to fit the low-bit range wastes bins when there are outliers. Splitting the tensor into small blocks, each quantized with its own constant, confines an outlier’s effect to its block.
- Dettmers et al., 2023, QLoRA (Advances in Neural Information Processing Systems 36 (NeurIPS 2023)), §2
3 QLoRA Finetuning
- What are QLoRA’s storage and computation data types?Weights are stored in 4-bit NF4; whenever a weight is used it is dequantized to 16-bit BrainFloat for the matrix multiplication. Gradients flow through the dequantized weights, but only the LoRA adapter parameters (in BF16) receive weight updates.
- Dettmers et al., 2023, QLoRA (Advances in Neural Information Processing Systems 36 (NeurIPS 2023)), §3
- What idea underlies the 4-bit NormalFloat data type?Quantile quantization: give each quantization bin an equal share of values. Because pretrained weights are roughly zero-centred normal, the bins can be computed once from \(\mathcal{N}(0,1)\) quantiles and normalized to \([-1, 1]\); weight blocks are rescaled to that range, avoiding expensive per-tensor quantile estimation.
NF4 idea: bin boundaries at normal quantiles, so each of the 16 bins holds an equal share of the weights - Dettmers et al., 2023, QLoRA (Advances in Neural Information Processing Systems 36 (NeurIPS 2023)), §3
- How does NF4 get an exact zero, and why does that matter?A symmetric quantile scheme has no exact zero. NF4 is built asymmetrically from separate quantiles for the negative and positive halves, sharing one zero, so padding and other zero values are represented exactly while all 16 codes are used.
- Dettmers et al., 2023, QLoRA (Advances in Neural Information Processing Systems 36 (NeurIPS 2023)), §3
- How much memory does Double Quantization save?With blocks of 64 weights and 32-bit constants, constants cost 32/64 = 0.5 bits per parameter. Quantizing them to 8-bit floats in blocks of 256 cuts this to \(8/64 + 32/(64 \cdot 256) \approx 0.127\) bits, saving about 0.37 bits per parameter (about 3 GB for a 65B model).
- Dettmers et al., 2023, QLoRA (Advances in Neural Information Processing Systems 36 (NeurIPS 2023)), §3
- What problem do Paged Optimizers solve?Gradient checkpointing on mini-batches with long sequences causes memory spikes that can crash training on one GPU. Using NVIDIA unified memory, optimizer states are paged out to CPU RAM when the GPU runs out and paged back when needed for the update.
- Dettmers et al., 2023, QLoRA (Advances in Neural Information Processing Systems 36 (NeurIPS 2023)), §3
4 QLoRA vs. Standard Finetuning
- Did 4-bit QLoRA match 16-bit fine-tuning?Yes: with NF4 and double quantization it matched 16-bit full fine-tuning (RoBERTa on GLUE, T5 on Super-NaturalInstructions) and 16-bit LoRA on LLaMA 7B–65B (5-shot MMLU), while QLoRA with plain 4-bit floats lagged by about a point. LoRA adapters on every layer were key.
- Dettmers et al., 2023, QLoRA (Advances in Neural Information Processing Systems 36 (NeurIPS 2023)), §4
- What trade-off between model size and precision does QLoRA suggest?For a fixed fine-tuning and inference memory budget, it is better to use a larger base model at lower precision than a smaller one at higher precision.
- Dettmers et al., 2023, QLoRA (Advances in Neural Information Processing Systems 36 (NeurIPS 2023)), §4
5 Pushing the Chatbot State-of-the-art with QLoRA
- What is Guanaco, and how good was it?LLaMA fine-tuned with QLoRA on OASST1, a small (about 9K examples) high-quality crowd-sourced dialogue dataset. Guanaco 65B reached 99.3% of ChatGPT’s score on the Vicuna benchmark after 24 hours on one GPU; Guanaco 7B needs only 5 GB of memory.
- Dettmers et al., 2023, QLoRA (Advances in Neural Information Processing Systems 36 (NeurIPS 2023)), §5
- What did the QLoRA study reveal about instruction-tuning data?Data quality and suitability matter more than size: 9K OASST1 examples beat 450K FLAN v2 examples on chatbot benchmarks, while FLAN v2 was best on MMLU. Strong MMLU performance does not imply strong chatbot performance, and vice versa.
- Dettmers et al., 2023, QLoRA (Advances in Neural Information Processing Systems 36 (NeurIPS 2023)), §5
- How did Dettmers et al. evaluate chatbots, and how reliable was GPT-4 as a judge?With tournaments of pairwise matches judged by GPT-4 or humans, aggregated into Elo ratings, rather than absolute scores with wide confidence intervals. GPT-4 and human rankings agreed moderately at the system level (Kendall τ 0.43) but weakly per example (Fleiss κ 0.25).
- Dettmers et al., 2023, QLoRA (Advances in Neural Information Processing Systems 36 (NeurIPS 2023)), §5
7 Limitations and Discussion
- What limitations of the QLoRA study do Dettmers et al. acknowledge?They couldn’t afford to show that QLoRA matches full 16-bit fine-tuning at 33B and 65B; they didn’t evaluate other benchmarks (BigBench, HELM), other bit widths or other adapter methods; and benchmark results seem to depend on how similar fine-tuning data is to the benchmark.
- Dettmers et al., 2023, QLoRA (Advances in Neural Information Processing Systems 36 (NeurIPS 2023)), §7
Source
- Tim Dettmers, Artidoro Pagnoni, Ari Holtzman and Luke Zettlemoyer. 2023. QLoRA: Efficient Finetuning of Quantized LLMs. In Advances in Neural Information Processing Systems 36 (NeurIPS 2023). https://papers.nips.cc/paper_files/paper/2023/hash/1feb87871436031bdc0f2beaa62a049b-Abstract-Conference.html