The Loss Landscape: Flat vs Sharp Minima
Two trained models can have identical training loss and still behave completely differently under small perturbations, because one sits in a wide, gentle valley of the loss surface and the other sits in a narrow, steep-walled canyon.
Prerequisites: Gradient Boosting as Functional Gradient Descent, The Bias-Variance Decomposition
Two trained models can report the exact same training loss down to the fourth decimal place and still be dramatically different in a way that number completely hides: what happens to the loss if the weights are nudged just slightly, by the kind of tiny perturbation that live deployment always introduces — a slightly different training window, floating-point rounding on different hardware, one more day of data. One model might barely notice; the other might fall apart. The difference is not in where the minimum sits, but in what shape the loss surface has around it, and that shape has a name: flat versus sharp.
The analogy: a wide bowl versus a narrow canyon
Picture two valleys, both with their lowest point at exactly the same elevation. One is a wide, gently sloped bowl — walk a hundred meters in any direction from the bottom and you have only climbed a few meters. The other is a narrow canyon with near-vertical walls — walk just ten meters from the bottom and you have already climbed as high as the bowl's hundred-meter walk got you. A ball resting at the bottom of either valley is equally "at the minimum," but a small earthquake that jostles the ball ten meters in a random direction leaves the bowl's ball nearly where it started and sends the canyon's ball rocketing up a wall. Trained model weights sitting at the bottom of a loss landscape behave exactly like this. The "earthquake" is anything that perturbs the weights slightly after training — quantization, hardware differences, or simply evaluating on data drawn from a very slightly different distribution than the training set.
Measuring sharpness with the Hessian
Near a minimum , the loss surface can be approximated by a second-order Taylor expansion — a curved bowl shape, described entirely by the loss's second derivatives:
In words: the loss at a point away from the minimum is approximately the loss at the minimum itself, plus a correction term built from , the Hessian — the matrix of every second derivative of the loss with respect to every pair of weights. is just the small perturbation vector: how far, and in which direction, the weights have been nudged. The Hessian's eigenvalues measure exactly how steeply the bowl curves along each of its natural axes — a large eigenvalue means the loss shoots up fast for a perturbation along that direction (a canyon wall); a small eigenvalue means the loss barely moves (the bowl's gentle floor). "Sharp minimum" is shorthand for "the Hessian has large eigenvalues somewhere"; "flat minimum" means all its eigenvalues stay small.
Worked example 1: the same perturbation, two very different penalties
Simplify to one weight, with two candidate loss shapes that both reach zero loss at :
Both are perfect, zero-loss fits at — indistinguishable by training loss alone. Now perturb by just , to :
The identical nudge costs the sharp minimum 25 times more loss than the flat minimum. If represents a model weight and the perturbation represents anything that shifts it slightly at deployment time — a slightly different retraining window, numerical rounding, a marginally different data distribution — the sharp-minimum model's error explodes while the flat-minimum model barely notices, even though both scored identically during training.
Worked example 2: sharpness is directional
With two weights, curvature can differ by direction. Take , which has Hessian — a diagonal matrix whose eigenvalues, and , sit directly on the diagonal because the two weights don't interact in this loss.
Perturb alone by : .
Perturb alone by : .
The same-size nudge costs 100 times more loss along the direction than along — exactly the ratio of the two eigenvalues. A real network's loss surface has thousands of these directions at once, most of them flat, a handful of them sharp; "how sharp is this minimum" really means "how large is the largest Hessian eigenvalue," because that single steepest direction is where a small perturbation does the most damage.
The explorer above shows a matrix stretching a circle into an ellipse along its eigenvector directions — exactly the shape of a Hessian's curvature. A long, thin ellipse (one large eigenvalue, one small one) is a sharp minimum in one direction and a flat one in another, just like worked example 2's -to- ratio; a nearly circular ellipse (eigenvalues close together and small) is a uniformly flat, robust minimum.
Two minima with identical training loss can have completely different curvature around them. Sharpness is measured by the Hessian's eigenvalues — large eigenvalues mean a small nudge to the weights causes a big jump in loss; small eigenvalues mean the model is robust to that same nudge.
What this means in practice
Flat minima are widely believed to generalize better, because the small, unavoidable mismatch between a training distribution and the true live distribution acts exactly like the perturbation in the formula above — a flat minimum absorbs that mismatch gracefully, a sharp one amplifies it into a large error. This is one of the leading explanations for why training with very large batch sizes tends to produce models that generalize worse than the same model trained with smaller batches: large batches give a smoother, more precise gradient estimate at every step, which lets optimization settle into narrow, sharp minima that a noisier small-batch gradient would have jumped straight past on its way to a wider, flatter one. It is also the practical argument behind techniques like stochastic weight averaging and adding noise during training — both nudge the optimizer away from sharp minima and toward flatter, more forgiving ones.
Practice
- A model has Hessian eigenvalues at one candidate minimum and at another, with identical training loss at both. Which minimum would you expect to generalize better on live data, and why?
- Using , write the loss increase from a perturbation of size as a function of , and explain what larger means physically.
- Why might training with a much larger batch size produce a sharper minimum than training with a small batch size, given the same total number of training examples seen?
Sharpness as defined above is not invariant to how the model is parameterized — simply rescaling a layer's weights (multiplying one layer's weights by 10 and dividing the next layer's by 10, which leaves every prediction completely unchanged) can turn a "sharp" minimum into a "flat" one by this Hessian-eigenvalue measure, without the model's actual behavior changing at all. This is a well-known subtlety, not a minor technicality: it means raw eigenvalue magnitude alone is not a rigorous, parameterization-independent proof of good generalization, only a strong empirical correlate observed across many real training runs. Treat "flat minima generalize better" as a useful heuristic that guides training choices like batch size, not as a theorem you can invoke to prove a specific model will generalize well.
Related concepts
Practice in interviews
Further reading
- Keskar et al., On Large-Batch Training for Deep Learning: Generalization Gap and Sharp Minima (2017)
- Hochreiter & Schmidhuber, Flat Minima (1997)