Boss lesson · Unit 03
Fine-tune on one GPU
Work out the memory bill of training, then cut it line by line
What you practise
- The memory bill of training (weights, gradients, optimizer state, activations) worked as arithmetic
- Half precision, gradient checkpointing, adapters on a quantised base
- What each trick costs
Try a question from this lesson
Pick one
Running a 1-billion-parameter model in 32-bit floats takes 4 GB for its weights. You have 12 GB of memory. Does full fine-tuning with Adam fit?
Hint
Count the numbers kept for each parameter while training with Adam, not just the weight itself.
Correct answer
No: 16 GB before any activations
Why
Training keeps four numbers per parameter: the weight, its gradient and Adam's two averages. 4 × 4 GB = 16 GB, and the activations come on top. Running the model fits three times over; fully fine-tuning it does not fit at all.
The ideas
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
The four lines of the bill
Training memory has four parts. Weights: every parameter. Gradients: one per trainable parameter. Optimizer state: two more per trainable parameter for Adam. Activations: each layer's outputs, kept from the forward pass because the backward pass needs them, and growing with batch size and sequence length.
A frozen parameter pays only the first line.
Concept
Gradient checkpointing
The backward pass needs each layer's activations, so normally all of them are kept from the forward pass. For long sequences that is the largest line of the bill.
Gradient checkpointing keeps only some activations and recomputes the others when the backward pass asks for them. Memory for activations drops. The price is extra forward computation on every step.
10 more exercises in the app
- 4× type the answer
- 3× multiple choice
- 1× true or false
- 1× match the pairs
- 1× fill the blanks
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.