ML Systems Lab Open interactive version →
Advanced 29 min read fine-tuningLoRAPEFTadaptersLLM

Fine-Tuning Strategies

Full fine-tune, LoRA, prefix tuning, adapter layers — when each applies

Pre-training's own closing flagged the risk: fine-tune too aggressively and you overwrite the knowledge that made the model valuable. This module is about how to make the correction small enough that the risk mostly disappears. You want LLaMA-2 70B to answer internal questions in your company's tone and format. The brute-force way — full fine-tuning — means updating *all 70 billion* weights. Just the bookkeeping (16-bit weights and gradients, plus Adam's two 32-bit running averages) needs roughly 12 bytes per parameter — about 840 GB of GPU memory, a dozen top-end GPUs, days of training, and a real risk of overwriting the very abilities that made the model good. For most teams that is a non-starter.

But look at what actually has to change. Teaching a 70-billion-parameter model your company's tone doesn't require touching what it already knows about grammar, facts, or reasoning — it requires a small, structured *correction* layered on top of what's already there. Picture a sticky note stuck on one page of a huge textbook: you don't retype the page, you leave a small note in the margin, and reading proceeds normally except wherever the note applies. If the correction a task genuinely needs is small and structured, the note can be tiny compared to the page it corrects.


Making that concrete

Take a representative 4096×4096 weight matrix — a typical attention-projection size at this scale — 16.7 million numbers. A full update to it would itself be a 4096×4096 matrix: 16.7 million more numbers to learn from your comparatively tiny fine-tuning dataset. But suppose the *correction* that matrix needs can be described by a much narrower structure — the product of two skinny matrices, one 4096×8 and one 8×4096. Multiply them out and you get a full 4096×4096 update, but you only had to *learn* the two skinny factors: 4096×8 + 8×4096 = 65,536 numbers — a 99.6% cut from 16.7 million.

That is the whole trick behind LoRA (Low-Rank Adaptation): freeze the giant base model exactly as it is, and train only the two skinny "sticky-note" matrices, B and A. Once trained, the tiny update merges *straight back* into the original weights — new W = W + B·A — so the deployed model is exactly the same size and speed as the original: zero extra inference cost. That mergeability is LoRA's edge over "adapter" approaches that bolt on permanent extra modules the model must run through forever.


The next crisis: the frozen base is still huge

LoRA already cuts *trainable* parameters by 99.6%. But the frozen base model still has to sit in GPU memory at full size — 70B parameters at 16-bit precision is still about 140GB, more than any single GPU holds. Can the frozen part be shrunk too, without hurting the tiny trainable part's accuracy?

Squash the frozen base down to 4-bit numbers (from ~140GB to ~35GB), and train the small LoRA matrices in full precision on top. Because the base weights are never actually updated — all the learning happens in the little adapters — the rounding error from the 4-bit squashing barely matters to the final result. This combination — a 4-bit frozen base plus full-precision LoRA matrices — is what's called QLoRA, and it is what lets a 70B fine-tune fit on a single 80GB GPU, at near-full-fine-tuning quality.


One distinction worth nailing down

People sometimes call "train a fresh classifier on top of a frozen model" *fine-tuning* — it is not, it is feature extraction, and it can only *re-sort* the representations the model already has. True fine-tuning (including LoRA) actually changes the model's effective weights, which is what lets it learn genuinely new behaviour — a new tone, a new format, a new skill. If you need the model to *do* something new, you need real fine-tuning; if you only need to classify what it already understands, feature extraction is enough.

Key points

Takeaway

Task-specific weight updates have low intrinsic rank — LoRA exploits this to fine-tune a 70B model while training only a small fraction of its total parameters (typically well under 1% across the whole model; a single 4096×4096 matrix's own update is a 99.6% cut, from 16.7M to 65K trainable numbers), and because BA merges directly into W after training, the deployed model is byte-for-byte identical to the base model with zero inference overhead.

Recap

Check your understanding

Q1. You fine-tune a pre-trained BERT model on a sentiment classification task with 500 labeled examples. What are the risks, and what techniques do you use? Select the TWO correct statements.

Q2. LoRA (Low-Rank Adaptation) decomposes weight updates into low-rank matrices: ΔW = BA where B ∈ ℝ^{d×r} and A ∈ ℝ^{r×k}. For d=k=1024 and r=8, how many parameters does LoRA add vs full fine-tuning? Why does this work?

Q3. When does RLHF (Reinforcement Learning from Human Feedback) improve a language model beyond standard fine-tuning? What is the reward model, and what can go wrong?

Try it interactively

ML Systems Lab is a free interview-prep platform for ML engineers — work through the full interactive module, quizzes, and drills.

Open ML Systems Lab →