SGD and its variants are the workhorses of neural network training.
Vanilla gradient descent:
- Uses the full dataset to compute — expensive for large datasets
Stochastic GD: compute gradient on a single random sample. Noisy but cheap.
Mini-batch SGD (the practical default): compute gradient on a random subset (batch) of size :
Key properties:
- Noise from mini-batches can help escape shallow local minima and saddle points
- Smaller batch → more noise, potential regularization effect
- Larger batch → more stable gradients, better hardware utilization
- The learning rate is the single most important hyperparameter → Learning Rate Schedules
Gradient clipping: before the update, compute the global norm over all gradients; if it exceeds a threshold, scale every gradient down by the same factor to bring the norm under the max. This prevents any single step from being catastrophically large (important for RNNs and transformers).
Limitations of vanilla SGD:
- Same learning rate for all parameters
- Struggles with ill-conditioned loss surfaces (ravines) — oscillates across the narrow direction
- Addressed by Momentum and Adam Optimizer
See also: Gradient, Convexity, Backpropagation