Learning rate schedules
Quick answer
A learning-rate schedule changes the optimizer step size according to progress or measured validation performance. A warmup may start small, a decay schedule may reduce late updates, and a plateau scheduler reacts to a monitored metric. Examples are static Python snippets tested locally on PyTorch CPU. ByteMind execution is unverified.
Step schedule ordering
import torchw=torch.nn.Parameter(torch.tensor(0.)); o=torch.optim.SGD([w],lr=.2)s=torch.optim.lr_scheduler.StepLR(o,step_size=2,gamma=.5)rates=[]for _ in range(5): rates.append(round(o.param_groups[0]["lr"],3)); w.grad=torch.ones_like(w); o.step(); s.step()print(rates)Expected output (locally tested): [0.2, 0.2, 0.1, 0.1, 0.05]. The schedule changes the next epoch rate after two completed updates.
How it works
Step decay with base eta0, period k and factor gamma uses eta(e)=eta0gamma**floor(e/k), for zero-based epoch e before its updates. Cosine decay over T steps uses eta_min + (eta_max-eta_min)(1+cos(pi*t/T))/2 for 0<=t<=T. A warmup can interpolate from a small rate to the target over W updates. Define the unit (batch update or epoch) explicitly. In PyTorch call optimizer.step() before scheduler.step(); StepLR is usually advanced after an epoch, whereas OneCycleLR advances per batch. ReduceLROnPlateau consumes a monitored metric after validation, unlike StepLR. Save optimizer and scheduler state to resume the same trajectory; construct the scheduler before loading optimizer state per API guidance. A rate that is too high can cause oscillation or divergence; too low can make progress impractically slow.
Cosine schedule checkpoints
import mathprint([round(.01+.09*(1+math.cos(math.pi*t/4))/2,3) for t in [0,2,4]])Expected output (locally tested): [0.1, 0.055, 0.01]. The endpoints and midpoint are easy to verify independently.
Common mistakes
Do not call an epoch schedule every mini-batch unless the period is defined in batches. Never feed the final test loss into ReduceLROnPlateau. A schedule and an optimizer are different mechanisms.
Practice and next steps
Write down the rates actually used in the first five epochs. Compare them with the rates logged after scheduler.step(), which apply to the next epoch.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Learning rate schedules — knowledge check
Apply learning rate schedules to small examples and debugging scenarios.
When is StepLR normally advanced in an epoch schedule?
Which scheduler consumes a validation metric?
What is the cosine midpoint between 0.1 and 0.01?
What should a scheduler period specify?
What must be restored for schedule continuity?