QLoRA — the democratization event
Now snap the two pieces together. LoRA left one stubborn memory item: the frozen base still sits in GPU memory at FP16 — 14 GB for 7B before anything else. Quantization shrinks storage 4×. The obvious question: can you train LoRA adapters on top of a 4-bit base?
QLoRA (Dettmers et al., 2023) proved yes, with quality matching 16-bit LoRA. The recipe:
- Load the base model quantized to 4-bit NF4 — frozen, as always. 7B → ~3.5 GB.
- Attach LoRA adapters in full 16-bit — the trainable parts stay precise.
- During training, each layer's weights are dequantized on the fly for computation (the unzip-compute-discard from Topic 24); gradients flow through the frozen 4-bit base into the adapters. The quantization error never compounds — the imprecise parts never move, and the moving parts are never imprecise.

- Two supporting tricks from the paper: double quantization (the per-block scale factors are themselves quantized — squeezing the metadata) and paged optimizers (optimizer states can spill to CPU RAM during memory spikes instead of crashing — an overflow valve against the OOM errors that end training runs at hour six).
In code, the whole thing is a config object:
import torch
from transformers import AutoModelForCausalLM, BitsAndBytesConfig
bnb = BitsAndBytesConfig(load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_use_double_quant=True,
bnb_4bit_compute_dtype=torch.bfloat16)
model = AutoModelForCausalLM.from_pretrained(
"Qwen/Qwen2.5-7B-Instruct", quantization_config=bnb)
# ...then apply the exact LoraConfig from Topic 23 on topAnd here is the full arc of this lesson in one picture — where the 112 GB went:
The paper's headline demo fine-tuned a 65B model on a single 48 GB GPU — previously a many-GPU-cluster job. The downstream effect was cultural as much as technical: QLoRA is why Hugging Face hosts hundreds of thousands of community fine-tunes, why a student with a free Colab account can specialize a 7B model over a weekend, and why "fine-tune a small open model for the task" became a realistic answer for tiny teams. When you run your first training in the next lesson, it'll be QLoRA under the hood.
One deployment subtlety for the advanced file: merging (Topic 23) gets awkward with QLoRA. Your adapter was trained against the 4-bit base; cleanly merging means dequantize → merge → maybe requantize, and each step shifts things slightly. The practical guidance: either serve exactly what you trained (4-bit base + separate adapter), or merge into a 16-bit base — and whichever artifact you ship, evaluate that exact artifact, not its cousin. A theme you'll recognize: train the way you serve (Topic 15), evaluate what you deploy (Topic 24).
Summary
QLoRA = frozen 4-bit NF4 base + 16-bit LoRA adapters + paged optimizers, with gradients flowing through quantized weights into precise adapters. 7B training in ~6 GB, quality on par with 16-bit LoRA — the technique that democratized fine-tuning.
Mental model
Studying with a shrunken library. The reference books are compressed to pocket size and never edited (4-bit frozen base); your own notebook stays full-sized and precise (16-bit adapters). All the new learning lands in the notebook, so the compression never contaminates it.
Mistakes to avoid
- Assuming 4-bit training means a broken model. The base's small quantization error is static; adapters learn around it. The paper measured parity with 16-bit LoRA — this worry is empirically settled.
- Training against a 4-bit base, then deploying a differently quantized or merged artifact without re-evaluating. Small mismatches, real quality drift.
Exercise
Hardware reality check — your personal cheat sheet from Lesson 2, training edition. For 3B, 8B, 14B, and 32B models, estimate QLoRA training memory (params × 0.5 bytes + ~2–4 GB for adapters, activations, and overhead). Mark which fit: a free Colab T4 (16 GB), your Mac M4's unified memory, a rented 24 GB GPU. You've just priced your own fine-tuning lab. (Note for Mac specifically: the memory fits, and Apple's MLX framework — Module 5 — is how you'd actually use it.)