How much GPU memory do model states take when fine-tuning a -billion-parameter model with mixed-precision Adam under (a) full fine-tuning, (b) LoRA with million trainable adapter parameters on an fp16 base, and (c) QLoRA with a -bit NormalFloat base? How do NF4, double quantisation and paged optimisers work, and what is the trade-off?
Sequence models and transformers, Parameter-efficient fine-tuning
Level L3 Intermediate. Length Medium. Nature Mat Mathematical.
What's being asked
Whether you can compare the model-state memory footprint of full fine-tuning, LoRA (Low-Rank Adaptation) and QLoRA (Quantised Low-Rank Adaptation), and explain the three mechanisms that make QLoRA work.
Key idea
Full fine-tuning stores bytes per parameter across all billion weights (). LoRA freezes the base weights in fp16 () and trains only small low-rank adapters (), while QLoRA compresses the frozen base further to -bit NormalFloat ( plus small quantisation constants), bringing model states down to roughly .
Steps
- Full fine-tuning with mixed-precision Adam: every parameter needs ( fp16, 16-bit floating point, weight fp16 gradient fp32, 32-bit floating point, master weight for Adam moments ). For parameters, model states require (using ).
- LoRA on a frozen fp16 (or bf16, 16-bit brain floating point) base: the billion base weights have no gradients or optimiser states, taking . With trainable adapter parameters (counting across adapted layers, covered in LoRA parameter-count questions), adapter states take , for a total of .
- QLoRA with a -bit NF4 (4-bit NormalFloat) base: storing frozen weights at bits () per parameter takes . Blockwise quantisation constants add small overhead (reduced to by double quantisation below), plus for the 16-bit adapter states, giving roughly total.
- Note excluded activations: these totals count model states only. Activation memory (saved intermediate tensors for backpropagation) grows with batch size and sequence length and often needs gradient checkpointing on single GPUs (graphics processing units).
- Explain QLoRA's three techniques: (1) NF4 places its quantisation levels (approximately) at equal-probability quantiles of a standard normal distribution , matching pretrained weight distributions better than uniform int4 (-bit integers); (2) double quantisation quantises the per-block fp32 scaling constants themselves (e.g. into -bit floats in blocks of ), cutting constant overhead from ( on 7B) to (); (3) paged optimisers use NVIDIA unified memory to page optimiser states between GPU VRAM (video memory) and CPU RAM (host memory) during activation memory spikes.
- State the trade-off: when adapters are applied to all linear layers, QLoRA nearly matches 16-bit LoRA and full fine-tuning accuracy, at the cost of slower training throughput because -bit base weights must be dequantised to bf16/fp16 on the fly during each forward and backward pass.
Common mistakes
- Thinking QLoRA trains in -bit arithmetic; the base weights are stored in -bit NF4 and dequantised to 16-bit (bf16/fp16) for matrix multiplies, while adapters are stored and updated in 16-bit/32-bit precision.
- Forgetting activation memory and thinking a QLoRA footprint means long-sequence training cannot run out of memory on an GPU.
- Applying LoRA or QLoRA adapters only to query and value projections; QLoRA showed that adapting all linear transformer layers (including MLP, multilayer perceptron, blocks) is important to match full fine-tuning quality.
How long your answer should be
3–4 minutes; give the three GB totals, explain NF4, double quantisation and paged optimisers, and note activations and speed trade-offs.
Read this
Previous in Sequence models and transformers: In an encoder–decoder transformer with and 8 heads, a decoder layer cross-attends to an encoder output of length while it has target tokens. What are the shapes of , and and of the score matrix, which projections cost the most, and why does cross-attention need no causal mask?
Next in Sequence models and transformers: Why is autoregressive LLM decoding at batch size memory-bandwidth bound? For a -billion-parameter fp16 model () on a GPU with memory bandwidth and of fp16 compute, what is the upper bound on tokens/s at batch size , what is the arithmetic intensity, and near what batch size does decoding reach the compute ridge point?