Home / Deep Learning

Optimizers & The 3D Loss Landscape

By Updated

Visualize how different optimization algorithms navigate complex terrain, escape local minima, and find the global minimum. Run multiple in parallel to observe realistic relative speeds!

0.1x

Optimization State

Global Minimum is at (0, 0) Watch out for Local Minima!

Overview

Visualize how different optimization algorithms navigate complex terrain, escape local minima, and find the global minimum.

In this guide
  1. What the terrain is made of
  2. Saddles matter more than local minima
  3. The loss surface as a landscape
  4. How each optimiser behaves on that landscape
  5. Saddle points, not local minima
  6. Try this above
  7. What often goes wrong
  8. In one line
  9. Sharp and flat minima
  10. Visualising a real loss surface
  11. Four surfaces that break four other optimisers
  12. Questions people ask
  13. Recap in one screen

Optimizers in 3D: A Practical Guide

A loss surface in three dimensions is the only version you can actually look at. The features that decide which optimiser wins — ravines, plateaus, saddle points — are all visible here.

What the terrain is made of

  • Ravines — steep in one way, nearly flat in another. Plain SGD ricochets between the walls.
  • Plateaus — large regions where the gradient is tiny. Progress crawls since there is almost nothing to follow.
  • Saddle points — the gradient is close to zero but you are not at a min: the surface curves up in some ways and down in others.

At a saddle point, plain SGD stalls since the gradient is near zero in each way — momentum. Or a per-param scaling like Adam, is what pushes through. A ravine (a long narrow valley) is the other classic failure mode: the gradient points across the valley rather than along it. So plain SGD oscillates side to side instead of progressing toward the min. Momentum damps the oscillation by averaging past gradients. And RMSprop scales each param's learning rate by the recent magnitude of its gradient. It shrinks the step across the valley and lets the step along it dominate. Adam mixes both: it carries a momentum term and a per-param scaling term, with bias correction for the first few steps. The 3D loss surface makes these gaps visible in a way that 2D curves cannot — you can see the trajectory spiralling into a bowl, overshooting a ridge, or threading through a saddle. This page plots three loss surfaces (a bowl, a ravine, and a saddle), runs SGD, momentum, RMSprop, and Adam on each, and shows the trajectory and convergence speed side by side.

Saddles matter more than local minima

The folk explanation of training failure is "it got stuck in a local min". In high dimensions that is mostly wrong. For a point to be a local min, the surface must curve upward in each way at once — and with millions of params that is vanishingly unlikely. Saddle points, where it curves up in some ways and down in others, are enormously more common.

This is a real gap. A local min is a trap. A saddle is not — there is a way down. And an optimiser with momentum carries enough velocity from earlier steps to keep moving across the flat region until it finds one.

The loss surface as a landscape

Picture two weights on the horizontal axes and the loss on the vertical one. Training is a ball rolling downhill on that surface. And the optimiser decides how the ball moves.

Real networks have millions of weights. So the surface is millions of dimensions rather than two. The picture is still useful, since the features that make optimisation hard are visible in three dimensions:

  • Ravines — steep in one way, nearly flat in another. Plain gradient descent zigzags across the steep way and crawls along the flat one.
  • Saddle points — downhill in some ways, uphill in others, with a gradient of zero at the centre. In high dimensions these vastly outnumber local minima, since it is improbable for millions of curvature signs to agree.
  • Plateaus — large flat regions where gradients are tiny and progress stalls.
  • Sharp versus flat minima — both fit the training data. Flat ones tend to generalise better, since a small shift in the weights (or in the data) changes the loss less.

How each optimiser behaves on that landscape

Plain SGD takes a step right downhill, scaled by the learning rate. In a ravine that means oscillating across the narrow way while barely advancing along the valley floor.

Momentum accumulates velocity, so the oscillations partly cancel and the consistent downhill way builds speed. It is the gap between a ball on a rough surface and one with mass.

Adam gives each weight its own effective step size, dividing by the square root of its recent squared gradients. Weights on flat ways get more steps and weights on steep ones get less. It reshapes the ravine into something closer to a bowl.

OptimiserIn a ravineOn a plateauNear a saddle
SGDZigzags slowlyStallsCan stall
SGD + momentumAdvances along the valleyCoasts throughCoasts through
AdamAdvances directlyAmplifies small gradientsEscapes readily

That plateau row explains a real advantage of adaptive ways: dividing by a small accumulated gradient magnitude raises the step. So Adam keeps moving where SGD would sit still.

Saddle points, not local minima

The old fear was that gradient descent would get stuck in bad local minima. High-dimensional geometry says otherwise.

For a stationary point to be a local min, the curvature must be positive in each way. With ten million params, that needs ten million signs to agree. It is vanishingly unlikely. Almost each point where the gradient vanishes is a saddle — downhill in at least one way.

That is good news, since saddles are escapable. The stochastic noise from mini-batches is often enough to push the net off the ridge and onto a descending path. It is one reason mini-batch training generalises better than full-batch.

It also reframes what training is doing: not searching for a unique global min. But descending through a field of many near-equivalent good solutions, most of which are fine.

Try this above

  1. Run SGD (Red) alone and watch it stall when it reaches a flat region — near-zero gradient means near-zero step.
  2. Switch to Momentum (Blue) from the same start. It coasts across the flat section on accumulated velocity.
  3. Select All (Check) and note the arrival order, then change Learning Rate and see whether the order holds. It often does not.
  4. Slow Sim Speed right down at the moment each optimiser crosses the ridge — that is where the gaps are widest.

What often goes wrong

Over-reading the picture. This surface has two params. A real network has millions. And its loss landscape has properties that genuinely do not exist in 3D. Use this to build intuition about momentum and adaptive step sizes. Do not use it to conclude anything about how many minima a real network has.Judging an optimiser from one starting point. Change where the run begins and the ranking often changes with it. A single trajectory is an anecdote.

In one line

The shape of the surface, not the cleverness of the algorithm, decides which optimiser looks good.

Sharp and flat minima

Two solutions can fit the training data equally well and behave very differently on new data.

A sharp min is a narrow crevice: move the weights slightly and the loss rises steeply. Since the test distribution differs slightly from the training one, that sensitivity translates into worse test performance.

A flat min is a broad basin: nearby weights are almost as good. So a small mismatch between train and test costs little.

A few observed behaviours follow from this:

  • Small batches generalise slightly better since their gradient noise makes it hard to settle into a narrow crevice.
  • Very large batches sometimes generalise worse. And techniques like LARS and longer warm-up exist to counter it.
  • Weight averaging (SWA) averages weights from a few late-training points, landing nearer the centre of a basin than any individual point.
  • Sharpness-aware minimisation (SAM) clearly penalises sharpness by taking a step towards the worst nearby point before updating.

Visualising a real loss surface

You can plot the field of an actual network. And the pictures are informative.

Take a trained net's weights, pick two random ways in weight space. And test the loss on a grid of small perturbations along them. Plotting that grid gives a two-dimensional slice through a million-dimensional surface.

What such plots reliably show: networks without skip connections have chaotic, spiky surfaces. Networks with them are dramatically smoother. That is a fairly direct visual explanation of why residual connections make deep networks trainable. And it is one of the more satisfying results in the area.

The caveat is that a two-dimensional slice of a million-dimensional surface can be misleading. Treat these plots as intuition, not proof.

Four surfaces that break four other optimisers

A bowl, a ravine, a saddle and a plateau. Each one defeats a other optimiser. And running all four on all four shows why there is no single right answer.

example_01.pyNumPy
Output

Now read the table surface by surface to see what each one reveals about optimiser design.

example_02.pyNumPy
Output

The saddle and plateau are the surfaces that split adaptive ways from plain SGD.

example_03.pyNumPy
Output

Questions people ask

Does the optimiser find the global min? No. And it does not need to. High-dimensional landscapes have vast counts of near-equivalent good solutions.

Why does momentum help? It averages recent gradients. So consistent ways accumulate and oscillations cancel — just what a ravine needs.

Are local minima a problem? Rarely. Saddle points and plateaus are the real obstacles in high dimensions.

Should I use a large batch to get a cleaner gradient? A cleaner gradient is not automatically better — the noise helps escape saddles and avoid sharp minima. Scale the learning rate if you do increase the batch.

What is the gap between the learning rate and momentum? The learning rate is how far to step. Momentum is how much of the last way to keep.

Can I see whether my min is flat? About — perturb the weights slightly and measure how much the loss rises. Large raises mean a sharp min.

Recap in one screen

  • Loss landscapes have ravines, plateaus and saddles. The optimiser's job is to navigate them.
  • Momentum damps oscillation across a ravine. Adaptive ways rescale each way.
  • In high dimensions almost each zero-gradient point is a saddle, not a local min — and noise escapes them.
  • Flat minima generalise better than sharp ones. It is why small batches and weight averaging help.
  • Skip connections visibly smooth the surface. It is a direct explanation of why they work.

Recall check

0 of 4

Say the answer out loud before you reveal it — recalling it is what makes it stick, and rereading it is not.

  1. What is meant by “Small batches generalise slightly better” here?

  2. What is meant by “Very large batches sometimes generalise worse” here?

  3. What is meant by “Weight averaging” here?

  4. What is meant by “Sharpness-aware minimisation” here?

Cheat sheet

Optimizers in 3D

Race SGD, Momentum, RMSprop and Adam across a 3D loss landscape and watch which of them escape local minima and which get stuck.

DEEP LEARNING · vizlearn.in/deep_learning/optimizers_in_3d.html

Further reading

About the author

Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.