QLoRA › The Memory Bottleneck
Language AI HandbookAll chapters QLoRA › The Memory BottleneckOne section · Sections in this chapter2 / 15 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Before examining QLoRA's solutions, let's understand exactly where memory goes during fine-tuning. When training with standard LoRA, GPU memory is consumed by several components, each adding to the overall memory footprint in different ways. Understanding this breakdown reveals why reducing trainable parameters is insufficient to make large models accessible. Trainable parameters are only part of the problem: the model itself, even when entirely frozen, must occupy GPU memory continuously throughout training.
Think of GPU memory as a workspace on your desk. Everything you're actively using must fit on the desk at once. You can't just put the things you're currently writing on the desk; you need all your reference books open and ready too, because constantly retrieving books from a distant shelf would slow you down to a crawl. The base model weights are like those reference books: you need them constantly, even when you aren't changing them, because every forward pass requires consulting every layer's weights to produce the next output. The size of those reference materials places a hard lower bound on how large your desk needs to be.
The key insight is that memory constraints and compute constraints are distinct. A GPU might have plenty of computational power to process a 70B model quickly, but if the weights don't fit in VRAM, the computation simply cannot happen regardless of processing speed. This is the basic asymmetry that QLoRA exploits: we can afford to compress the storage of frozen weights aggressively, because what matters for computation is that we can quickly decompress them at the moment of use, not that they permanently occupy space in full precision.
The base model weights dominate memory for large models. Even frozen, these weights must reside in GPU memory for forward passes. The reason is straightforward: every forward pass requires matrix multiplications between activations and weights, and these operations happen on the GPU. Moving weights from CPU to GPU for each forward pass would create an unacceptable bottleneck. In FP16, each parameter requires 2 bytes of storage:
where:
- : the total number of parameters in the base model
- : the size in bytes of a single parameter in half-precision (FP16 or BF16)
For a 7B parameter model, that's 14 GB. For a 70B model, that's 140 GB. These numbers represent a hard floor on memory requirements regardless of any other optimizations we might apply to the training process.
LoRA adapter weights are relatively small. With typical settings (rank 8-64 targeting attention layers), the adapters constitute roughly 0.1-1% of base model parameters. This is precisely what makes LoRA attractive: the trainable component is tiny compared to the base model.
Gradients are only computed for LoRA parameters during backpropagation, since the base model is frozen. This is LoRA's key memory advantage. In full fine-tuning, gradients for every parameter must be stored, effectively doubling the memory requirement during training. LoRA eliminates this cost for the large majority of parameters.
Optimizer states for Adam-based optimizers store momentum and variance estimates for each trainable parameter. In FP32, this requires 8 bytes per trainable parameter (4 for momentum, 4 for variance). Again, because LoRA only trains a small number of parameters, this cost remains manageable.
Activations must be stored during the forward pass for gradient computation during backpropagation. This scales with batch size and sequence length. Gradient checkpointing can reduce this cost by recomputing activations during the backward pass, trading computation for memory.
The bottleneck is clear: even with LoRA's efficient training, the base model's frozen weights consume enormous memory. QLoRA directly attacks this by storing those weights in 4-bit precision, a 4× reduction compared to FP16. This insight, that we can dramatically compress the frozen weights without harming the training process, is the foundation of the entire QLoRA approach.