How it works · 32 of 37 Advanced

What is LoRA fine-tuning?

Cheap fine-tuning

LoRA: Instead of retraining the whole model, train a small add-on layer; swap add-ons per task.

Loading the animation…

Say it like this LoRA freezes the big model and trains only a small add-on per task, so one model can wear many cheap specialisations.

Under the hood — for builders
How small the add-on is
For GPT-3, the trained add-on was 35 MB against the model's 350 GB, about 10,000 times smaller; the squares are drawn to scale.
As good as retraining
On GPT-3, the small add-on matched or beat retraining every number on three tasks.
How the add-on works
The change to each big table of numbers is written as two thin tables multiplied together, so far fewer numbers are trained.
Training cost
On GPT-3 175B, training memory fell from 1.2 TB to 350 GB, and training ran 25% faster.
Even cheaper
QLoRA trains LoRA on a 4-bit model (see Quantization): a 65B model fine-tuned on one 48 GB graphics card.
Words to know
Adapter: the add-on. Rank (r): how thin the two tables are; small values like 1–8 worked on GPT-3.
Watch out
Mixing requests for different adapters in one batch takes extra work, if adapters are merged into the model for speed.
Sources
Hu et al., LoRA: Low-Rank Adaptation of Large Language Models, arXiv 2106.09685 · Dettmers et al., QLoRA: Efficient Finetuning of Quantized LLMs, arXiv 2305.14314.

What happens in the LoRA animation, step by step?

  1. Fine-tuning normally retrains every number in a model. For GPT-3 that means a new 350 GB copy for each job.
  2. LoRA locks the model and trains only a thin add-on: 35 MB, about 10,000 times smaller.
  3. Your turn: drag a lens onto the camera. Same model, same question, a different specialist.
  4. Swapping lenses is instant. For 100 jobs: one model plus 100 lenses is 354 GB, not 35 TB.
  5. And it costs little quality: on GPT-3, LoRA scored as well as retraining the whole model.

What everyday example explains LoRA?

Clip-on lenses for one camera instead of buying new cameras.

Why should a team care about LoRA?

How most companies actually fine-tune.