Notes

LoRA

Fine-tuning used to mean moving every weight in the model, which for a 70-billion-parameter network is a research-cluster job. LoRA starts from a quieter observation: the change you need is far simpler than the model being changed.

Two thin matrices instead of one fat one

The original weights are frozen. Beside a chosen weight matrix, LoRA trains a pair of small matrices whose product has the same shape — a low-rank stand-in for the update, with a rank of typically 8 to 64 instead of thousands. Gradients flow only through that pair, so fewer than 1% of the parameters are trainable and the optimizer state that normally dominates memory shrinks with them. At inference the product is added back into the frozen weights, so there are no extra layers and no added latency.

What this buys in practice
  • A 7B model adapts on a single 24 GB consumer GPU; with QLoRA, which holds the frozen base in 4-bit, a 70B model fits on one 48 GB card.
  • An adapter is tens of megabytes, so one base model can serve dozens of task-specific adapters, swapped per request.
  • The base model is untouched, so a bad training run costs nothing but time.
Where it falls short

A low-rank update steers behaviour and style well and teaches output format reliably, but it is a poor way to install large amounts of genuinely new knowledge — that still wants continued pretraining. Hugging Face PEFT is the standard implementation, and adapters are conventionally attached to the attention projections first.

LoRA (Low-Rank Adaptation) fine-tunes a large model by freezing its weights and training a pair of small matrices whose product approximates the weight update. Fewer than 1% of parameters are trainable, so a 7B model adapts on one consumer GPU and the result is a file of tens of megabytes rather than a full model copy. Merged back at inference, it adds no latency. It is what makes task-specific tuning affordable and swappable.

Imagine a thick reference manual that is almost right for your office, but not quite. You could rewrite the whole book — or you could slip in a few pages of amendments and read them alongside the original. LoRA is the second approach applied to a language model. The billions of numbers it learned during training are left untouched, and only a small new set is trained to nudge its behaviour toward one particular job, like writing in a company's house style. The amendment file is small enough to email, and you can keep several of them for different tasks and swap them in as needed.