Learning LabExplorable explanations
โ† All artifacts
Machine Learning

Optimizer Race

Drop four optimizers on the same loss surface from the same point and race them. Watch momentum carry through a ravine and Adam rescale each axis while plain SGD crawls or oscillates.

optimizationgradient-descentadammomentum
LiveInteractive ยท drag, toggle, run it
Optimization, computed live

Optimizer Race

Four optimizers start at the same point and read the same analytic gradient, then step in lockstep down a real 2D loss surface. The only difference between the paths is the update rule. Click anywhere on the surface to drop a new start and watch them relaunch.

Surface:

An ill-conditioned bowl, two hundred times steeper across one axis than along the other. At the default rate, which sits right at SGD's stability edge for the steep axis, plain SGD oscillates and stalls while the others descend cleanly. One shared rate cannot serve both axes, which is exactly what per-dimension scaling fixes.

SGDMomentumRMSPropAdam
step 0
0.010
Shared by all four. Raise it until SGD overshoots the ravine walls and diverges.
0.90
Friction for Momentum's velocity. Higher carries more speed along the valley.
0.90
Decay of Adam's first moment, its smoothed gradient direction.
0.9990
Decay of the squared-gradient cache that rescales each axis.

Adam's second moment uses beta2 = 0.999, eps = 1e-8. Changing any slider relaunches the race from the current start so the comparison stays fair.

Live standings
SGDloss 84.380(-2.60, 0.90)lowest
Momentumloss 84.380(-2.60, 0.90)lowest
RMSProploss 84.380(-2.60, 0.90)lowest
Adamloss 84.380(-2.60, 0.90)lowest

On the ravine, let it run: Momentum, RMSProp, and Adam all reach a far lower loss than plain SGD in the same number of steps. At this rate SGD sits right at its stability edge for the steep axis, so it oscillates across the valley and its loss plateaus while the others slide down to the floor.

The four update rules
SGD
x -= lr * g
Momentum
v = mu*v - lr*g; x += v
RMSProp
c = rho*c + (1-rho)*g^2; x -= lr*g/(sqrt(c)+eps)
Adam
m,v moments, bias-corrected; x -= lr*mhat/(sqrt(vhat)+eps)

Plain SGD takes a fixed fraction of the raw gradient, so in a ravine it must keep the step small enough to not blow up on the steep axis, which leaves it crawling on the flat one. Momentum accumulates a velocity that averages out the side-to-side gradient and keeps the consistent down-valley component, so it powers through. RMSProp divides each axis by the running size of its own gradients, shrinking the step where gradients are large and growing it where they are small, which evens out the conditioning. Adam combines both: a momentum-like first moment for direction and an RMSProp-like second moment for per-axis scale, with a bias correction so the early steps are not damped toward zero.