Skip to content

Low-rank adaptation

Frozen base weights, trainable low-rank updates, a checked parameter-count example and the limits of LoRA memory savings.

Low-rank adaptation (LoRA) adapts a pretrained neural network by freezing selected weight matrices and learning a low-rank additive update to them. A quant team could use it to adapt a language model to labelled earnings-call passages while training and saving far fewer task-specific parameters. Whether those labels improve on a simpler classifier remains a held-out measurement question.
LoRA is a form of parameter-efficient fine-tuning: training changes the model, but the optimiser updates only a small set of additional weights. The original LoRA paper by Hu et al., §4, introduces the factorised update and shows how it can be merged into the original weights.

Keep the matrix, constrain the change

Use column-vector inputs. A frozen linear layer has W0∈Rd×kW_0\in\mathbb{R}^{d\times k}, input x∈Rkx\in\mathbb{R}^k and output in Rd\mathbb{R}^d. Standard LoRA writes

h=W0x+ΔWx,ΔW=αrBA,A∈Rr×k,B∈Rd×r.h=W_0x+\Delta W x, \qquad \Delta W=\frac{\alpha}{r}BA, \qquad A\in\mathbb{R}^{r\times k},\quad B\in\mathbb{R}^{d\times r}.

The positive integer rr is the chosen adapter rank, and α\alpha controls the update's scale. Here, standard LoRA means the original α/r\alpha/r scaling; some variants use other conventions. Biases and other trainable modules are excluded from this calculation.

The matrix rank of ΔW\Delta W is at most rr, because its output lies in the span of the rr columns of BB. Training learns both factors. It does not require either factor to be orthogonal, and does not obtain them by truncating the pretrained matrix's singular values.
In particular, W0+ΔWW_0+\Delta W can remain full rank. LoRA constrains the change, unlike replacing the entire layer with a low-rank approximation.
Column-vector input x follows two paths: a frozen 1024 by 1024 W0 and trainable A of shape 8 by 1024 followed by B of shape 1024 by 8, scaled by alpha over r and added to the frozen output. The adapter has 16,384 trainable weights versus 1,048,576 for the full matrix, a fraction of 1 over 64.
Column-vector input x follows two paths: a frozen 1024 by 1024 W0 and trainable A of shape 8 by 1024 followed by B of shape 1024 by 8, scaled by alpha over r and added to the frozen output. The adapter has 16,384 trainable weights versus 1,048,576 for the full matrix, a fraction of 1 over 64.
Illustrative single-layer LoRA, with rank 8. The bars compare trainable scalar weights on the same linear scale; the frozen base matrix still has to be stored and used.

What the 64-fold reduction counts

For a frozen 1024×10241024\times1024 weight matrix and r=8r=8, the two factors contain

8×1024⏟A+1024×8⏟B=16,384\underbrace{8\times1024}_{A} +\underbrace{1024\times8}_{B} =16{,}384

trainable scalar weights. Updating every entry of the original matrix would involve 1,048,5761{,}048{,}576 weights, so the adapter's count is 1/64=1.5625%1/64=1.5625\% of that full-matrix count.

This is 64 times fewer trainable weights for this matrix. It does not establish a 64-fold reduction in whole-model training memory or runtime. The frozen weights remain present, activations still occupy memory, and gradients must still propagate through the network to train the adapters. Training memory also depends on optimiser state, precision, batch size and sequence length. Additional trainable heads or biases change the count too.
The current PEFT LoRA documentation distinguishes the rank, target modules, scaling, biases and separately saved trainable modules. A parameter ratio for one matrix cannot substitute for measuring the configured training job.

A rank-one change you can multiply by hand

Consider a separate, deliberately tiny layer with d=k=2d=k=2, r=1r=1 and α=1\alpha=1. The scaling is therefore α/r=1\alpha/r=1. Suppose the learned factors are

B=(12),A=(34).B=\begin{pmatrix}1\\2\end{pmatrix}, \qquad A=\begin{pmatrix}3&4\end{pmatrix}.

Their update is

ΔW=BA=(3468).\Delta W=BA=\begin{pmatrix}3&4\\6&8\end{pmatrix}.

The second row is twice the first. For any input, the extra output lies along (1,2)⊤(1,2)^\top. For example, x=(2,−1)⊤x=(2,-1)^\top gives Ax=2Ax=2, followed by B(Ax)=(2,4)⊤B(Ax)=(2,4)^\top. Multiplying the displayed update by xx gives the same answer.

If W0=I2W_0=I_2, then W0+ΔWW_0+\Delta W has rows (4,4)(4,4) and (6,9)(6,9) and determinant 1212. The adapted matrix has rank two even though its update has rank one. This tiny example teaches the constraint; its two factors contain four scalars, so it offers no parameter saving over a four-entry full matrix.

A zero update can still start learning

The original paper initialises AA randomly and BB at zero. PEFT's documented default uses a random Kaiming-uniform AA and zero BB. In either case, the adapter initially adds nothing.

Zero initial output does not mean every learning gradient is zero. Write s=α/rs=\alpha/r and let GG be the loss gradient with respect to the effective weight matrix. For the task loss through this layer,

∇BL=sGA⊤,∇AL=sB⊤G.\nabla_B L=sGA^\top, \qquad \nabla_A L=sB^\top G.
At B=0B=0, the gradient for AA is zero, while the gradient for BB can be nonzero when AA is nonzero. Nonzero AA alone does not guarantee a nonzero BB gradient: it also depends on GG. Initialising both factors at zero makes both task-loss gradients zero. These statements concern the task loss, separately from any weight-decay update.

Using the saving in financial text research

Choose the target matrices, rank, scaling and stopping rule using training and validation data. A smaller adapter can still overfit; fewer trained weights do not prove that the task needs only a low-rank change. Keep a later test period untouched, and check whether the base model's pretraining or the adaptation corpus introduces look-ahead bias.

For standard linear LoRA at inference, one can form Wmerged=W0+(α/r)BAW_{\text{merged}}=W_0+(\alpha/r)BA. The merged layer uses the usual matrix multiplication, without a separate adapter branch. This does not shrink the base model's dimensions. Alternatively, keep the factors separate when swapping task adapters; then the extra branch remains part of the computation.

QLoRA adds another memory-saving mechanism: the QLoRA paper describes learning low-rank adapters through a frozen, four-bit quantised base model. Low-rank updates and reduced-precision storage address different parts of the memory budget. LoRA itself does not require four-bit weights.
The Transformers lesson develops the fine-tuning and held-out validation context for financial text. Kernel, Image, and the Rank-Nullity Theorem explains why a map's image limits its output directions. Both have public previews; full lessons require membership.

Sources

Last updated
  • lora
  • fine tuning
  • low rank updates
  • language models
← Back to the glossaryBack to top ↑