knowledge base · entry 09
Fine-tune by adding, not rewriting
A read-through of the paper that made fine-tuning cheap — by leaving the model frozen and training a tiny low-rank correction beside it.
every figure zooms — click it, scroll to magnify, drag to pan
part one
The idea, before any jargon
figure 1 · the whole idea
Fine-tune by adding, not rewriting
Fine-tuning a large model the normal way updates every one of its weights. Do that for five tasks and you have five full copies of a very large model to store, version, and serve. As models grew into the hundreds of billions of parameters, that stopped being practical.
LoRA's move is to leave the pretrained weights completely alone — frozen — and learn a small, separate correction to sit beside them. The big model already knows almost everything; a new task only needs a nudge, so why rewrite the whole thing to express it?
click any figure to zoom · scroll to magnify · drag to pan
This is the third answer in the making models smaller arc, and the sideways one. Distillation trains a new small model; the lottery ticket finds a small one hiding inside; LoRA keeps the big model whole and shrinks the fine-tune instead. All three chase the same question — how little is actually necessary?
part two · the mechanism
Why a nudge is enough
figure 2 · low rank
The update is low-rank
Here is the observation everything rests on. When you fine-tune, the change to a weight matrix — call it ΔW — turns out to have very low intrinsic rank. In plain terms: the fine-tune moves the weights in only a handful of directions, not in all of them. And any low-rank matrix can be written as a tall-thin matrix times a wide-short one.
So instead of learning the full ΔW, LoRA learns those two small factors, B and A, and takes their product as the update. A full matrix is d×d weights; the two factors are only 2·d·r, and the rank r is tiny — often 1, 2, or 8. That single substitution is the whole method.
figure 3 · the forward pass
How a layer runs
In the model, nothing dramatic happens. The input runs through the frozen weight matrix as always, and also through the little pair B·A, and the two results are simply added.
The frozen path carries what the model already knew; the trained path carries the task-specific correction. One nice detail: B is initialized to zero, so at the very start the correction is nothing at all — training begins exactly at the pretrained model and only departs as far as the task demands.
part three · the numbers
How much this actually saves
Skippable, but it's just multiplication — and the size of the saving is the reason anyone uses LoRA.
figure 4 · the parameter count
The saving, by hand
Take one attention weight matrix in a large model, with dimension 4096, and a LoRA rank of 8. Count the trainable weights both ways.
Two hundred and fifty-six times fewer, for that one matrix. Across an entire 175-billion-parameter model the paper reports on the order of 10,000× fewer trainable parameters — a 350 GB checkpoint becomes a 35 MB adapter — with no measurable loss in quality versus full fine-tuning.
part four · the payoff
Free at inference, and swappable
figure 5 · merge and swap
No inference tax, and a shelf of specialists
There's a second advantage that's easy to miss. Because B·A has the same shape as W, once training is done you can just add them together into a single matrix W′. At inference there's one matrix where there was one before — zero extra latency. Adapter methods that insert new layers cannot say the same.
Or don't merge, and keep the adapters separate: one frozen base loaded on the GPU, and a shelf of tiny per-task adapters you swap in by loading a few megabytes. That's what makes running many specialists on shared hardware affordable.
the math · in the paper's notation
One equation, one count
LoRA's entire formal content is a modified forward pass and a parameter count. Both here, in the paper's own symbols, with the numbers from figure 4 re-derived.
the equations · worked
The forward pass, and what it costs to train
§4.1, eq. (3) · the modified forward pass
h = W0 x + ΔW x = W0 x + αr BA x
read aloud: the input runs through the frozen weights as always, plus through the low-rank pair BA, scaled by α/r; the two results add. B starts at zero, so training begins exactly at the pretrained model — the correction grows from nothing.
- W0the pretrained weight matrix, d×k — frozen, never updated
- B, Athe trained factors: B is d×r (initialized 0), A is r×k (initialized gaussian)
- rthe rank — the width of the bottleneck, often 1–8; the paper's core claim is that tiny r suffices
- αa fixed scaling constant; α/r keeps the update's magnitude stable when you change r, so the learning rate doesn't need retuning
§4.2 · the trainable-parameter count
|Θ| = 2 · L̂ · dmodel · r vs dmodel × dmodel per full matrix
read aloud: each adapted matrix costs two thin factors — d·r each — instead of d²; multiply by the number of adapted matrices L̂. The count is linear in r, which is why the savings are enormous at small rank.
- L̂how many weight matrices get an adapter — the paper adapts the attention projections Wq, Wv
- dmodelthe model width — 12,288 for GPT-3 175B
part five · what we take from it
One base, many owned specialists
applied · our reading
The arc's practical endpoint
For sovereign, domain-specific systems this is the most directly useful paper in the whole making models smaller arc. Train and freeze one base model on-premise. Then, for each task — tax, customs, payroll — fine-tune a small adapter, version it like a piece of code, and swap it in place. Nothing large ever leaves the box, and a new specialist costs megabytes, not a model.
the caveat we would flag LoRA reshapes directions the base already has — it adapts existing knowledge cheaply, but it can't install capacity the base fundamentally lacks. If a domain needs knowledge the base never saw, an adapter won't conjure it. And the rank r is a genuine knob: set it too low and a hard task quietly underfits, with no error to warn you.
next in the arc
Where this goes
That completes making models smaller — distillation, the lottery ticket, and LoRA, three routes to the same end. The next arc, data & scaling laws, steps back to ask the prior question: given a fixed compute budget, how big should the model be and how much data should it see? That's Chinchilla.
source
Hu, Shen, Wallis, Allen-Zhu, Li, Wang, Wang, Chen — Microsoft (2021). LoRA: Low-Rank Adaptation of Large Language Models. arXiv:2106.09685. The parameter counts and the ~10,000x figure are the paper's; the matrix diagrams and the worked example are our own illustration.
← back to the knowledge base · ⚙ the illustrated decoder · ▶ run the forward pass
attention.sh — a division of Jinacode Systems. Transformers,
fine-tuning, and sovereign LLMs.
we're hiring the curious — hello@attention.sh