Before you move a control in the demo, say what you expect to change.
Foundation reference
Loss Landscapes, Sharpness & Flat Minima
A loss landscape is the loss viewed as a function of the parameters. A minimum is sharp when the loss rises quickly as the parameters move away from it in some direction, and flat when it rises slowly in every direction. Keskar et al. (2017) found that large-batch training reached sharper minima and generalized worse than small-batch SGD in their experiments.
Study guide
Where to start
Sharp and flat minima are usually drawn in two dimensions; what does sharpness mean in millions of dimensions, where the curvature differs greatly from one direction to another?
How to study this pagePredict · Check · Generalize · Continue
Compare what the demo shows with the key equation and with the papers cited below.
Identify the part of the idea that survives a change of notation or model, so you can recognize it in another paper or system.
The newer notebook covers the same concept and has an interactive demo.
Why It Matters for Modern Models
- A loss landscape is the loss viewed as a function of the parameters. A minimum is sharp when the loss rises quickly as the parameters move away from it in some direction, and flat when it rises slowly in every direction. Keskar et al. (2017) found that large-batch training reached sharper minima and generalized worse than small-batch SGD in their experiments.
- Sharpness alone does not decide generalization, because rescaling a network can make a flat minimum sharp without changing the function it computes (Dinh et al., 2017).
- SAM improved test accuracy on image-classification benchmarks and when fine-tuning pretrained models, at roughly twice the cost per step (Foret et al., 2021).
Questions to Think About
- How does mode connectivity (separate minima joined by low-loss paths) relate to flatness and to weight averaging?
Interactive Demos
Core Math
If you prefer intuition first, try the demos above, then come back for the math.
Sharpness-aware minimization (SAM) objective:
In practice (for ):
- Approximate the worst-case perturbation with one gradient step:
- Update using the gradient at the perturbed weights:
Each SAM step therefore needs two gradient computations.
On the theory side, Kawaguchi (2016) proved that every local minimum of a deep linear network is a global minimum, and extended a similar result to nonlinear networks under strong simplifying assumptions.