Exercises — Parameter-efficient fine-tuning (PEFT)
Reminders you will lean on (all from Parameter-efficient fine-tuning (PEFT)):
Level 1 — Recognition
Exercise 1.1
Which of these does LoRA train, and which does it freeze? (a) the pretrained matrix ; (b) the matrix ; (c) the matrix ; (d) the scaling constant .
Recall Solution
- Frozen: (the giant pretrained weight — never touched).
- Trained: and (the two thin low-rank matrices).
- Fixed hyperparameter (not trained): . You choose it; gradient descent does not learn it.
Why: the whole point of PEFT is to leave alone and only learn a tiny additive correction . See Low-Rank Matrix Factorization for why can be small.
Exercise 1.2
Match each PEFT method to its family: LoRA, BitFit, Prompt tuning, Adapters.
Recall Solution
| Method | Family |
|---|---|
| LoRA | Additive (low-rank update to weights) |
| Adapters | Additive (bottleneck MLP layers) |
| BitFit | Selective (train only bias terms) |
| Prompt tuning | Prompt-based (soft vectors prepended to input) — see Prompt Tuning |
Exercise 1.3
True/False: In QLoRA, the trainable adapters are stored in 4-bit.
Recall Solution
False. Only the frozen base model is loaded in 4-bit. The adapters () stay in higher precision (e.g. 16-bit) so their gradients are meaningful. Quantizing the thing you're learning would destroy the signal you need.
Level 2 — Application
Exercise 2.1
A weight matrix is . You apply LoRA with rank . (a) Give the shapes of and . (b) How many trainable parameters? (c) How many would full need? (d) The saving factor?
Recall Solution
Here (rows), (cols).
- (a) , . ( maps the small rank space back up; squeezes the input down.)
- (b) .
- (c) .
- (d) . 256× fewer parameters.
Exercise 2.2
A transformer has 32 layers. In each layer you apply LoRA () to the and projections only, each of size . Total trainable parameters?
Recall Solution
- Per matrix: (from 2.1).
- Matrices adapted: .
- Total: .
The choice is standard for Transformer Attention — those projections carry most of the task-relevant adaptation.
Exercise 2.3
Fully fine-tuning just those 64 matrices would touch how many parameters, and what percentage of that does LoRA train?
Recall Solution
- Full: .
- Fraction trained: . So LoRA trains about 0.39% of those weights.
Exercise 2.4
You tuned well at . You switch to for more capacity but want the update magnitude unchanged. What ?
Recall Solution
Old scale: . Keep scale at : solve . Why: the raw product tends to grow with ; dividing by decouples "how strong the update is" from "how much capacity it has."
Level 3 — Analysis
Exercise 3.1
At training step 0, LoRA sets and . Show that the forward pass equals the pretrained one, and explain why this design fights Catastrophic Forgetting.
Recall Solution
The update term is . With , the product (a zero matrix), so The tuned model starts identical to the pretrained one. Training only adds corrections from zero, so it never blindly overwrites prior knowledge — it drifts away gently. That gradual, additive departure is exactly what mitigates catastrophic forgetting.
Subtle point: you must not zero both and — then no gradient could flow and would stay forever. One is zero (output side ), one is random (input side ), so gradients are nonzero and learning starts.
Exercise 3.2
Explain why adapters add inference latency but merged LoRA does not. Reference the figure.

Recall Solution
Look at the figure. An adapter (top) inserts a new sequential block between layers: the data must pass through it in series, so it adds real forward-pass time on every token, forever.
LoRA (bottom) computes and and adds them — a parallel branch, not a series one. After training you fold the branch into a single matrix: Now inference runs : one matrix multiply, zero extra ops (red arrow). The extra cost existed only during training.
Exercise 3.3
The rank of is at most . Prove and explain why that caps LoRA's expressiveness.
Recall Solution
has at most rows, so its row space has dimension ; hence . For any product, .
Meaning: LoRA can only produce weight-updates that live in an (at most) -dimensional subspace. If the true task update genuinely needs more directions than , LoRA cannot represent it — you'd need a larger or full fine-tuning. This is the trade-off knob controls.
Level 4 — Synthesis
Exercise 4.1
You must serve 3 tasks {summarize, translate, classify} from one 7B base. The base checkpoint is 14 GB; each LoRA adapter is 8 MB. Compare total storage for (a) full fine-tuning (one 14 GB model per task) vs (b) LoRA. Express the LoRA saving as a percentage of the full-FT storage.
Recall Solution
- (a) Full FT: .
- (b) LoRA: one base + three adapters (using ).
- Full FT in MB: .
- Ratio: . LoRA uses about 33.4% of the storage — and most of that is the single shared base you'd need anyway.
- The marginal cost of each extra task is only 8 MB vs 14 GB — a saving per new task.
This is the "one model, many cheap plug-ins" idea: hot-swap the 8 MB adapter per request; contrast with Full Fine-Tuning which forces a whole new copy per task.
Exercise 4.2
Design decision: a 65B model in 16-bit needs GB just for weights, plus gradients and optimizer state for full FT. You have one 48 GB GPU. Sketch how QLoRA fits, and estimate the frozen-weight footprint in 4-bit.
Recall Solution
- 4-bit base footprint: . This fits in 48 GB with room for activations and the tiny adapters.
- Why it works: the frozen base is only read in the forward pass — 4-bit precision loss there is tolerable. All learning happens in the small 16-bit adapters, so gradients stay precise.
- What flows where: gradients pass through the 4-bit weights (which are dequantized on the fly for the matmul) but only update the 16-bit . No optimizer state is stored for the 65B base — only for the ~millions of adapter params.
- Full FT would need (weights) (Adam state) — impossible on 48 GB. QLoRA's 32.5 GB base makes it feasible.
Exercise 4.3
For the 65B QLoRA run, suppose you apply rank-16 LoRA to in 80 layers, each projection . Total trainable params, and what fraction of 65B is that?
Recall Solution
- Per matrix: .
- Matrices: .
- Total: .
- Fraction of 65B: . You fine-tune a 65B model by training about 0.06% of its size.
Level 5 — Mastery
Exercise 5.1 (Edge case: )
What does LoRA reduce to if ? Is that ever useful?
Recall Solution
With the matrices and are empty; their product is the zero matrix . So — the frozen model, unchanged, with nothing trainable. It is the degenerate "no adaptation" baseline: useful only as a control to confirm that any gain you measure truly comes from the LoRA update, not from other training-loop effects.
Exercise 5.2 (Merging is exact)
Prove that after merging, computed by is bit-for-bit the same operation as the two-branch LoRA (ignoring floating-point rounding).
Recall Solution
Two-branch: . By the distributive law of matrix multiplication over addition, The associativity lets us precompute once and fold it into . So merged inference is algebraically identical — that's why it can be lossless and latency-free.
Exercise 5.3 (When merging is NOT free)
Give a concrete deployment where you should not merge, even though merging removes latency.
Recall Solution
Multi-task hot-swapping. If one server answers requests for summarize, translate, and classify, you keep the single base in memory and swap the 8 MB adapter per request. If you merged, you'd need three separate full matrices (each the size of the base) resident — losing the entire storage/memory advantage of Exercise 4.1. So: merge for single-task, low-latency serving; keep unmerged for multi-task hot-swap.
Exercise 5.4 (Rank vs data — the overfitting cliff)
You have only 500 training examples. Would you pick or ? Justify using the rank–capacity argument.
Recall Solution
Pick . Larger gives a higher-capacity update that can memorize a tiny dataset (overfit), and it fights LoRA's founding assumption that the true update is low intrinsic dimension. With only 500 examples there's little signal to fill 256 directions — most would fit noise. Empirically returns saturate by –; beyond that you spend memory to lose generalization. More rank is not always better.
Active recall
Recall Quick self-quiz
Trainable params of one LoRA layer? ::: . Saving factor for ? ::: . Why at init? ::: So and the model starts equal to the pretrained one — no forgetting. Why merged LoRA has zero latency? ::: is one matrix; distributivity makes it exact. When should you NOT merge? ::: Multi-task hot-swap serving — keep the base + swap tiny adapters. 4-bit footprint of a 65B base? ::: GB.
Connections
- Parameter-efficient fine-tuning (PEFT) — the parent note these exercises drill.
- Full Fine-Tuning — the costly baseline all savings are measured against.
- Low-Rank Matrix Factorization — why and the rank bound.
- Quantization — the 4-bit trick behind QLoRA (Ex 4.2–4.3).
- Transformer Attention — where LoRA is applied.
- Catastrophic Forgetting — mitigated by zero-init (Ex 3.1).
- Prompt Tuning — the prompt-based PEFT branch (Ex 1.2).