SGD, momentum, AdamW and schedules
What it is
Plain SGD follows the current batch gradient; momentum accumulates a velocity so persistent directions are amplified and contradictory batch noise is damped. Adam keeps moving estimates of both gradient direction and scale, adapting the step for each parameter, while AdamW applies weight decay separately so its regularising effect remains predictable. A schedule changes the global learning rate over time: warmup prevents unstable early updates, and decay encourages later updates to refine rather than overshoot. Optimiser state is part of a resumable training run and must be checkpointed with the model.
Why it matters
Optimiser and schedule choices can decide whether the same architecture trains at all. They are hyperparameters, so compare them on validation data rather than tuning on the test set. Start with a sensible, documented baseline such as AdamW plus warmup and decay, then change one factor at a time while recording the exact effective batch size and update count.
In the real world: Picking the optimiser and schedule decides how long and how expensive training is.
Visual example
Learning-rate scheduleWarm up to a useful step size, then reduce it as optimisation settles.
import torch
opt = torch.optim.AdamW(model.parameters(), lr=3e-4, weight_decay=0.01)
sched = torch.optim.lr_scheduler.CosineAnnealingLR(opt, T_max=total_steps)
for xb, yb in loader:
opt.zero_grad()
loss_fn(model(xb), yb).backward()
opt.step()
sched.step() # per step here, not per epoch — match T_max to thisAssuming AdamW makes learning-rate tuning unnecessary. AdamW is robust, not magic; its learning rate is usually the first setting to investigate when training is unstable or stalled.