Back to paths

Gradient Descent — What "Training" Actually Is

Every operational fact about training — why jobs run for weeks, why they checkpoint, why there's optimizer state eating HBM, why a run sometimes diverges into NaNs — falls out of one idea. Training is gradient descent, an iterative downhill loop. The learning rate is the control gain, with a stability band. For infra engineers, no calculus.

intermediate~12 min#math-infra#training#fundamentals
200Math of Learning (gradient descent)Lesson 1 of 4Show

Prerequisites: What Is a Tensor? — A Multidimensional Array, Tensor Shapes — Align to the Hardware Tile, or Pay in Padding


The one-line summary

Almost everything you'll operate about a training job — why it runs for weeks, why it checkpoints, why there's mysterious "optimizer state" eating HBM, why a run sometimes explodes into NaNs — falls out of a single idea: training is gradient descent. You don't need the calculus to operate it; you need the shape of the loop. Get that, and run length, stability failures, and resource footprint stop being magic.

What "learning" is

A model is just a big pile of tunable numbers — its weights. "Learning" means adjusting them. Strip away the math and it's four steps on repeat:

  1. Loss — one number that says how wrong the model currently is.
  2. Gradient — which way is downhill on that loss. (You use it as a direction; you never compute a derivative by hand.)
  3. Step — nudge the weights a little in the downhill direction.
  4. Repeat — thousands to millions of times, over mini-batches of data.

That's it. Picture a loss surface — the loss plotted against the weights, a landscape where height is how wrong the model is. The model "learns" by walking downhill toward the lowest point (the minimum).

Walk the whole loop once on a simple line fit — guess it by hand (the forward pass), hover a point to see its error (the loss), then let the optimizer train it down to a fit over epochs and predict a new value (inference):

Simulation: training-loop-explorer

The learning rate is the gain — and it has a stability band

The sets how big each step is. It behaves exactly like a control-loop gain:

  • too low — tiny steps, the loss crawls down; you burn compute making little progress;
  • in the band — the loss glides smoothly to the minimum (what you want);
  • too high — each step overshoots, the loss oscillates, and past a threshold it diverges to inf/NaN — the run is dead.

Drag the learning rate and watch the path on the loss surface and the loss-vs-step curve. Push it up and the path zig-zags, then flies off:

Simulation: gradient-descent-explorer

Momentum — keeping some velocity

Real training adds : each step carries a running average of past gradients, so it keeps moving in a consistent direction instead of zig-zagging across the steep walls of a narrow valley. It smooths the path and speeds convergence — at the cost of storing that running average for every parameter. That stored average is the first piece of , which is why the optimizer's footprint is several times the model's — roughly 16 bytes per parameter for Adam, vs 2 for the weights themselves. (The next lesson quantifies that bill.)

Why this matters

The loop is the operational story:

  • Long, stateful jobs. Training is iterative — thousands of steps, not one shot — so jobs run for days or weeks. That's why you checkpoint: a crash mid-run shouldn't restart from zero.
  • The NaN blow-up. When a run dies early with exploding loss, "is the learning rate too high?" is a real first question — an unstable loop, not a chip fault. You'll see it as the loss going to NaN/inf in the logs (or the job just crashing), so don't go chasing a hardware RMA.
  • The memory bill. Optimizer state (momentum and friends) is per-parameter, so it inflates the HBM footprint well past the weights alone — the capacity surprise the next lesson quantifies.

You won't set the learning rate — that's the ML team's dial. But knowing the run is a control loop with a stability band tells you why it diverges, why it's long, and why it's memory-hungry — which is most of operating it.

Put it together

Steps
  1. Find the stability band

    In the explorer, start low and raise the learning rate. Name the three regimes you pass through — crawling, gliding, diverging — and roughly where the band ends.

  2. Read the NaN

    Push the rate until the loss curve turns upward. Explain, in control-loop terms, what just happened and what you'd tell the team that owns the run.

  3. Use momentum

    Set a high-ish learning rate that zig-zags, then add momentum. Say what momentum changed about the path — and what it costs in memory.

Review

Flashcards1 / 4

What is training, in one loop?

Check yourself

Quick exam1 / 3 · 0 correct

A training run's loss explodes to NaN after a few steps. Most likely cause?

Your notes on this lesson