Gradient descent, as a race

Training a model means walking downhill on its loss. Each ball below starts at the same spot and only ever feels the slope under its feet. Plain SGD, Momentum and Adam take different paths. Click anywhere on the map to move the start point.

step 0

Lighter means lower loss; the ring is the start.

What each rule does

SGD: w -= lr * slope. Steps are big where it's steep and tiny where it's flat. In a narrow valley it bounces between the walls.

Momentum: keeps a running velocity, v = 0.9·v + slope; w -= lr·v. Bounces cancel out and the downhill part adds up, like a heavy ball.

Adam: momentum plus a per-direction step size: it divides by the typical slope size in each direction, so steep and flat directions move at similar speeds. It's what TinyGPT in this lab uses.

In a real model there are thousands to billions of directions instead of 2, but each weight feels exactly this.