TL;DR
QLoRA is a way to fine-tune a large language model when the model barely fits in memory. The pretrained weights are frozen and stored in a compressed 4-bit format. Gradients flow back through those 4-bit weights, but only a small set of LoRA adapters, kept in 16-bit precision, receives updates. Two extra tricks shave the memory of the quantization bookkeeping, and a paging scheme stops rare memory spikes from crashing training.
The result is that a 65-billion-parameter model can be fine-tuned on one 48 GB GPU, with accuracy matching 16-bit LoRA on the benchmarks the authors tested.
Where you'll see it: fine-tuning open-weight chat models on a single workstation or a single rented GPU.
Intuition
Keep the big thing small, train the little thing precisely
Fine-tuning has two memory costs. The first is the model's weights, which must be in memory to run it. The second is everything needed to compute updates: activations, gradients and optimizer state. For a large model the weights dominate the first cost, and the trainable part is tiny.
LoRA already solved most of the second cost. It freezes the weights and adds a small trainable correction to each layer, so only a fraction of a percent of parameters receive gradients. But the frozen weights still sit in 16-bit precision, and at 65 billion parameters that is about 130 GB before anything else.
QLoRA's observation is that the frozen weights do not need to be precise to be useful as a fixed base. If you store them in 4 bits, you save about four times the memory. Training then works like this: when a layer's computation needs the weights, the 4-bit values are expanded to 16-bit for that one multiplication, and the adapters are trained in 16-bit as usual. The adapters can compensate for the small errors the compression introduced, because they are learned from data after the compression.
flowchart LR W[Pretrained weights in 4-bit NF4] -->|dequantise to BF16 per layer| M[Matrix multiply] X[Input activations BF16] --> M L[LoRA adapters in BF16, trained] --> A[Add low-rank correction] X --> A M --> Y[Layer output] A --> Y
Why plain 4-bit quantization is not enough
Quantization of a trained model to 4 bits for inference loses accuracy. Earlier work showed that the loss is real even though the model still works. QLoRA's claim is that the loss can be recovered by training adapters after quantization, and that the choice of 4-bit number format matters a lot for how much is lost.
The math
Block-wise quantization
Quantize a tensor by scaling it so its largest magnitude maps to the top of the integer range. For a tensor , with for signed 8-bit,
Here is the quantization constant, the scale that must be stored to undo the mapping. A single large value, an outlier, sets and wastes most of the integer range on the rest of the tensor. The fix is to cut the tensor into blocks of size and give each block its own constant . QLoRA uses for the weights.
The NormalFloat data type
Pretrained weights are roughly zero-centred and normally distributed, with some standard deviation . If each block is scaled so that its values fall into , the values follow a known shape. The paper builds a 4-bit code book from the quantiles of the standard normal, using
where is the quantile function of (see the Gaussian distribution). Each code value then covers an equal share of the probability mass. The paper also forces an exact zero into the code book, so padding and zero-valued entries quantize without error. The authors call the result 4-bit NormalFloat (NF4) and argue it is information-theoretically optimal for normally distributed data. The optimality claim applies to the stated assumption. The empirical question, which the paper answers, is whether it beats the alternatives.
Double quantization
Each block of 64 weights needs one 32-bit constant, which costs bits per parameter. QLoRA quantizes those constants too, with 8-bit floats in blocks of 256, plus one 32-bit constant per 256 of them:
so the bookkeeping drops from 0.5 to about 0.127 bits per parameter, a saving of about 0.373 bits. The paper reports this as roughly 3 GB for a 65B model.
The QLoRA forward pass
For one linear layer, with stored 4-bit weights , constants , and adapters :
The first term expands the frozen weights to BFloat16 for the multiply. The second term is the LoRA correction, where and . Gradients are computed only for and . The weights need no gradient, but the backward pass still passes through the dequantised weights to reach the adapters.
Paged optimizers
Optimizer state for the adapters is allocated in NVIDIA unified memory. When the GPU runs short during a long-sequence mini-batch, the state is paged to CPU RAM and brought back when the optimizer step needs it. The paper says this avoids the out-of-memory spikes that gradient checkpointing causes on long sequences, and reports that with batch size 16 on a 65B model it matched the speed of regular optimizers.
Worked examples
Take one block of four weights, , and quantize to the signed 4-bit integer range with absmax scaling.
- Find the absmax: .
- Compute the constant: .
- Scale and round each value:
- , rounds to .
- , rounds to .
- , rounds to .
- , rounds to .
- Dequantize by dividing by : .
- Absolute errors: .
Interpretation: the small value is erased entirely, because it is less than half a step away from zero at this scale. A smaller block would give the outlier less influence over its neighbours. This is why QLoRA uses blocks of 64 rather than one scale for the whole tensor.
Count only the stored weights, in bytes per parameter, for parameters.
- 16-bit weights: .
- 4-bit weights: .
- Quantization constants with double quantization: .
- Total frozen-weight storage: .
- Adapter, optimizer, and activation memory must fit in the remaining room on a 48 GB card, which is the paper's claim.
Interpretation: the weights alone drop from about 130 GB to about 33.5 GB. The paper's headline figure is that full 16-bit fine-tuning of a 65B model needs more than 780 GB once optimizer state and gradients are counted, and QLoRA gets this under 48 GB. The paper also points out that most training memory comes from activation gradients, not from the adapters, so the 4-bit weights are only part of the story.
Take one attention projection of size and LoRA rank .
- Full matrix parameters: .
- Adapter parameters: .
- Fraction trainable: , or 0.39%.
Interpretation: each adapter trains about 0.4% of the parameters of the matrix it augments. The paper finds that the total number of adapters matters more for matching full fine-tuning than the rank .
Tradeoffs and failure modes
| Situation | What goes wrong | Better choice |
|---|---|---|
| Model fits comfortably in 16-bit | Quantization adds error and slows the forward pass for no memory gain | Standard 16-bit [[low-rank-adaptation |
| Adapters only on the query and value projections | The paper finds this does not match full 16-bit fine-tuning on large models | Adapters on all linear layers of each block |
| FP4 instead of NF4 | About one MMLU point behind 16-bit in the paper's experiments | NF4 with double quantization |
| Long sequences on a small GPU | Optimizer memory spikes cause out-of-memory crashes | Paged optimizers, as in the paper |
| Inference on the 4-bit model | Dequantisation adds latency per layer | Merge adapters and serve at a precision the hardware runs fast |
| Evaluating only on a single benchmark | Benchmark gaps can hide losses that appear in chat quality | Evaluate on several tasks, including human or model-judged chat |
Two cautions from the paper itself. First, its result is that 4-bit QLoRA matches 16-bit on the benchmarks studied. It does not show where the precision-versus-size tradeoff ends, which the authors leave open. Second, the paper's chatbot evaluations use GPT-4 as a judge, and it notes that model-based judging has uncertainties and sometimes disagrees with human raters.
History
Dettmers, Pagnoni, Holtzman and Zettlemoyer published QLoRA in May 2023 (arXiv 2305.14314). It built on LoRA (Hu et al., 2021) and on Dettmers and Zettlemoyer's earlier work on low-bit quantization for inference. The paper's main contributions were NF4, double quantization and paged optimizers, and the claim that 4-bit fine-tuning reaches 16-bit quality. It also released the Guanaco family of chat models, trained with QLoRA on the OASST1 dataset. The paper reports that the smallest Guanaco, at 7B parameters, needs about 5 GB at deployment.
Its practical significance, as the paper frames it, is that fine-tuning the largest open models becomes possible on a single GPU. See the paper node for the full reading guide.
Check yourself
QuestionIn one sentence, what is stored in 4 bits in QLoRA, and what is trained in 16 bits?Show answer
The frozen pretrained weights are stored in 4-bit NormalFloat. The LoRA adapter matrices are trained in 16-bit BFloat. The forward pass expands the 4-bit weights to 16-bit for each multiplication.
QuestionA block of weights has absmax 2.0. Using signed 4-bit integers in , what is the scale , and what integer does the value become?Show answer
. Then , which rounds to . The value dequantises to , an error of about .
QuestionWhy does double quantization save memory, and by how much per parameter for blocks of 64 with 8-bit constants in blocks of 256?Show answer
Without it, each block of 64 weights carries one 32-bit constant, which is bits per parameter. With double quantization the constants are themselves quantized to 8 bits with a second-level constant per 256 of them, giving about bits per parameter. The saving is about bits per parameter.
QuestionA model has 7 billion parameters. How many gigabytes do the 4-bit weights take, ignoring constants? Compare with 16-bit.Show answer
At 0.5 bytes per parameter, bytes, about 3.5 GB. At 2 bytes per parameter, the 16-bit weights take about 14 GB. The ratio is four to one.
QuestionApplied: a team fine-tunes a 13B model with LoRA on only the query and value projections and finds it underperforms full fine-tuning. Using the paper's findings, what would you change first, and why might it help?Show answer
Add LoRA adapters to all linear layers of each transformer block, not only the query and value projections. The paper finds that the number of adapted layers is the most critical LoRA hyperparameter for matching full fine-tuning, and that the rank matters less. The change costs little memory, because adapters are small, so it is a cheap experiment before trying anything heavier.
Sources
- Dettmers, T., Pagnoni, A., Holtzman, A., Zettlemoyer, L. (2023). QLoRA: Efficient Finetuning of Quantized LLMs.
- Hu, E. J., et al. (2021). LoRA: Low-Rank Adaptation of Large Language Models.