QLoRA: Efficient Finetuning of Quantized LLMs
TL;DR. Keep the base model frozen in 4 bits and train only LoRA adapters in 16 bits. Three memory tricks make this fit: the NF4 data type, double quantization of the quantization constants, and paged optimizers. A 65B model fine-tunes on a single 48GB GPU and matches 16-bit fine-tuning.
Key idea
Section titled “Key idea”QLoRA has one storage data type (4-bit NF4) and one computation data type (BF16). Each weight tensor is dequantized just before its matmul:
where are the two levels of quantization constants and is the LoRA update (Equation 5). Weight gradients are computed only for . NF4 levels are quantiles of a standard normal, so roughly normal pretrained weights use all levels evenly.
Results
Section titled “Results”On MMLU (Table 4, average across LLaMA sizes and datasets), NF4 with double quantization scores 53.1 against 53.0 for BF16 and 52.2 for FP4. The Guanaco chatbots, trained on OASST1, reach 99.3% of ChatGPT on the Vicuna benchmark after 24 hours on one GPU. In a GPT-4-judged Elo tournament, Guanaco 65B scores 1022 against 966 for ChatGPT and 1348 for GPT-4.
Connections
Section titled “Connections”- Before: LoRA for the adapter itself.
- Alongside: FP8 training for low precision during pretraining; PagedAttention uses the same paging idea for the KV cache.
- Evaluation: the chatbot results rest on a GPT-4 judge; see LLM-as-a-judge.
Questions to think through
These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.
- Derive / compute
For a 65B-parameter model, compute the memory for the 4-bit weights, for the quantization constants with one fp32 constant per block of 64 weights, and for the constants after double quantization (8-bit second-level constants with blocks of 256). Compare with the 16-bit weights alone and with the paper's figure for 16-bit full fine-tuning.
What a strong answer covers
- 4-bit weights: 65e9 × 0.5 bytes = 32.5GB. 16-bit weights alone would be 130GB, before gradients and optimizer state; the paper cites more than 780GB for 16-bit full fine-tuning of LLaMA 65B.
- Single-level constants: 32 bits / 64 = 0.5 bits per parameter, so 65e9 × 0.5 / 8 ≈ 4.06GB.
- Double quantization: 8/64 + 32/(64 × 256) = 0.127 bits per parameter, so about 1.03GB. The saving is 0.373 bits per parameter, about 3GB at 65B.
- This leaves room on a 48GB GPU for LoRA weights, activations (with gradient checkpointing) and paged optimizer state.
- Mechanism
Explain how QLoRA trains through a quantized model: what NF4 is and why it suits pretrained weights, why it is built asymmetrically, how storage and computation data types differ, and what paged optimizers solve. Where do the gradients actually go?
What a strong answer covers
- NF4 places its 16 levels at quantiles of a standard normal, estimated from 2^k + 1 quantiles and normalised to [−1, 1]. Pretrained weights are roughly zero-mean normal, so each level is used about equally; the paper calls this information-theoretically optimal for such data.
- A symmetric quantile grid has no exact zero. NF4 takes 2^(k−1) quantiles for the negative side and 2^(k−1) + 1 for the positive side and merges them, so zero is exactly representable (useful for padding and zero-valued elements).
- Weights are stored in 4-bit NF4 and dequantized to BF16 whenever they are used, so all matmuls run in 16-bit.
- Gradients flow through the frozen dequantized weights to the inputs, but only the LoRA parameters are updated. Paged optimizers use NVIDIA unified memory to move optimizer state to CPU when gradient checkpointing causes memory spikes.
- Memory profile (7B, batch 1): LoRA parameters 26MB, LoRA input gradients 567MB (18MB with checkpointing), 4-bit base 5,048MB, so shrinking LoRA rank saves little.
- Critique
QLoRA claims Guanaco reaches 99.3% of ChatGPT on the Vicuna benchmark and that a 9k-example dataset beats a 450k-example one. Critique what these chatbot results do and do not establish, and what the paper's own MMLU findings imply for using the Vicuna score to choose a model for a RAG reader.
What a strong answer covers
- Ranking uses GPT-4 as a judge in Elo tournaments (GPT-4 1348, Guanaco 65B 1022, ChatGPT 966). Judge bias toward certain styles or toward GPT-like answers is a threat; see LLM-as-judge.
- The paper itself reports that strong MMLU performance does not imply strong Vicuna performance and vice versa, so dataset suitability matters more than size for a given task.
- OASST1 (9k) beating FLAN v2 (450k, subsampled) concerns chatbot quality, not knowledge-intensive QA.
- The core quantization claim is better supported: NF4 with double quantization matches BF16 on MMLU (53.1 vs 53.0 average). For a RAG reader, evaluate grounded QA accuracy and citation faithfulness directly.