Foundations
Derivatives and gradients, geometrically
Derivatives measure local sensitivity, gradients collect those sensitivities into one arrow, and the learning rate decides whether a step follows that arrow downhill or overshoots the valley.
Updated
01 · Concept
Concept
Here is the problem calculus solves for us. A model has parameters, and some setting of them makes its predictions good. You have no map of that space, no formula for the best setting, and far too many knobs to try combinations. All you can do is evaluate how bad the current setting is and ask a local question: if I nudge this one number slightly, does the badness go up or down, and by how much? Answer that for every number at once and you have a direction to move. That is the entire content of gradient-based learning, and everything below is the machinery for asking the question precisely.
A derivative measures local sensitivity. For a one-variable function , the derivative at is the slope approached by ever-smaller secant lines:
If , then a sufficiently small change produces an output change of roughly . That is a local linear approximation, not a promise about large moves. Geometrically it is the slope of the tangent line: positive means rising, negative means falling, zero means locally flat. Flat does not mean minimal; the point could be a maximum, a minimum, or an inflection where the curve merely pauses.
Neural networks depend on many parameters, so the loss is a function . A partial derivative asks how the loss changes when parameter moves slightly while all others stay fixed. Collecting them all gives the gradient:
The gradient points toward steepest local increase; its negative points downhill. Gradient descent applies , where the learning rate sets the stride.
Work the simplest possible example completely, because the failure mode is more instructive than the success. Let , so , with the obvious minimum at zero. Start at with . The first step gives . The second gives . Then , then . Each step multiplies by , so the sequence marches steadily toward the minimum. Optimization looks easy.
Now change nothing but the learning rate, to . From : . From : . Then , then . The magnitude grows by 20 percent every step and the loss explodes. Look carefully at what went wrong, because it was not the calculus. Every gradient in that run was exactly correct, and every step moved in the correct direction. The stride simply carried the parameter clean across the valley and up the far wall, into territory the local reading never described. This is the origin of exploding losses, of learning-rate warmup, and of the schedules in lesson 5.11.
The chain rule connects local sensitivities through composed operations. If and , then . A neural network is a long composition of matrix multiplications, activations, normalizations, and finally a loss, so its derivative is a long product of local factors. Backpropagation is the efficient bookkeeping for that product: it reuses intermediate results instead of separately tracing every path from every parameter to the loss, which is what makes training a large model arithmetically possible at all. Lesson 2.5 works through the mechanics.
That efficiency matters at the scale this course studies. In a model such as Qwen3.8-27B, the gradient is not a small arrow: it is a vector with one component for every one of roughly 27 billion parameters, the same shape as the parameters themselves, recomputed on every batch. Whatever else training a large model involves, geometrically it is stepping against that arrow, over and over.
Gradients carry units and scale. Multiplying the loss by a thousand multiplies its gradient by a thousand without changing which parameters constitute a solution. Features on wildly different scales make the surface poorly conditioned: one direction is a cliff while another is nearly flat, and a single scalar learning rate cannot suit both. Normalization, careful initialization, adaptive optimizers, and schedules all exist to manage that geometry. None of them changes the meaning of a derivative; they change the terrain it is measured on, which is the subject of lessons 2.6 through 2.8.
Not everything is differentiable everywhere. ReLU has a corner at zero and software picks a conventional value there. Token selection is discrete, so training differentiates through probabilities and continuous representations rather than through a sampled word. Finite differences can sanity-check a tiny implementation by perturbing one parameter and re-evaluating, but analytic automatic differentiation is enormously cheaper once the parameter count passes a few hundred.
The durable picture is a local map. Loss is terrain over parameter space; a partial derivative is the slope along one axis; the gradient is the assembled uphill arrow; the negative gradient suggests a downhill move whose length you must choose. Optimization is hard not because the definition is subtle but because the terrain is vast, curved, noisy, and observed only through batches.
02 · Analogy
Analogy
Stand on a foggy hillside with an instrument that reports the tilt under each foot. A derivative gives the uphill slope along one chosen direction. The gradient assembles every coordinate's tilt into a single arrow pointing at the steepest local ascent. To go down, step against the arrow. But the instrument describes only the ground beneath your boots: take a stride longer than the patch it measured and you may land higher than you started, on terrain the reading never described.
03 · Teach it back
Teach it back
Explain derivative, partial derivative, gradient, and learning rate on a loss surface, and show with numbers what happens when the learning rate is too large.
Compare with a model answer
A derivative measures how much an output changes for a tiny change in one input, as a local linear approximation. With many parameters, each partial derivative varies one parameter while holding the rest fixed, and the gradient collects them all into a vector pointing toward steepest local increase. Gradient descent steps against it, scaled by a learning rate. On the loss L(w) = w squared, the gradient is 2w; starting at w = 1 with learning rate 0.1 gives 0.8, then 0.64, converging toward zero. With learning rate 1.1 the same rule gives minus 1.2, then 1.44, then minus 1.728: the magnitude grows every step and the run diverges. The gradient was correct each time; the step size was not.
04 · Check your understanding
Check your understanding
Complete the teach-back and answer the quiz correctly to finish this lesson.
◎ · Evidence marker
Sources
- Ian Goodfellow, Yoshua Bengio, and Aaron Courville (2016). Deep Learning.
- Qwen Team (2026). Qwen3.8-27B Model Card.