What is QLoRA, and how does it combine 4-bit quantization with LoRA?
Answer
QLoRA (Dettmers et al., 2023) is a fine-tuning recipe that keeps the entire base model frozen in 4-bit precision and trains only LoRA adapters in 16-bit on top of it, so the memory that would have held gradients and optimizer state for billions of parameters simply never gets allocated. During the forward pass each 4-bit weight block is dequantized to bf16 on the fly, used for the matrix multiply, and discarded; the backward pass dequantizes again to propagate gradients through the frozen weights into the adapters, which are the only tensors that receive updates. Three components make the 4-bit base workable: the NF4 data type, which places its 16 levels at quantiles of a normal distribution rather than uniformly, double quantization of the per-block scaling constants, and paged optimizers that offload optimizer state through unified memory when a long-sequence step spikes. The headline result was fine-tuning a 65B model on a single 48 GB GPU while matching 16-bit LoRA quality on instruction-following benchmarks. Note that QLoRA quantizes the frozen base, never the adapters or the gradients, so all learning still happens in bf16.
(1) NF4 (4-bit NormalFloat): pretrained weights within a block are approximately zero-centered Gaussian, so NF4 spaces its levels at quantiles of a standard normal instead of uniformly, which is information-theoretically optimal for that assumption and beats 4-bit float or int at equal bit width.
(2) Blockwise Absmax Scaling: weights are quantized in blocks of 64 with one absmax constant per block, which localizes outliers so a single large weight cannot crush the resolution of an entire tensor.
(3) Double Quantization: those constants are themselves quantized to 8-bit with a second-level fp32 scale per 256 constants, cutting the metadata overhead from 0.5 to about 0.127 bits per parameter (roughly 3 GB on a 65B model).
(4) Only Adapters Train: gradients pass through the frozen 4-bit weights but are stored only for and
, so optimizer state scales with the adapter rank, not with model size.
(5) Paged Optimizers: optimizer states live in NVIDIA unified memory and are paged to host RAM during transient spikes, which is what keeps a 33B or 65B single-GPU run from OOM-ing on a long batch.

Figure 1: One QLoRA linear layer. The NF4 weight and its quantization constants are read-only, the bf16 copy exists only for the duration of the matmul, and the dashed path shows that gradients terminate at the low-rank adapters.
Mathematical Formulation:
Where:
is the layer output and
the bf16 input activation; both stay in 16-bit throughout.
is the frozen base weight stored as NF4 indices, and
is the dequantization that reconstructs a bf16 tile just before the matmul.
indexes the blocks of 64 weights,
is the stored 4-bit code, and
are the fixed NF4 levels, obtained from normal quantiles and rescaled to
with an exact zero.
is the per-block absmax constant; double quantization stores it in 8 bits with one fp32 scale per 256 constants.
and
are the trainable bf16 adapters of rank
(the paper uses
on every linear layer), scaled by
;
starts at zero so the layer initially reproduces the quantized base model.
is the effective storage cost per base parameter: 4 bits of payload plus 0.125 bits of 8-bit constants plus 0.002 bits of second-level scales.

Figure 2: Illustrative state memory for a 7B model with rank-64 adapters on all linear layers. LoRA removes the optimizer and gradient bulk, and QLoRA then shrinks the remaining frozen weights from 14 GB to 3.6 GB; activation memory is excluded.
| Aspect | QLoRA (NF4 base) | 16-bit LoRA | Full Fine-Tuning |
|---|---|---|---|
| Base weight storage | NF4, about 4.13 bits per parameter with double quantization | bf16, 16 bits per parameter | bf16 weights plus an fp32 master copy |
| Trainable parameters (7B) | About 160M in bf16 at rank 64 on all linear layers | Identical adapter count | All 7B parameters |
| State memory (7B) | About 6 GB | About 17 GB | About 112 GB, needs sharding across GPUs |
| Step time | Slowest: dequantization runs in both forward and backward | Fastest of the two adapter methods | Highest total compute and communication |
| Instruction-tuning quality | Matches 16-bit LoRA when adapters cover every linear layer | Reference point for adapter tuning | Preferred with very large in-domain corpora or heavy domain shift |
| Deployment | Adapter cannot fold into NF4 losslessly; merge into the 16-bit base, then requantize | Merge into bf16 weights for zero added latency | One merged checkpoint per task |
Leave a Reply