Sharpness-Aware Minimization
Rather than just seeking a low point on the loss surface, this training method deliberately seeks a low point that stays low even if the weights are nudged slightly — because those flatter valleys tend to generalize better.
Prerequisites: Gradient Descent, Overfitting
Two models can reach the exact same training loss and yet perform very differently on new data. One clue for why: not every point at the bottom of a loss surface is equally trustworthy. A narrow, sharp valley means the loss shoots back up if the weights are perturbed even slightly — which is roughly what happens when you move from training data to slightly-different test data. A wide, flat valley means the loss barely changes under that same perturbation. Ordinary gradient descent has no preference between the two; it just walks downhill and stops wherever the gradient is zero. Sharpness-Aware Minimization (SAM) changes the objective itself to actively prefer the flat kind of minimum.
The analogy: parking on a plateau, not a ledge
Imagine parking a car on a hillside with an unreliable handbrake. A spot at the bottom of a narrow ravine looks perfectly flat right where you park, but nudge the car a few inches and it's suddenly rolling downhill fast. A spot on a broad, gently-sloped plateau looks similarly flat, but a few inches in any direction it is still roughly as flat. If you don't know exactly where the car will end up — because the ground shifts overnight, the way test data differs a little from training data — the plateau is the safer choice, even though both spots looked equally good from directly overhead.
From "loss here" to "worst loss nearby"
Ordinary training minimizes the loss at the current weights . SAM instead minimizes the worst loss found within a small neighborhood of radius around :
In words: instead of asking "how low is the loss right here," SAM asks "how low is the loss at the worst nearby point I could be nudged to," and minimizes that worst case. A sharp minimum has a bad worst-case neighbor nearby; a flat minimum's neighbors are nearly as good as the point itself, so the worst case is barely worse.
Computing the exact worst-case point is expensive, so SAM approximates it with one extra gradient step: first take a small step in the direction of the current gradient (call this the adversarial point , the direction most likely to be the "worst nearby" one), then compute the real gradient update using the gradient measured at that perturbed point rather than at itself.
Worked example 1: a 1D sharp valley
Suppose near a candidate minimum the loss locally looks like (a sharp, narrow bowl) for the sharp candidate, versus (a wide, shallow bowl) for the flat candidate, both with minimum value at . Perturb both by : the sharp bowl's loss becomes ; the flat bowl's becomes — twenty-five times lower. Both minima look identical if you only check the loss exactly at ; SAM's max-over-a-neighborhood objective is what distinguishes them, correctly favoring the flat one.
Worked example 2: the two-step update
Say the current gradient at weight is , and the perturbation radius is . SAM's adversarial point is (for a single weight, the unit direction of the gradient is just its sign). Suppose the gradient measured at this perturbed point turns out to be (steeper here — evidence of a sharper local slope). With learning rate , the actual weight update uses , not the original : . Using the sharper gradient found at the perturbed point pushes the weight further away from this fragile region than the original, gentler gradient at would have.
Drag the explorer's parameters to compare a smooth convergence path against a path that overshoots into a narrow dip — SAM's whole purpose is to steer the optimizer away from exactly those narrow dips.
What this means in practice
SAM adds real cost — roughly double the gradient computations per step, since it needs one gradient to find the adversarial point and a second at that point — and requires tuning . In exchange it shows consistent generalization gains across image and language models, especially when training data is limited or noisy.
SAM minimizes the worst loss found in a small neighborhood around the current weights, not just the loss at the current weights, which steers training toward flat minima that tend to generalize better than sharp ones with the same training loss.
Practice
- A sharp bowl is and a flat bowl is . Compare their loss at .
- Why does SAM need two gradient computations per step instead of one?
- In one sentence, why might SAM matter more when training data is small or noisy?
SAM is not a way to lower training loss faster — it often trains a bit slower and can even settle at a slightly higher training loss than plain SGD or Adam would reach. The point is never training-loss speed; it's that the minimum it settles into tends to generalize better to unseen data, which is a different, and often more useful, thing to optimize for.
Related concepts
Practice in interviews
Further reading
- Foret et al., Sharpness-Aware Minimization for Efficiently Improving Generalization (2021)