QLoRA memory layout, byte by byte
QLoRA's contribution is an accounting trick plus two engineering details: NF4 quantization matched to the weight distribution, and paged optimizers that spill optimizer state to CPU RAM on memory spikes.
NF4 + Double Quantization
NormalFloat4 matches the empirical distribution of trained weights better than uniform int4. Quantizing the quantization constants saves ~0.4 bits/param.
Paged Optimizers
NVIDIA unified memory lets AdamW's moments page between GPU and CPU RAM, absorbing the activation-memory spikes of long sequences.
The Ledger
4-bit base + bf16 adapters + fp32 optimizer moments for adapters only. Everything big is frozen; everything trainable is tiny.
7B model: full fine-tune ≈ 112 GB (bf16 weights, bf16 grads, fp32 Adam moments and master copy). QLoRA ≈ 3.9 GB base + <2 GB adapters — a 20× reduction.
- Gradient checkpointing plus QLoRA is what makes 13B-class fine-tunes fit on 16–24GB cards.
- Beware merged-precision loss: merging bf16 adapters into an NF4 base, then dequantizing, can lose a little quality — merge into a bf16 copy for deployment.