Training and Tuning, lesson 8
Adapters and LoRA
Train a small add-on instead of the whole model.
You know fine-tuning from "Instruction tuning": more training on a smaller, targeted dataset. It helps to know that a layer's weights are a grid of numbers ("Stacking neurons into layers" in Neural Networks).
Part 1. What full fine-tuning costs
Fine-tuning every weight of a 7-billion-parameter model takes far more memory than running it. Each parameter brings luggage.
Example 1.1
Memory for full fine-tuning, 7B
- weights7B × 2 bytes=14 GB
The weights in a 16-bit format. This is all you need to run the model.
- gradients7B × 2 bytes=14 GB
One gradient per weight, from the backward pass.
- Adam7B × 12 bytes=84 GB
The Adam optimiser keeps a 32-bit copy of every weight plus two running averages per weight: 4 + 4 + 4 bytes.
- total7B × 16 bytes=112 GB
And that's before activations. It's more than one 80 GB GPU holds, for a model that runs in 14 GB.
Your turn
You want 20 versions of a 7B model, each tuned for a different customer. With full fine-tuning, what do you store?
Full fine-tuning
Training every parameter of a pretrained model. It's the most flexible option and the most expensive one.
Part 2. A small add-on beside the big matrix
Keep going with Pro
You've done the first part. Pro opens the rest of this lesson, and every other one.
- A small add-on beside the big matrix
- Starting harmless, ending free
- QLoRA: shrink the frozen part
Training and Tuning overviewSpotted a mistake? Tell us.