Start studying
Module 10 · Fine-Tuning Module contents
Module 10  ·  Card 5 / 15intermediate

LoRA

LoRA stands for Low-Rank Adaptation.

It freezes the original weights and trains small added matrices instead.

Those matrices are low-rank, so they hold very few parameters.

You often train under 1% of the model and still get most of the benefit.

The adapter is a few megabytes and can be swapped in and out at will.

Learn in depth ↓
Module 10 · Fine-Tuning · 15 concepts
In depth  /  15 lines

LoRA, in more detail

LoRA is low-rank adaptation, and it made fine-tuning affordable.

Full fine-tuning updates every weight and needs memory for gradients and optimizer state too.

For a 7B model that is comfortably over 60 GB, which is beyond most single GPUs.

LoRA freezes the original weights entirely and never updates them.

It adds a small pair of matrices beside each weight matrix it wants to adapt.

Their product has the same shape as the original, so it can be added to the output.

The pair is low-rank, meaning deliberately narrow in the middle.

A 4,096 by 4,096 matrix holds 16 million numbers.

Two matrices of rank 8 hold about 65,000, which is a fraction of a per cent.

The insight is that the change a task needs is simple even when the model is not.

You train under one per cent of the parameters and get most of the benefit.

The adapter is a few megabytes and ships separately from the base model.

Many adapters can share one base, swapped per request.

Rank is the main knob, with 8 to 16 typical and higher for harder tasks.

It can be merged into the base weights afterwards, leaving no inference overhead.

Want the full technical article? Wikipedia ↗
Deep dive

What is underneath LoRA

Train a difference, not the weights

Full fine-tuning updates every parameter. LoRA freezes them all and learns a small additive correction instead.

W′=W0+ΔW=W0+BAW' = W_0 + \Delta W = W_0 + BA
  • W0W_0: the pretrained weight matrix, d×kd \times k, frozen and never touched.
  • BB: a new matrix, d×rd \times r, initialised to zero.
  • AA: a new matrix, r×kr \times k, initialised randomly.
  • rr: the rank, and the one number you choose. Typically 8, 16 or 64.

Because BB starts at zero, BABA starts at zero, and the model at step zero is exactly the pretrained model.

The arithmetic that makes it worth doing

full: d×kLoRA: r(d+k)\text{full: } d \times k \qquad \text{LoRA: } r(d + k)

For a 4096×40964096 \times 4096 attention projection, full fine-tuning trains 16.8 million parameters.

At r=8r = 8 LoRA trains 8×(4096+4096)=65,5368 \times (4096 + 4096) = 65{,}536, which is 0.39% of them.

r(d+k)dk=8×819216,777,216≈0.0039\frac{r(d+k)}{dk} = \frac{8 \times 8192}{16{,}777{,}216} \approx 0.0039

The saving compounds: optimiser state for Adam is two extra numbers per trainable parameter, so cutting the trainable count by 250x cuts optimiser memory by 250x too.

For a 7 billion parameter model in 16-bit, full fine-tuning with Adam needs over 100 GB for weights, gradients and optimiser state.

With LoRA it needs little more than the 14 GB the frozen weights take, plus activations.

The scaling factor

W′=W0+αrBAW' = W_0 + \frac{\alpha}{r} BA
  • α\alpha: a constant, usually fixed while rr is varied.

Dividing by rr means the size of the update does not change when you change the rank, so a learning rate tuned at r=8r = 8 still works at r=64r = 64.

Without it, raising the rank would silently raise the effective learning rate as well, and the two effects would be impossible to separate.

One training step, in order

  1. Forward through the frozen W0W_0 as normal.
  2. Forward the same input through AA then BB, scaled by α/r\alpha / r.
  3. Add the two outputs together.
  4. Backward: gradients flow only into AA and BB.
  5. The optimiser updates AA and BB and nothing else.

The bet it is making

The claim is that the useful update has low intrinsic rank: adapting a model to a new task moves it in far fewer directions than it has parameters.

rank(BA)≤r\mathrm{rank}(BA) \leq r

That is a hard ceiling, not a tendency. Whatever AA and BB learn, the correction can never have rank above rr.

It holds well for adapting style, format and domain, and badly for teaching genuinely new knowledge. That is the honest boundary between when LoRA is enough and when it is not.

Merging

Wmerged=W0+αrBAW_{\text{merged}} = W_0 + \frac{\alpha}{r} BA

The product can be computed once and folded into the original weights, after which inference costs exactly what the base model cost.

That is the practical difference from adapters: LoRA adds no latency at serving time, because at serving time it no longer exists as a separate thing.

Test yourself

One question on this card. Every option explains itself once you pick, right or wrong.

Question 1
What does LoRA actually train?
Fine-Tuning

15 concepts in this module, then a graded test with every answer explained.

Study this module →
↑↓ move↵ openesc close