QLoRA and Quantized Fine-Tuning
QLoRA fine-tunes huge language models on a single ordinary GPU by freezing and compressing the base model down to 4-bit precision, then training only a tiny set of added low-rank adapter weights in full precision on top of it.
Prerequisites: Instruction Tuning and Supervised Fine-Tuning, Transfer Learning and Fine-Tuning
Fine-tuning a large language model the ordinary way means updating every parameter, and standard training keeps not just weights but gradients and optimiser state (for Adam, two extra numbers per weight) in memory at full precision — for a 65-billion-parameter model, that's well over 780 GB, far beyond any single consumer or most enterprise GPUs. QLoRA makes fine-tuning this large model possible on a single 48 GB GPU by combining two ideas that together cut memory by roughly two orders of magnitude: quantization (storing the frozen base model at much lower numerical precision) and LoRA (training only a tiny number of newly added parameters, never touching the original weights).
The analogy: annotating a reference book without rewriting it
Imagine adapting a 1,000-page reference book for a new audience. One approach is rewriting the entire book — expensive, and you need the full, high-resolution original open the whole time. QLoRA's approach is to photocopy the book at reduced resolution (still readable, just compressed — quantization, applied to the frozen base weights) and write a small set of margin notes and sticky inserts (a handful of new, small trainable matrices — LoRA) that redirect the content for the new audience, without reprinting the original pages. The reduced-resolution copy stays fixed; only the sticky notes get rewritten during training, tiny compared to the book itself.
The two mechanisms combined
4-bit quantization of the frozen base model. Every weight in the pretrained model is compressed from 16-bit floating point down to a specialised 4-bit format (QLoRA introduces "NF4," a format tuned for the roughly-normal distribution of trained neural network weights), cutting the base model's memory footprint by about 4×. These weights are frozen — never updated — so precision loss here only affects the starting point, not the ability to learn.
LoRA adapters, trained in higher precision. For selected weight matrices (typically the attention projections), LoRA adds a small trainable update , where is and is , with rank chosen far smaller than (commonly to ):
In words: the model's effective weight is the frozen, compressed original plus a small correction built from two skinny matrices and — only and ever receive gradient updates, and because , they contain a tiny fraction of the parameters itself has.
Worked example 1: counting trainable parameters
For of size (about 16.8 million parameters) and rank : is and is , together parameters — about 0.78% of the original matrix. Applied across a 65-billion-parameter model's attention projections, LoRA typically trains well under 1% of total parameters, while the frozen 4-bit base still needs forward and backward passes through it, just at drastically reduced memory.
Worked example 2: memory budget comparison
For a 65B-parameter model: full 16-bit fine-tuning needs roughly GB for weights, plus gradients (another 130 GB) plus Adam state (~260 GB) — over 500 GB total, requiring multiple high-end GPUs.
QLoRA: base weights at 4-bit GB, frozen (no gradient or optimiser state needed), plus LoRA parameters at 16-bit — under 1% of 65B, well under 1 GB combined. Total: roughly 33–36 GB, comfortably inside a single 48 GB GPU — the paper's actual reported result, where standard fine-tuning would need over a dozen GPUs.
| Approach | Approx. memory |
|---|---|
| Full 16-bit fine-tuning, 65B model | ~520 GB |
| QLoRA (4-bit frozen base + LoRA) | ~35 GB |
frozen, 4-bit
Trainable parameter count as a fraction of the full matrix shrinks steeply as rank falls relative to dimension — a curve of this shape — which is why even a modest rank like 16 or 32 keeps the adapter tiny relative to a multi-thousand-dimension weight matrix.
QLoRA fine-tunes a large model by freezing and compressing the entire base model to 4-bit precision (so it never needs gradients or optimiser state) and training only small, added low-rank adapter matrices in full precision — combining quantization's memory savings on the frozen part with LoRA's parameter savings on the trained part.
What this means in practice
QLoRA (and LoRA more broadly) made fine-tuning frontier-scale open models accessible outside large labs, underlying most of the "custom fine-tuned model" ecosystem — a quant team can fine-tune a large open model on a single workstation GPU, storing only small adapter weights per task, and swap adapters onto the same frozen base for different uses without duplicating the multi-gigabyte base model.
Quantizing the frozen base model to 4-bit is safe because those weights are never updated by gradient descent — but naively trying to fine-tune weights directly at 4-bit precision (updating the low-precision weights themselves) degrades badly, because gradient updates need much finer numerical resolution than 4 bits can represent. QLoRA's key design choice is keeping the trainable path (the LoRA adapters) at full precision throughout, and only the untouched, frozen weights are ever compressed.
Practice
- For a weight matrix and LoRA rank , how many trainable parameters does the adapter add, and what fraction of the original matrix's parameter count is that?
- Why does freezing the base model's weights make it safe to store them at much lower numerical precision than the parameters that are actually being trained?
Related concepts
Practice in interviews
Further reading
- Dettmers, Pagnoni, Holtzman & Zettlemoyer, QLoRA: Efficient Finetuning of Quantized LLMs (2023)
- Hu et al., LoRA: Low-Rank Adaptation of Large Language Models (2021)