← All Posts
Math · Numerical Optimization

Optimizer Geometry: From Gradient Descent to AdamW

Before you start: Gradients and gradient descent.

A gradient tells you which direction locally increases the objective fastest under the ordinary Euclidean geometry. It does not tell you how far to travel. On a narrow valley, one coordinate can tolerate a large step while another becomes unstable. Optimizers differ in how they use history and scale to choose that motion.

01Positionx=3, y=2
02Gradient(x,10y)=(3,20)
03GD step, η=0.1(3,2)−0.1(3,20)
04New position(2.7,0)
The steep y direction changes ten times faster than x for the same coordinate displacement.
Compare actual updates on f(x,y)=(x²+10y²)/2 from (3,2). Choose an optimizer and move the iteration slider; the path is computed in the browser, not a benchmark claim.

A stability condition you can derive

For $f(x)=\tfrac12ax^2$ with $a>0$, gradient descent gives $x_{t+1}=(1-\eta a)x_t$. Convergence requires $|1-\eta a|<1$, or $0<\eta<2/a$. Larger curvature permits a smaller stable step. For a positive-definite quadratic with Hessian H, the largest eigenvalue controls this upper bound.

In f(x,y)=(x²+10y²)/2, a single learning rate must respect the curvature 10 along y. The shallow x direction then progresses relatively slowly. Feature scaling, preconditioning, and adaptive methods all try to make the optimization geometry easier, though they do so differently.

Momentum remembers directions

$$m_t=\beta m_{t-1}+(1-\beta)g_t,\qquad \theta_{t+1}=\theta_t-\eta m_t.$$

This exponential-average convention smooths gradients. Some implementations omit the factor 1−β and absorb it into the learning rate; the two conventions need matched scaling before comparison. Consistent directions accumulate, while rapidly alternating components partially cancel. Momentum can accelerate progress but can also overshoot; it does not remove the need to tune the step size.

Adam scales coordinates using their recent squared gradients

$$m_t=\beta_1m_{t-1}+(1-\beta_1)g_t,\quad v_t=\beta_2v_{t-1}+(1-\beta_2)g_t^2.$$
$$\widehat m_t=\frac{m_t}{1-\beta_1^t},\quad \widehat v_t=\frac{v_t}{1-\beta_2^t},\quad \theta_{t+1}=\theta_t-\eta\frac{\widehat m_t}{\sqrt{\widehat v_t}+\epsilon}.$$

Squares, division, and square roots are coordinatewise. The bias corrections compensate for moments initialized at zero. On the first step with a nonzero gradient, the corrected moments are g and g², so the update is approximately −ηsign(g), ignoring ε. Adam therefore changes the direction relative to raw gradient descent; it is not just smoothing the same vector.

The second moment is an uncentered squared-gradient average, not the variance unless the mean is also accounted for. It is not the Hessian. It changes sensitivity to coordinate scaling and gradient history, but does not encode full cross-coordinate curvature. Two parameters with correlated gradients still have separate denominators.

AdamW separates shrinkage from the adaptive gradient

$$\theta_{t+1}=(1-\eta\lambda)\theta_t-\eta\frac{\widehat m_t}{\sqrt{\widehat v_t}+\epsilon}.$$

This displayed AdamW-style step applies weight shrinkage separately from the loss gradient. Adding λθ to the gradient instead sends that term through Adam’s moments and coordinate scaling. Those operations are generally different. Specify which parameters decay; biases and normalization parameters are often handled separately according to the training recipe.

Memory comparisons also depend on parameter, gradient, and optimizer-state dtypes; this table counts logical buffers only.
MethodPersistent state per parameterMain control
SGDNone beyond the parameterLearning rate
MomentumOne first-moment bufferLearning rate and momentum
Adam/AdamWFirst and second momentsRates, moment decay, epsilon, decay policy

Compare optimization fairly

Use the same initialization, data order, objective, and batch definition. Tune each optimizer on validation under a declared budget. Plot objective versus steps and versus wall-clock time: a costly step can win per iteration and lose per second. Across stochastic runs, show variability rather than selecting the best seed.

Monitor update norm relative to parameter norm, gradient norm, loss spikes, and validation quality. A stable training loss does not prove useful generalization. If changing the optimizer also changes batch size, precision, or regularization, report those changes instead of attributing everything to the update rule.

Check your understanding: Does Adam’s second-moment buffer estimate the Hessian?

No. It tracks coordinatewise squared gradients. Curvature methods use derivatives or approximations with a different mathematical meaning.

Sources and further reading