Concept · Chapter 2: The Math Toolkit
Gradient Descent
Gradient descent minimizes a loss by repeatedly nudging every parameter a small step in the direction that decreases the loss fastest — the negative gradient.
The problem
A model may have billions of parameters and no formula for the best values; we need a general procedure that improves any differentiable model.
The solution
Compute the gradient of the loss with respect to all parameters, move each parameter a little against it (scaled by the learning rate), and repeat.
The consequence
One simple loop trains everything from linear regression to GPT — with the learning rate as the most important knob, and non-convex landscapes meaning no guarantee of the global best.
You should understand first
- Derivatives and Gradients
- Loss Functions
- Gradient Descent
Intuition
Blindfolded on a hilly landscape, trying to reach the lowest point: feel which way the ground slopes, take a step downhill, repeat. You'll get lower and lower. You might end up in a small hollow rather than the deepest valley — but in the high-dimensional landscapes of neural networks, the hollows you reach are usually good enough.
Tiny numeric example
Minimize , whose gradient is . Start at with learning rate :
Step 1
gradient ;Step 2
gradient ;Keep going
Each step shrinks the distance to 3 by 20%: . We converge to .Now with η = 1.1
Each step multiplies the distance by : it overshoots, flips side, and grows. Diverged.
The equation
Try it
Try it · toy model
Drop a point on a loss landscape and watch gradient descent, momentum and Adam race to the bottom. Push the learning rate until training diverges; add noise to see stochastic gradient descent.
Where it appears in AI
Every time a model "learns", this loop runs: forward pass → loss → gradient (via backpropagation) → update. Real training adds three refinements covered next: gradients from random mini-batches (SGD), momentum and per-parameter step sizes (Adam), and learning-rate schedules (warm up, then decay).
Why should I care?
As a researcher
Optimization choices — learning rate, schedule, optimizer — often matter as much as architecture, and many papers' improvements turn out to be optimization effects.
As an engineer
Diverging losses, slow training and wasted GPU hours usually trace back to learning-rate and optimizer settings.
Modern systems that depend on it
- Training every neural network
- SGD, momentum, Adam/AdamW
- Learning-rate schedules and warm-up
- Fine-tuning and LoRA
Historical context
Before
Closed-form solutions (e.g. least squares) for simple models; Cauchy described the method of steepest descent in 1847.
After
Stochastic gradient descent made it practical on huge datasets; momentum and adaptive methods like Adam made it faster and more robust.
Used today
Every modern neural network, including every LLM, is trained with a variant of gradient descent — typically AdamW on mini-batches.
What to remember
- Update: w ← w − η · ∇L(w).
- η (learning rate) too small → painfully slow; too large → overshoot and diverge.
- On non-convex losses it finds a good local region, not a guaranteed global minimum.
- Ill-conditioned (ravine-shaped) losses make plain GD zig-zag — momentum and Adam help.
- Stop condition in practice: a fixed budget of steps, not 'reaching the minimum'.
Key papers
An overview of gradient descent optimization algorithms
Sebastian Ruder · 2016
The standard readable survey of SGD, momentum, RMSprop, Adam and friends — one paper that explains the whole optimizer family tree.
How to read it: Very approachable. Read it after trying the Gradient Descent Playground.
Learning representations by back-propagating errors
David E. Rumelhart, Geoffrey E. Hinton, Ronald J. Williams · 1986 · Nature
Showed that backpropagation lets multi-layer networks learn useful internal representations — the algorithm that still trains every neural network.
How to read it: Only four pages in Nature. Read it after the chain-rule concept page.
Watch
3Blue1Brown
Gradient descent, how neural networks learn | Deep Learning Chapter 2
Connects the abstract idea of minimizing a function to how a real network learns to recognise digits.
StatQuest with Josh Starmer
Gradient Descent, Step-by-Step
Works gradient descent out by hand on a tiny regression problem, one step at a time.