Simple Algorithm
Deep Learning · Emergence · 28 min

Low-Rank Adaptation in Depth

Intrinsic dimension, LoRA’s design choices and fine-tuning quantized models.

LoRA freezes the model and trains two thin matrices per weight, and on GPT-3 a rank of one was enough for some tasks. Why should such small updates work, what do they actually learn, how should they be scaled and trained, and what do they give up? This lesson goes from the intrinsic dimension of fine-tuning through LoRA's design choices and its successors to fine-tuning a 4-bit model with QLoRA, and ends with the evidence that LoRA learns less and forgets less.

What you’ll learn

  • Define the intrinsic dimension of fine-tuning, interpret its measurements, and state the generalization bound built on it.
  • Derive LoRA's gradients at initialization and justify its design choices: zero-initialized BB, the α/r\alpha/r factor, which matrices to adapt and how small the rank can be.
  • Explain rank-stabilized scaling, separate learning rates for AA and BB, magnitude–direction decomposition and adaptive ranks.
  • Compute the memory budget of QLoRA's 4-bit NormalFloat weights with double quantization.
  • Summarize what LoRA learns and forgets compared with full fine-tuning, including intruder dimensions.

How many dimensions does fine-tuning need?

Li, Farkhoor, Liu & Yosinski (2018) asked how many directions training really needs: train only dd coordinates ϑ∈Rd\boldsymbol\vartheta\in\R^d in a fixed random subspace, θ=θ0+Pϑ\boldsymbol\theta=\boldsymbol\theta_0+P\boldsymbol\vartheta, and find the smallest dd that reaches 90% of full performance (Training in a Tiny Subspace covers training from scratch). Aghajanyan, Gupta & Zettlemoyer (2021) applied the idea to fine-tuning pretrained language models, with θ0\boldsymbol\theta_0 the pretrained weights and PP a fast structured random projection (the Fastfood transform). Their structure-aware variant spends a few of the dd coordinates on one scale per layer, θi=θ0,i+λiPiϑ\boldsymbol\theta_i=\boldsymbol\theta_{0,i}+\lambda_iP_i\boldsymbol\vartheta.

Modeld90d_{90} on MRPCd90d_{90} on QQP
BERT-Base1,6088,030
BERT-Large1,0371,200
RoBERTa-Base896896
RoBERTa-Large207774
d90d_{90} is the smallest subspace dimension reaching 90% of full fine-tuning's score (structure-aware version). About 200 parameters, out of some 355 million in RoBERTa-Large, suffice for the MRPC paraphrase task.

Two trends stood out. Over the checkpoints of a RoBERTa pretraining run, the intrinsic dimension of downstream tasks fell steadily, although pretraining never saw those tasks: in their words, "pre-training implicitly minimizes intrinsic dimension". And larger models tended to have lower intrinsic dimension after a fixed number of pretraining updates. They also turned the measurement into a compression bound: a model fine-tuned in a dd-dimensional subspace on mm examples has a generalization gap of order d/m\sqrt{d/m}, independent of the full parameter count. The bound applies to subspace training itself; ordinary fine-tuning by SGD is not shown to stay in such a subspace.

Think first If 200 random directions suffice, why does LoRA learn its low-rank factors instead of using a random projection?

Random subspaces are a measuring device, not an efficient method: to reach full performance they need far more than d90d_{90} dimensions, and the projection must be recomputed in every forward pass. LoRA keeps the low-dimensional spirit but learns the subspace, with structure that matches the network: one low-rank factor pair per weight matrix, which costs an extra matrix product during training and nothing at inference once merged.

LoRA’s design, derived

For a frozen weight W0∈Rd×kW_0\in\R^{d\times k}, LoRA (Hu et al., 2022) computes h=W0x+γr BA x\mathbf h=W_0\mathbf x+\gamma_r\,BA\,\mathbf x with B∈Rd×rB\in\R^{d\times r}, A∈Rr×kA\in\R^{r\times k} and a scaling factor γr=α/r\gamma_r=\alpha/r. AA starts as a random Gaussian matrix and BB at zero.

DerivationGradients at initialization
  1. ∂L∂B=γr g (Ax)⊤,∂L∂A=γr B⊤g x⊤\frac{\partial\loss}{\partial B}=\gamma_r\,\mathbf g\,(A\mathbf x)^\top,\qquad\frac{\partial\loss}{\partial A}=\gamma_r\,B^\top\mathbf g\,\mathbf x^\top

    Let g=∂L/∂h\mathbf g=\partial\loss/\partial\mathbf h be the gradient arriving at the layer's output for one example. The adapter's output is γrB(Ax)\gamma_rB(A\mathbf x), so by the chain rule

  2. B=0 ⟹ ∂L∂A=0,∂L∂B=γr g (Ax)⊤≠0B=0\ \Longrightarrow\ \frac{\partial\loss}{\partial A}=0,\qquad\frac{\partial\loss}{\partial B}=\gamma_r\,\mathbf g\,(A\mathbf x)^\top\ne0

    With B=0B=0 the model starts exactly at the pretrained one, and only BB moves on the first step, in the directions AxA\mathbf x picked by the random projection. AA starts moving once BB is nonzero. Initializing both at zero would leave both gradients zero forever; initializing both randomly would perturb the pretrained model at step 0.

  3. Why α/r\alpha/r? Hu et al. note that when optimizing with Adam and a suitably scaled initialization, "tuning α is roughly the same as tuning the learning rate", so they set α\alpha to the first rr they try and leave it, which lets rr be changed without retuning the learning rate, at least for small ranks. The next step shows that this choice is not stable for large rr.

Which matrices, which rank. On GPT-3 (175 billion parameters) with a fixed budget of 18 million trainable parameters, putting it all into WQW_Q or WKW_K at rank 8 did markedly worse than spreading it: WQW_Q and WVW_V together at rank 4 (73.7% on WikiSQL, 91.3% on MultiNLI) and all four attention matrices at rank 2 (73.7%, 91.7%) gave the best results. Applied to WQW_Q and WVW_V, a rank as small as 1 sufficed on those datasets, with the authors' caveat that tasks far from the pretraining data, such as a new language, may need more. Freezing W0W_0 also removes its gradients and optimizer state: with r=4r=4 on WQW_Q and WVW_V, training memory for GPT-3 fell from 1.2 TB to 350 GB, and a task's checkpoint from 350 GB to 35 MB.

What the update learns. Comparing the learned subspaces at ranks 8 and 64, only the top direction or so was shared, which suggests the remaining directions mostly carry noise. Projecting WQW_Q onto the singular directions of its update ΔWQ\Delta W_Q (rank 4, layer 48) gave a Frobenius norm of 0.320.32, against 21.6721.67 for WQW_Q's own top directions and 0.020.02 for random ones: the update is correlated with WQW_Q but does not reinforce its dominant directions. With ∥ΔWQ∥F=6.91\norm{\Delta W_Q}_F=6.91, it amplifies the directions it picks by a factor of about 6.91/0.32≈21.56.91/0.32\approx21.5. Hu et al.'s reading: LoRA amplifies features that pretraining learned but did not emphasize.

Predict before you look

LoRA with rank r=16r=16 adapts a feed-forward weight matrix of shape 4096×11,0084096\times11{,}008 (the shape used in LLaMA-7B). How many parameters does it train for this one matrix, in thousands?

Show the answer

241.7 thousand

r(d+k)=16×(4096+11,008)=16×15,104=241,664r(d+k)=16\times(4096+11{,}008)=16\times15{,}104=241{,}664, against 4096×11,008≈45.14096\times11{,}008\approx45.1 million for the full matrix: about 0.54%0.54\%. For a square 4096×40964096\times4096 matrix at r=8r=8 it would be 65,53665{,}536 against 16.816.8 million, about 0.39%0.39\%.

Scaling, learning rates and decompositions

With γr=α/r\gamma_r=\alpha/r, practitioners found that raising the rank often did not help, as if the extra directions went unused. Kalajdzievski (2023) traced this to the scaling factor.

A one-step calculation shows the mechanism.

DerivationWhy the factor should be α/√r (sketch)
  1. γr B1Ax=−η γr2 ∥Ax∥2 g\gamma_r\,B_1A\mathbf x=-\eta\,\gamma_r^2\,\norm{A\mathbf x}^2\,\mathbf g

    Start from B=0B=0 and take one gradient step of size η\eta on a single example. From the gradient above, B1=−ηγr g (Ax)⊤B_1=-\eta\gamma_r\,\mathbf g\,(A\mathbf x)^\top, so the adapter's new output on that input is

  2. E∥Ax∥2=r σA2∥x∥2⟹update size ∝ γr2 r\E\norm{A\mathbf x}^2=r\,\sigma_A^2\norm{\mathbf x}^2\quad\Longrightarrow\quad\text{update size}\ \propto\ \gamma_r^2\,r

    AxA\mathbf x has rr coordinates, each a random combination of the input with fixed variance, so ∥Ax∥2\norm{A\mathbf x}^2 grows in proportion to rr:

  3. γr=αr: ∝α2rγr=αr: ∝α2\gamma_r=\frac\alpha r:\ \propto\frac{\alpha^2}r\qquad\qquad\gamma_r=\frac\alpha{\sqrt r}:\ \propto\alpha^2

    With γr=α/r\gamma_r=\alpha/r the update shrinks like 1/r1/r: higher ranks learn more slowly, which wipes out their benefit. With γr=α/r\gamma_r=\alpha/\sqrt r it is independent of rr, as the theorem requires along the whole trajectory: rank-stabilized LoRA (rsLoRA), which lets extra rank trade training compute for accuracy at no inference cost. (The theorem is proved for SGD; the paper's main experiments use AdamW, with a separate check under SGD.)

VariantChange to LoRAMotivation and reported effect
rsLoRA (Kalajdzievski, 2023)scaling α/r\alpha/\sqrt r instead of α/r\alpha/rkeeps learning from slowing down at higher ranks
LoRA+ (Hayou, Ghosh & Yu, 2024)a larger learning rate for BB than for AA, ηB=ληA\eta_B=\lambda\eta_A with λ≫1\lambda\gg1a width-scaling analysis shows equal rates are suboptimal for wide models; up to about 2×2\times faster fine-tuning and 1–2% better results
DoRA (Liu et al., 2024)W′=m⊙W0+BA∥W0+BA∥cW'=\mathbf m\odot\dfrac{W_0+BA}{\norm{W_0+BA}_c}: a trainable magnitude per column, with LoRA updating only the direction (∥⋅∥c\norm{\cdot}_c is the norm of each column)brings LoRA's pattern of magnitude and direction changes closer to full fine-tuning's; still mergeable, so no inference overhead
AdaLoRA (Zhang et al., 2023)the update in SVD form PΛQP\Lambda Q, pruning singular values by an importance scoremoves the rank budget to the matrices and layers that need it
All four keep the frozen base and a low-rank update. Their reported gains are empirical and depend on the model and task; none has a guarantee.

Fine-tuning a 4-bit model: QLoRA

LoRA removes the optimizer state of the frozen weights, but the weights themselves still have to sit in memory: 130 GB for a 65-billion-parameter model in 16-bit precision. QLoRA (Dettmers, Pagnoni, Holtzman & Zettlemoyer, 2023) stores the frozen base in 4 bits and backpropagates through it into LoRA adapters. Three ideas make it work:

  • 4-bit NormalFloat (NF4). Pretrained weights are roughly normally distributed, so the 16 levels are placed at quantiles of a standard normal, rescaled to [−1,1][-1,1]; the two halves are built separately so that zero is exact, giving 7 negative levels, zero and 8 positive levels. Each block of 64 weights is divided by its largest absolute value before quantization. The authors call NF4 "information theoretically optimal for normally distributed weights", since each level is then used about equally often.
  • Double quantization. The per-block scales are themselves quantized, to 8-bit floats in blocks of 256, so their overhead drops from 32/64=0.532/64=0.5 bits per parameter to 8/64+32/(64⋅256)≈0.1278/64+32/(64\cdot256)\approx0.127 bits.
  • Paged optimizers. Optimizer states live in unified memory and move to CPU RAM during memory spikes, such as long sequences with gradient checkpointing.

For each matrix multiplication the 4-bit weights are dequantized to BF16 and multiplied in 16-bit; only the adapters receive gradients. Adapters on all linear layers were needed to match 16-bit full fine-tuning; adapting only the query and value projections, as in the original LoRA, was not enough for large models. The paper's headline: fine-tuning a 65-billion-parameter model on a single 48 GB GPU "while preserving full 16-bit finetuning task performance".

Predict before you look

How many gigabytes do the frozen weights of a 65-billion-parameter model take in QLoRA's format, counting 4 bits per weight plus the double-quantized constants (≈0.127\approx0.127 bits per weight)? Use 1 GB=1091\text{ GB}=10^9 bytes.

Show the answer

33.5 GB

65×109×4.127/8≈33.5×10965\times10^9\times4.127/8\approx33.5\times10^9 bytes: 32.532.5 GB of 4-bit weights plus about 1.01.0 GB of constants (single-level 32-bit constants would have taken about 4.14.1 GB, so double quantization saves about 33 GB). That leaves room on a 48 GB card for the adapters, their optimizer state and the activations, against 130130 GB for the 16-bit weights alone.

How the 4-bit base compares with other weight-only quantizers such as GPTQ, and why outlier features make low-bit formats hard, is the subject of Quantization in Depth.

What LoRA learns and what it forgets

Matching full fine-tuning on benchmarks like GLUE does not mean LoRA is full fine-tuning. Biderman et al. (2024) compared the two on harder targets, programming and mathematics, in two regimes: instruction fine-tuning on about 100,000 prompt–response pairs and continued pretraining on 20 billion tokens. In standard low-rank configurations LoRA substantially underperformed full fine-tuning on the target domain, especially for continued pretraining, but it better preserved the base model's performance outside that domain: LoRA learns less and forgets less. It reduced forgetting more than weight decay or dropout did, and kept generations more diverse. Their spectral analysis offers a reason for the first half: full fine-tuning learned weight perturbations with ranks 10 to 100 times higher than typical LoRA configurations.

Shuttleworth, Andreas, Torralba & Sharma (2025) looked at the singular value decompositions of the fine-tuned weights. Even when accuracy matched, LoRA introduced intruder dimensions, new singular vectors with large singular values that are nearly orthogonal to those of the pretrained matrix, which full fine-tuning did not. LoRA forgot less overall, but its forgetting was concentrated in those dimensions: scaling their singular values down after training recovered much of the pretraining loss at little cost on the new task, and in sequential fine-tuning they accumulated and hurt.

Think first You must teach a base model a large new domain, continued pretraining on billions of tokens of code, and you care mainly about performance on that domain. Low-rank LoRA or full fine-tuning?

The evidence favors full fine-tuning. Biderman et al. found the gap largest for continued pretraining, where LoRA stayed behind full fine-tuning in every configuration they tried, rank 256 included (higher ranks narrowed the gap without closing it), and full fine-tuning's updates had very high rank. The trade-off reverses if keeping the base model's other abilities matters more than peak performance on the new domain, since low-rank LoRA forgets less.

Key takeaways

  • Fine-tuning has a low intrinsic dimension: about 200 random directions bring RoBERTa-Large to 90% of full fine-tuning on MRPC, pretraining lowers the intrinsic dimension, and larger models have lower values.
  • LoRA's zero-initialized BB starts training at the pretrained model, with only BB moving at first; adapting several matrices at low rank beats one matrix at higher rank, and its updates amplify directions the pretrained weights contain but do not emphasize.
  • The α/r\alpha/r factor makes updates shrink with rank; α/r\alpha/\sqrt r (rsLoRA) fixes it. LoRA+ uses a larger learning rate for BB, DoRA trains magnitudes separately from directions, and AdaLoRA reallocates rank.
  • QLoRA freezes the base in 4-bit NormalFloat with double-quantized constants (about 4.1274.127 bits per weight, so about 33.5 GB for 65 billion parameters) and trains 16-bit adapters on all linear layers.
  • LoRA learns less and forgets less than full fine-tuning, whose updates have far higher rank; its forgetting concentrates in intruder dimensions that accumulate under sequential fine-tuning.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

LoRA initializes AA randomly and BB at zero. Which factor receives a nonzero gradient on the very first training step?

  1. Only AA, because it multiplies the input
  2. Both, equally
  3. Neither, so a warmup step is needed
  4. Only BB, since ∂L/∂A=γrB⊤g x⊤\partial\loss/\partial A=\gamma_rB^\top\mathbf g\,\mathbf x^\top vanishes while B=0B=0
Show the answer

D. Only BB, since ∂L/∂A=γrB⊤g x⊤\partial\loss/\partial A=\gamma_rB^\top\mathbf g\,\mathbf x^\top vanishes while B=0B=0

∂L/∂B=γrg(Ax)⊤\partial\loss/\partial B=\gamma_r\mathbf g(A\mathbf x)^\top is nonzero because AA is random; ∂L/∂A\partial\loss/\partial A contains B⊤B^\top and is zero. After the first step B≠0B\ne0 and both factors train. The zero factor keeps the model exactly at the pretrained one at step 0.

Question 2

Why does rank-stabilized LoRA scale the update by α/r\alpha/\sqrt r instead of α/r\alpha/r?

  1. So that the size of the learning updates no longer shrinks as the rank grows, letting higher ranks actually help
  2. So that the adapter can be merged into the weights
  3. To reduce the number of trainable parameters
  4. To make LoRA equivalent to full fine-tuning at every rank
Show the answer

A. So that the size of the learning updates no longer shrinks as the rank grows, letting higher ranks actually help

An update's effect scales like γr2∥Ax∥2∝γr2r\gamma_r^2\norm{A\mathbf x}^2\propto\gamma_r^2r. With α/r\alpha/r that is ∝1/r\propto1/r, so learning slows as the rank rises; with α/r\alpha/\sqrt r it is rank-independent.

Question 3

In QLoRA, what does double quantization quantize?

  1. The LoRA adapters, to 4 bits
  2. The gradients, to 8 bits
  3. The per-block scaling constants of the 4-bit weights, cutting their overhead from about 0.5 to about 0.127 bits per weight
  4. The activations, to NF4
Show the answer

C. The per-block scaling constants of the 4-bit weights, cutting their overhead from about 0.5 to about 0.127 bits per weight

Each block of 64 weights has a 32-bit scale, half a bit per weight. Quantizing those scales to 8 bits in blocks of 256 leaves 8/64+32/(64⋅256)≈0.1278/64+32/(64\cdot256)\approx0.127 bits, about 3 GB saved on a 65-billion-parameter model.

Question 4

Hu et al. projected WQW_Q onto the top singular directions of its LoRA update ΔWQ\Delta W_Q and got a small norm (0.320.32), larger than for random directions (0.020.02) but far below WQW_Q's own top directions (21.6721.67). What do they conclude?

  1. ΔWQ\Delta W_Q duplicates the dominant directions of WQW_Q
  2. ΔWQ\Delta W_Q amplifies directions that WQW_Q contains but does not emphasize, by a factor of about 21.5
  3. ΔWQ\Delta W_Q is unrelated to WQW_Q, like a random matrix
  4. ΔWQ\Delta W_Q must be full-rank to work
Show the answer

B. ΔWQ\Delta W_Q amplifies directions that WQW_Q contains but does not emphasize, by a factor of about 21.5

The update is correlated with WQW_Q (more than random) but not with its top directions; with ∥ΔWQ∥F=6.91\norm{\Delta W_Q}_F=6.91, the directions it picks are amplified by 6.91/0.32≈21.56.91/0.32\approx21.5. Their reading: fine-tuning boosts features pretraining learned but did not stress.

Further reading

  • A. Aghajanyan, S. Gupta & L. Zettlemoyer, "Intrinsic dimensionality explains the effectiveness of language model fine-tuning," ACL (2021).
  • E. J. Hu, Y. Shen, P. Wallis, Z. Allen-Zhu, Y. Li, S. Wang, L. Wang & W. Chen, "LoRA: low-rank adaptation of large language models," ICLR (2022).
  • D. Kalajdzievski, "A rank stabilization scaling factor for fine-tuning with LoRA," arXiv:2312.03732 (2023).
  • T. Dettmers, A. Pagnoni, A. Holtzman & L. Zettlemoyer, "QLoRA: efficient finetuning of quantized LLMs," NeurIPS (2023).
  • D. Biderman et al., "LoRA learns less and forgets less," Transactions on Machine Learning Research (2024).