Where We Are
In Chapter 023 we finally gave the model a rule for improving itself:
The gradient tells us which direction lowers the loss.
But the learning rate decides how far we trust that direction.
That sounds like a small implementation detail. It is not. It is the difference between learning, wasting compute, and divergence.
1. The Problem: Downhill Can Still Go Wrong
Imagine standing on a valley floor in fog.
You can feel the local slope beneath your feet, so you know which way is downhill. But you do not know how far the hill keeps bending the same way.
Three choices:
- tiny step → safe, but painfully slow,
- sensible step → fast progress,
- giant step → jump across the valley and climb the other wall.
Gradient descent has exactly the same problem.
Suppose
Then
Start at .
Case A —
We moved toward 3.
Case B —
We jumped past the answer to the opposite side.
One more step:
Now we bounce forever: .
Case C —
The next step overshoots even farther. The oscillation grows. Training diverges.
The gradient was correct in all three cases. The difference was the step size.
2. Why Curvature Matters
A steeply curved loss changes direction quickly.
A gently curved loss changes direction slowly.
That means a learning rate that is safe on a flat surface may be too aggressive on a sharply curved one.
For
we have
Gradient descent becomes
The error shrinks only when
which gives
The number is curvature.
Higher curvature → smaller safe learning rate.
This is our first deep connection between geometry and optimization.
3. One Parameter Is Easy. Neural Networks Are Not.
A real model does not have one parameter.
It may have millions or billions.
Then the loss is not a curve. It is a high-dimensional surface.
Near a point, the curvature is captured by the Hessian:
Its eigenvalues tell us how sharply the surface curves along different directions.
For a quadratic loss, the safe constant learning rate must satisfy approximately
where is the largest eigenvalue of the Hessian.
So the steepest direction controls the maximum safe step for every direction.
4. Why Narrow Valleys Make Learning Zig-Zag
Consider a bowl that is wide in one direction and narrow in another.
steep wall
/\
/ \
--------/----\-------- flat direction
/ \
Along the narrow direction, curvature is large. Along the long valley, curvature is small.
A single learning rate must be small enough not to explode across the narrow direction.
But that same small step now moves slowly along the flat direction.
This creates the classic zig-zag path:
\ /\ /\
\ / \ / \
\ / \ / → minimum
The model wastes many steps bouncing across the valley instead of moving directly along it.
This is why feature scaling, normalization, momentum, RMSProp and Adam matter later: they are all, in different ways, attempts to make optimization less hostage to badly shaped geometry.
5. Tiny Numerical Experiment
Let
Then
The curvature in is 50 times larger than in .
Start at .
With :
One direction is solved almost instantly. The other barely moves.
That mismatch is the optimization problem.
6. Code It From Scratch
import numpy as np
def loss(x, y):
return 50*x**2 + y**2
def grad(x, y):
return np.array([100*x, 2*y])
def run(lr, steps=20):
p = np.array([1.0, 1.0])
history = []
for _ in range(steps):
history.append((p.copy(), loss(*p)))
p = p - lr * grad(*p)
return history
for lr in [0.001, 0.01, 0.021]:
h = run(lr)
print(lr, h[-1])
Before running it, predict:
- which learning rate is painfully slow?
- which one is useful?
- which one becomes unstable?
That prediction matters more than the code.
7. What the Loss Curve Tells You
A training-loss graph is not just a scorecard. It is a diagnostic tool.
Smooth downward curve
Likely healthy learning rate.
Almost flat
Learning rate may be too small, gradients may be tiny, or optimization may be stuck in a flat region.
Wild oscillation
Learning rate may be too large.
Loss suddenly becomes nan
Possible exploding activations/gradients, numerical overflow, or an excessively large update.
Falls fast then plateaus
Could be normal convergence, poor conditioning, saturation, insufficient model capacity, or a learning-rate schedule that needs adjustment.
Optimization debugging begins by learning to read the shape of training.
8. Why We Change the Learning Rate During Training
Early in training, we are far from the solution. Large steps are useful.
Near the minimum, large steps cause bouncing. Smaller steps help settle.
So modern training often uses a learning-rate schedule.
A simple decay might be
Other common ideas include:
- step decay,
- cosine decay,
- exponential decay,
- warmup,
- one-cycle schedules.
Do not memorize them yet.
Remember the principle:
far away → exploration can tolerate larger steps; near the bottom → precision needs smaller steps.
9. Warmup: Why Start Smaller?
Transformers are often trained with learning-rate warmup.
At the beginning, parameters and optimizer statistics are poorly calibrated. Large updates can destabilize the network before useful representations form.
Warmup gradually increases the learning rate:
and then a decay schedule takes over.
This may look like a hack until you see the geometry: the model begins in a region whose scale and curvature are not yet well behaved.
10. PyTorch View
import torch
w = torch.tensor([0.0], requires_grad=True)
optimizer = torch.optim.SGD([w], lr=0.1)
for step in range(20):
optimizer.zero_grad()
loss = (w - 3).pow(2).mean()
loss.backward()
optimizer.step()
print(step, w.item(), loss.item())
Change lr to 0.01, 0.5, 1.0, and 1.2.
Do not merely observe whether it works. Explain the behaviour from the update equation.
11. Shape Check
The parameter vector has shape
[P]
The gradient must have the same shape:
[P]
The update
parameter - scalar_learning_rate * gradient
therefore returns
[P]
A scalar learning rate changes magnitude, not dimensionality.
Later optimizers will effectively create different step sizes for different parameters, but the shape rule remains the same.
12. Break It
Try these experiments:
- Make the curvature in the first direction
5000instead of50. - Keep the same learning rate.
- Observe divergence.
- Reduce the learning rate until training becomes stable.
- Rescale the variable so the two directions have similar curvature.
- Compare the number of steps needed.
You are experimentally discovering conditioning.
13. Research Lens
The learning-rate problem is not a beginner-only issue.
Large-scale training still spends enormous effort on:
- optimizer choice,
- learning-rate schedules,
- warmup length,
- gradient clipping,
- normalization,
- curvature-aware updates,
- stability at extreme batch sizes.
The same question survives from a two-parameter parabola to frontier models:
How large a trustworthy update can we take from the information we have right now?
14. What You Should Now Understand
You should be able to explain:
- why the gradient alone is not enough,
- why curvature determines safe step size,
- why too-small learning rates waste time,
- why too-large learning rates oscillate or diverge,
- why ill-conditioned valleys cause zig-zagging,
- why schedules and warmup exist,
- why optimization is fundamentally a geometric problem.
Bridge to Chapter 025
We can now move parameters through a loss surface.
But neural networks do not contain one scalar weight. They contain vectors and matrices of weights.
If
what exactly does
mean?
And how can we derive it without differentiating every matrix entry one by one?
Next → Matrix Calculus for Neural Networks.