Boss lesson · Unit 01
Read the loss curve
Warmup, decay, clipping, and diagnosing a run from its log
What you practise
- Warmup, cosine and linear decay computed for given steps, gradient clipping by norm, and diagnosing runs from their curves: diverging, stuck, too slow, overfitting
Try a question from this lesson
Pick one
A transformer run starts at its full learning rate and dies within 20 steps. The same rate works once training is underway. What is the standard fix?
step lr loss
1 3e-4 10.8
5 3e-4 11.9
10 3e-4 27.4
20 3e-4 nanHint
The rate is fine later on. What is different about the model and the optimizer's averages in the very first steps?
Correct answer
Start near zero and ramp the rate up
Why
At step 1 the weights are random, the gradients are large and Adam's averages rest on a handful of samples. A warmup ramps the rate up from near zero over the first steps, so the wild early updates are small ones.
The ideas
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
A schedule is a function of the step
The learning rate does not have to be one number. A schedule computes it from the step count: warm up from zero to the base rate, then decay back toward zero, so the last steps settle instead of bouncing.
Linear warmup is the base rate times the fraction of the warmup completed.
def lr_at(step, base, warmup):
if step < warmup:
return base * step / warmup
return base # decay comes nextConcept
Clip the gradient norm
One bad batch can produce a gradient a hundred times the usual size, and one step along it can wreck the weights. Clipping caps the length of the whole gradient: if its norm is over the limit, every entry is scaled down by the same factor.
The direction is kept. Only the length changes.
norm = sum(g * g for g in grads) ** 0.5
if norm > max_norm:
scale = max_norm / norm
grads = [g * scale for g in grads]10 more exercises in the app
- 3× type the answer
- 1× fill the blanks
- 3× multiple choice
- 1× true or false
- 1× order the lines
- 1× match the pairs
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.