25/31
Part 6 of 6 · What interviewers ask nextLearn and do

QLoRA keeps the frozen weights in 4 bits

Once the layer works, the follow-ups move to memory, quality and serving. Have four answers ready.

Memory for 65 billion frozen weights
16-bit
130 GB
QLoRA
33.5 GB

LoRA drops the gradients and optimizer state for the frozen weights, but the weights themselves still sit in memory at 16 bits. QLoRA (Dettmers et al., 2023) stores them in 4 bits. It backpropagates through the frozen 4-bit model into the LoRA adapters. Three pieces make that work:

  • NF4, a 4-bit NormalFloat type built for weights that are normally distributed.
  • Double quantization, which quantizes the per-block scale constants too.
  • Paged optimizers, which move optimizer state to CPU memory when the GPU runs short.

The weights are stored in 4 bits and turned back into bf16 for each matmul, which is called dequantizing. Only the adapters get weight gradients, and they stay in 16-bit BrainFloat (bf16).

The memory math:

  • With blocks of 64 weights, a 32-bit scale per block adds 0.5 bits per weight.
  • Double quantization cuts that to 0.127 bits.
  • So 65 billion weights at 4.127 bits come to about 33.5 GB, against 130 GB in 16-bit.

That's how QLoRA fine-tunes a 65B parameter model on a single 48GB GPU. Regular 16-bit fine-tuning of it needs more than 780 GB of GPU memory. QLoRA also puts adapters on every linear layer, which is where the all-layers finding in Part 3 comes from.

Predict

A QLoRA adapter learned its correction on top of the dequantized 4-bit weights. Which weights do you merge it into?

Pick an answer above to see the rest