4.3.8 · D5Pretraining & Fine-Tuning LLMs

Question bank — LoRA and QLoRA

1,763 words8 min readBack to topic

Prerequisite ideas you should already own: Matrix Rank and Low-Rank Approximation, Quantization of Neural Networks, Adam Optimizer memory cost, Full Fine-Tuning vs PEFT, Attention Q K V Projections, Adapter Layers.


True or false — justify

LoRA reduces the number of parameters in the model at inference time.
False. After merging, is one full-size matrix (output dim , input dim ) — same size as before. LoRA reduces trainable parameters during fine-tuning, not the model's footprint.
LoRA changes the model's architecture (adds new layers).
False. It injects a low-rank correction into an existing linear layer's weights; unlike Adapter Layers there are no new sequential blocks, and after merging there's literally no trace left.
If genuinely had full rank, LoRA could still represent it exactly.
False. (with of shape and of shape ) has rank at most , so a full-rank update is fundamentally outside its reach — LoRA bets the needed update is low-rank.
Freezing means the pretrained knowledge is discarded during fine-tuning.
False. Frozen means unchanged and fully used on every forward pass; the knowledge is preserved perfectly — only a small correction is added on top.
In QLoRA the model is trained in 4 bits.
False. Only the frozen base is stored in 4-bit; the trainable adapters stay full precision and the base is dequantized to bf16 for each matmul. Nothing that receives a gradient is 4-bit.
Setting keeps the effective update scale constant across all ranks.
True — by definition for every , so the scale is exactly regardless of rank. The separate heuristic instead fixes the scale at ; don't conflate "is the scale constant?" (yes for ) with "which constant should I pick?" (a tuning question).
Because at initialization, LoRA can never learn anything (it's stuck at zero).
False. only makes at step 0. Gradients flow into through (which is nonzero), so immediately moves away from zero on the first update.
You could equally initialize and random to get at start.
True in spirit — either choice gives initially. The convention is , Gaussian; the key requirement is just that the product starts at zero.
Merging LoRA weights is always the right thing to do.
False. Merging gives zero latency for one adapter, but if you serve many task adapters on the same base simultaneously you must keep them unmerged to swap them cheaply.

Spot the error

"7B full fine-tuning needs ~14 GB because that's 7B × 2 bytes."
The 14 GB is just the fp16 weights. Full FT with Adam also needs momentum + variance + fp32 master weights (~12 bytes/param) → ~84 GB. The trap is quoting only weight storage.
"QLoRA's 4-bit base means gradients for the base are computed cheaply in 4-bit."
There are no gradients for the base at all — it's frozen. Gradients exist only for ; the whole point is you never need high-precision gradients for a base you don't update.
"NF4 is better than int4 because it uses more bits."
Both are 4 bits. NF4 wins by placing its 16 levels at the quantiles of a normal distribution, matching where weight values actually cluster — same bit budget, smarter bin placement.
"To double LoRA's capacity, double ."
is a scaling scalar, not capacity. Capacity comes from rank (the width of the waist in , i.e. the number of independent directions). Doubling just scales the same low-rank update up.
"Since is trainable, LoRA can overfit less than full FT because it has fewer parameters."
The reason it overfits less isn't fewer parameters per se — it's that the low-rank constraint restricts the update to a genuinely low-dimensional, task-relevant subspace, blocking noisy high-rank directions.
"Applying LoRA to more matrices (Q, K, V, O, MLP) always beats applying it to just Q, V."
More placement can help but also adds parameters and can hurt; papers often find Q,V alone is a strong sweet spot. It's a tradeoff, not a monotone "more is better."
"Double Quantization quantizes the LoRA adapters a second time."
No — it quantizes the quantization constants (the per-block scales of the frozen base), saving ~0.37 bits/param. The adapters are never quantized.

Why questions

Why must the scaling factor be and not just a plain constant?
As grows, sums more outer-product terms and tends to grow. Tiny numeric sketch: if each term contributes ~magnitude , then rank gives ~ but rank gives ~; dividing by pulls both back to ~, so the learning rate stays valid across ranks.
Why is quantizing the frozen base safe but quantizing weights you're training would be dangerous?
On a frozen weight the 4-bit rounding error is a single fixed offset the adapters cancel. But in training you round every step, and gradient descent accumulates those errors: over steps the drift grows like instead of staying — see the diverging red curve.
Figure — LoRA and QLoRA
Why does LoRA add zero inference latency but Adapter Layers add some?
LoRA's correction is linear in the same layer and merges into one matrix; adapter layers are extra nonlinear blocks in series that must be computed every forward pass and can't be folded away.
Why does starting with make the first gradient step "a pure improvement"?
At step 0 the model output equals the pretrained model exactly, so the loss gradient points purely toward task improvement — not toward undoing random corruption you injected.
Why is the "intrinsic rank" of the update low even though itself is high-rank?
Adapting to one narrow task nudges the model along a few task-relevant directions; the base already encodes general knowledge, so the change needed is a small, structured perturbation, not a full-rank rewrite.
Why do Paged Optimizers help without changing the math of training?
They only relocate optimizer state to CPU RAM during transient GPU memory spikes (e.g., a long sequence), preventing an out-of-memory crash — a memory-management safety net, not an algorithmic change.

Edge cases

What happens to LoRA if you set ?
vanishes ( has shape , has shape ) → permanently. You've frozen the whole model; it's inference-only, no adaptation possible.
What happens as ?
can represent an arbitrary full update, so you recover something like full fine-tuning of that layer — but you've thrown away the parameter savings and re-invited overfitting.
Does LoRA touch the layer's bias vector?
No — standard LoRA adapts only the weight matrix (shape ); the bias (length ) stays frozen and unchanged. If a task truly needs a shifted bias you must unfreeze explicitly (it's cheap: only numbers), but the vanilla recipe leaves it alone, which is why merging is a clean weight-only fold.
If you fine-tune, merge, then want a different task, can you reuse the same merged model?
No — once merged, is baked in and can't be cleanly removed. Keep the base + separate adapters if you need to swap tasks.
Two adapters trained separately on the same base — can you add both merged updates ?
Mathematically you can sum them, but they were each trained assuming the other wasn't present, so their interaction isn't accounted for; results can degrade — it's an approximation, not a guarantee.
What if the base weights are not approximately Gaussian — does NF4 still help?
Less so. NF4's optimality assumes near-normal weights; for a very different distribution its quantile bins are mismatched and a distribution-matched or uniform scheme could do better.
At the very first training step, is the QLoRA base already dequantized?
Yes — every forward pass (including step 0) dequantizes the frozen NF4 base to bf16 for the matmul; the 4-bit form is purely a storage format, not a compute format.

Recall Fast self-test

Cover the answers, run every item once, and flag any where you said "true/false" without a reason — those are the ones the exam (and reality) will punish.