Gradient descent: the basic algorithm
If training a neural network is a hike toward the bottom of a valley, gradient descent is the most natural strategy: at each step, look at the slope under your feet and descend in the steepest direction.
The formula
At each iteration:
- You compute the gradient : the direction of steepest ascent of the loss
- You take a step in the opposite direction (you want to descend, not climb)
- The step size is controlled by the learning rate
It's the simplest optimization algorithm, and yet it's the foundation of all deep learning training.

The learning rate: the most important parameter
The effect of learning rate
The learning rate controls the size of each step. It's probably the most critical hyperparameter in deep learning.
- too large: steps are too big, you "jump over" minima. The loss oscillates or diverges completely toward infinity.
- too small: steps are tiny, convergence is astronomically slow. You're wasting compute.
- just right: convergence is fast and stable.
Analogy
Imagine you're descending a hill in the fog. If you take big steps, you risk tumbling down the slope and ending up on the other side of the valley. If you take steps that are too cautious, it'll take hours to reach the bottom. The right step size depends on the steepness of the slope.
Learning rate schedules
In practice, you almost never keep a constant learning rate. Common strategies:
- Warmup: start with a very small and gradually increase it. This stabilizes the first iterations when gradients are noisy.
- Cosine decay: decrease following a cosine, to "land" gently in a minimum.
- Step decay: divide by a factor at predefined steps.
- Warmup + cosine: the most popular combination for LLM training.
SGD: the stochastic version
The problem with the full gradient
The "exact" gradient requires computing the loss over all training data:
For a dataset of millions of examples, that's extremely expensive for a single optimization step.
The solution: the mini-batch
Stochastic Gradient Descent (SGD) estimates the gradient on a random subset (mini-batch) of examples:
It's a noisy estimate of the true gradient, but in expectation it's correct:
Batch size
- Small batch (32, 64): noisy gradient, good exploration, implicit regularization, but poor GPU utilization
- Large batch (4096, 8192): more precise gradient, better GPU utilization, but may converge to narrower minima and requires larger learning rates
- Rule of thumb: if you multiply the batch by , you can often multiply the learning rate by (square root scaling rule, sometimes also called linear scaling rule when using a factor of directly)
Momentum: accumulating speed
The problem with plateaus and narrow valleys
Basic SGD has two problems:
- On a plateau (gradient nearly zero), it barely moves
- In a narrow valley, it oscillates from one side to the other instead of descending along the valley
The solution: momentum
Inspired by physics (a ball rolling downhill accumulates speed), momentum maintains a "memory" of past gradients:
The parameter (typically 0.9) controls inertia. Consistent gradients accumulate (acceleration in the right direction), while oscillations cancel out.

Analogy
A ball in a bowl oscillates at first, then stabilizes at the bottom thanks to friction. Without momentum, SGD is like a ball with no inertia that stops as soon as the slope is zero. With momentum, the ball crosses small bumps and flat zones thanks to its accumulated speed.
Nesterov momentum
An improved variant that "looks ahead" before computing the gradient:
Instead of computing the gradient at the current position, you compute it at the position where momentum would take you. This allows anticipatory correction and often improves convergence.
Adaptive optimizers
The idea
Instead of using the same learning rate for all parameters, adapt to each parameter individually. Parameters with large frequent gradients need a small learning rate, and vice versa.
Adam: the standard
Adam (Adaptive Moment Estimation) combines momentum and learning rate adaptation:
The default hyperparameters (, , ) work remarkably well in most cases.
AdamW: Adam with decoupled weight decay
Classic Adam applies weight decay to the modified gradient, which interacts poorly with adaptation. AdamW decouples the two:
This is the standard optimizer for training transformers and LLMs.
Convergence conditions
Smoothness
If the loss is -smooth (the gradient doesn't vary too fast), gradient descent converges with:
A learning rate greater than risks diverging. This is the theoretical justification for "too large = diverges."
Convergence rate
For a convex and smooth function:
- Gradient descent: converges in , after iterations, the error is proportional to
- With momentum: converges in , much faster
- Strongly convex: exponential convergence
For non-convex functions (deep learning), these guarantees don't apply directly, but they guide intuition.
The high-dimensional landscape
Saddle points everywhere
In a -dimensional space, a critical point has curvature directions. For it to be a local minimum, all curvatures must be positive. The probability of this happening "by chance" is on the order of , astronomically small when is in the millions.
Result: the vast majority of critical points in high dimensions are saddle points, not local minima. Gradient descent doesn't get "stuck" in local minima; the real challenge is traversing saddle points and plateaus.
Why SGD crosses saddle points
The stochastic noise of SGD is the key. At a saddle point, the average gradient is zero, but the noisy gradient fluctuates. These fluctuations push the trajectory in directions of negative curvature (descent), allowing it to escape.
An exact gradient (full batch) would remain stuck indefinitely at a saddle point. The noise of SGD is an advantage, not a drawback.
Key takeaways
- Gradient descent is the fundamental algorithm:
- The learning rate is the most critical hyperparameter; schedules are used (warmup + cosine decay)
- SGD estimates the gradient on a mini-batch, which is noisy but correct in expectation
- Momentum accumulates speed to cross plateaus and narrow valleys
- Adam/AdamW adapt the learning rate per parameter and are the standard for transformers
- In high dimensions, saddle points dominate and SGD noise helps traverse them
Where this is used. These methods are what the optimizers used in practice implement, Adam first among them.