LoRA and QLoRA: Training Small Adapters
You'll learn to
- -Explain LoRA as a frozen weight matrix plus a small low-rank update
- -Compute how many values a LoRA adapter trains compared with the full matrix
- -Explain what QLoRA adds, and estimate memory for full fine-tuning, LoRA and QLoRA
- -Say why an adapter can be merged into the base model or swapped per customer
Tip: the highlighter is on - just select any text below to mark it. Use the highlighter button up top to change color or turn it off. Highlights are saved on this device only. Log in to save them to your account instead.
Updating every weight of a large model is expensive. A model with 8 billion weights needs far more memory to train than to run, and every customer who wants their own tuned version would need a full copy of the model. LoRA, short for low-rank adaptation, changes the question: instead of rewriting the weights, leave them frozen and learn a small correction to add on top.
An Analogy: Sticky Notes in a Textbook
Suppose a textbook has to be adapted for a new course. You could reprint the whole book. Or you could leave the book untouched and add a thin set of sticky notes on the pages that matter. The notes are tiny compared with the book, you can keep a different set for each course, and you can peel them off to get the original back. The book is the frozen weight matrix and the notes are the LoRA adapter.
How LoRA Works
A weight matrix W has d_out rows and d_in columns. LoRA does not change W. It learns two thin matrices, B with d_out rows and r columns, and A with r rows and d_in columns, where the rank r is small, such as 8 or 16. The model then uses W plus a scaled product of B and A. Training only updates A and B. The authors report that for GPT-3 175B this cut trainable parameters by 10,000 times and GPU memory by 3 times compared with fine-tuning with Adam, with quality on par or better on the models they tested.
A single 4096 by 4096 matrix has about 16.8 million values. A rank 16 adapter trains 131,072 of them, 0.78 percent of the matrix. Put adapters on the query and value matrices of all 32 layers of an 8B model and that is 8.4 million trainable values, about 0.1 percent of the model. The memory lines count only the model states, the weights plus gradients and optimizer states, and leave out activations. Full fine-tuning with mixed precision Adam needs 16 bytes per weight, 128.0 GB. LoRA keeps the base at 2 bytes per weight and trains only the adapter, 16.1 GB. QLoRA stores the frozen base in 4 bits and lands near 4.6 GB.
What QLoRA Adds
QLoRA keeps the LoRA idea and shrinks the frozen base to 4 bits, then trains the adapters by passing gradients back through the quantized weights. Its paper introduces a 4-bit data type called NormalFloat, double quantization to compress the scaling constants, and paged optimizers to survive memory spikes. The result it reports is fine-tuning a 65 billion parameter model on a single 48 GB GPU while keeping the quality of full 16-bit fine-tuning.
The last part of the output shows the quantization idea on one block of eight weights: divide by a scale, round to a small integer, and multiply back. The codes are between minus 7 and 7, and the worst rounding error here is 0.06. Real QLoRA uses non-uniform NormalFloat levels, so treat this as the shape of the idea, not the recipe.
That small check explains a design choice. B starts at zero, so the effective weight equals the base weight before training, and the model begins unchanged and only drifts as B and A learn. It also explains deployment. You can merge B times A into W once and serve with no extra latency, or keep the base model loaded and swap a different small adapter per customer.
Rank, scaling and which matrices to adapt are choices to test, not defaults to trust. Too low a rank under-fits the task, and adapters on more matrices cost more. Compare each setting on the same held-out set.
Interview Signal is part of Pro
See a real weak answer next to a real strong one for this exact topic.
Quiz is part of Pro
Test what you just read with a short quiz, and bank the XP.
Discussion0
Join the Discussion
Sign in to leave comments, reply to others, or like insights.
No comments yet. Be the first to start the thread!