The optimizer is the recipe for using gradients
SGD takes w := w - lr * grad. Modern optimizers add momentum (running averages of past gradients), per-parameter scaling (running averages of past squared gradients), and weight decay. The differences are what make some optimizers train faster, some generalize better, and some be the right default for transformers vs CNNs.
- SGD with momentum — classic baseline. Often best for CNNs trained from scratch on ImageNet-style data. Tune lr, momentum (0.9), weight decay carefully.
- Adam — adaptive per-parameter learning rates via running mean and variance of gradients. Trains fast, sometimes generalizes worse than SGD on vision.
- AdamW — Adam with decoupled weight decay (the right way to do weight decay in adaptive optimizers). Default for transformers and most modern training.
- Lion — sign-based optimizer, less memory than Adam, comparable accuracy on some workloads.
- Adafactor — memory-efficient (no per-parameter variance state), used at very large scales (e.g., T5).
Why decoupled weight decay matters
"Weight decay" was originally an L2 regularizer added to the loss: L + 0.5 * λ * ||w||². In SGD, this is mathematically identical to subtracting λw from the gradient before stepping. In Adam, it is not — the adaptive learning rate scales the L2 term in a way that makes it less effective. AdamW decouples it: subtract λw directly during the step, separate from the adaptive scaling. This small fix makes a measurable difference on most tasks.