TL;DR
Training a model usually means finding weights that give a low loss on the training set. A model can reach a low training loss in many places, and some of those places generalize much worse than others. Sharpness-Aware Minimization (SAM) changes the target: it looks for weights whose whole small neighbourhood has low loss, so the loss does not climb steeply when the weights move a little. Each SAM step needs two gradient computations, one to find the worst nearby point and one to take the step from there. On image benchmarks the paper reports lower test error than standard training with the same models.
Builds on: Stochastic Gradient Descent, Empirical Risk Minimization, L2 Regularization, Taylor Series · Leads to: later work that treats the flatness of a minimum as a training target
Why it mattered
SAM is a drop-in change to the optimizer. The paper replaces the usual update with its own and keeps the model, data and learning-rate schedule. On CIFAR-10 with a WideResNet-28-10 trained for 200 epochs and basic augmentation, the paper reports 2.7 percent test error with SAM against 3.5 percent with standard SGD. On ImageNet, a ResNet-152 trained for 200 epochs reaches 18.5 percent top-1 error with SAM against 20.3 percent without it.
By late 2026 it had about 2,200 citations on OpenAlex. Its lasting contribution is the idea that a training loss can be shaped to care about curvature, at a cost cheap enough to use on large models.
The idea of flat minima is older. Hochreiter and Schmidhuber argued in the mid-1990s that flat minima generalize better. For two decades the idea was hard to use, because the sharpness measures were expensive and awkward to differentiate. In 2016 Keskar and colleagues reported that large-batch training tended to find sharper minima and generalized worse, which made sharpness a practical concern again. The SAM paper was posted to arXiv in October 2020 and gave an update rule that works with ordinary optimizers and scales to ImageNet-sized models.
The problem
A deep network has millions of weights, and its training loss is a non-convex surface. That surface has many minima. Some sit in wide, flat valleys and some in narrow, sharp ones, and several can have nearly the same training loss. The paper says these minima can differ a lot in test performance even when their training losses match.
Standard training minimizes the training loss and nothing else. Earlier work suggested that sharp minima generalize worse, but the methods that tried to find flat minima were hard to compute and differentiate through. The paper asks for a method that is cheap, scales to large models, and improves test accuracy on modern networks.
Two prerequisites matter here. The training loss is the average of a per-example Loss Function, and training follows its Gradient. The method also needs a small change of the weights measured with a length, so it uses an L2 norm.
How it works
Take a tiny model with one weight and a training loss that is a simple parabola, . The gradient is . Start at .
- Measure the slope where you are. The gradient at is . This is the step that standard Gradient Descent would take. Check: the loss here is , and it rises as moves away from .
- Find the worst nearby point. SAM asks: if I move the weight by at most a fixed distance , in the direction that raises the loss the most, where do I end up? For one weight the answer is to step along the gradient by the full distance: . The perturbed weight is . Check: the loss there is , up from .
- Measure the slope at that worse point. The gradient at is . This is the slope that matters. A sharp valley gives a steep slope here; a flat one would not.
- Update the original weight with that slope. With learning rate , the SAM update is . Plain SGD would have gone to . The tiny example is enough to see the rule: the step is taken from , but its size comes from the slope at the perturbed point.
The diagram shows the two passes that make up one SAM update.
flowchart LR A[weights w] --> B[gradient g at w] B --> C[perturb: w + rho times g over its length] C --> D[gradient at the perturbed point] D --> E[SGD step from w using that gradient] E --> A
The plot shows the same idea in one dimension: both curves have their minimum at , but the sharp one gains much more loss over the same step, so SAM is pushed toward the flat one.
- sharp minimum
- flat minimum
The math
The paper writes the training objective as a sum over the training set, , where is the vector of weights and is the loss on one example.
Step 2 in symbols: the worst point in a ball
SAM replaces with the worst training loss inside a ball of radius around :
and the paper minimizes . The second term is ordinary L2 Regularization with strength .
To find the inner maximum, the paper takes a first-order Taylor expansion of around : . The maximum over the ball is then attained by the vector of length that points along the gradient:
This is the step 2 formula in vector form. Each component of the gradient is scaled by the same factor, so the direction is kept and the length becomes .
Step 3 in symbols: the gradient used for the update
Differentiating the objective through would require second derivatives. The paper drops those terms and keeps only the gradient at the perturbed point:
The update then uses this vector as the gradient in ordinary SGD: .
In practice the paper uses minibatches. For each batch it computes on that batch, then the gradient at the perturbed weights on the same batch. Each update therefore costs two forward and backward passes. Let be the cost of one such pass: SGD costs per step and SAM costs . The paper compares the two methods at equal epoch counts, so its reported gains do not net out this extra cost.
Step by step with two weights
Take , , . Suppose the gradient at is and the gradient at the perturbed point is .
- The length of is .
- The perturbation is .
- Its length is , which is , as required.
- The perturbed weights are .
- The SAM update is .
- Interpretation: the second component moved by instead of , because the slope at the worse point was steeper. The step responds to the neighbourhood, not only to the current point.
Try it: with and , what is ? Answer: the length of is 10, so .
Results
The main results use the paper's own tables and numbers.
- CIFAR-10, WideResNet-28-10, 200 epochs, basic augmentation: SAM 2.7 percent error, SGD 3.5 percent. The absolute gain is points, a relative reduction of , about 23 percent.
- CIFAR-100, the same model and setting: SAM 16.5 percent error, SGD 18.8 percent, a gain of points.
- CIFAR-10, WideResNet-28-10, 1800 epochs, AutoAugment: SAM 1.6 percent, SGD 2.2 percent.
- ImageNet, ResNet-152: top-1 error at 200 epochs is 18.5 percent with SAM and 20.3 percent without; at 400 epochs it is 18.4 and 20.9.- Finetuning: SAM improves finetuned EfficientNet models on the paper's downstream tasks, and reports 0.30 percent error on CIFAR-10 and 11.39 percent on ImageNet in its finetuning table (Table 3).
- Label noise, CIFAR-10 with 80 percent of labels flipped: test accuracy is 77.9 percent for SAM and 26.2 percent for SGD. At 20 percent noise the values are 95.1 and 84.8.
- Hessian spectra (the paper's Figure 3): the largest eigenvalue at convergence is about 24 without SAM and about 1.0 with SAM. The ratio is up to 11.4 without SAM and 2.6 with it, so the ratio is about times smaller.
The limits are as important as the gains. The results are for image classification and finetuning on the benchmarks above, and the paper's own comparisons use its choice of models and augmentations. SAM costs two gradient computations per update, so it is not free. Its radius is a hyperparameter; the paper tunes it on a grid from 0.01 to 0.5 using a validation split, and reports 0.05 as a solid default. The paper also finds that the sharpness measure correlates better with generalization when computed over small groups of examples (-sharpness) than over the whole training set, which shows that flatness is useful but not a law. It is tempting to think SAM simply finds a minimum of the training loss faster; in fact it descends the worst loss in a small ball, so each update needs a second gradient at a point that the step does not start from.
Reading guide
- Section 1, Introduction. Needs Overfitting and the idea that flatness was linked to generalization. Read Figure 1 first.
- Section 2, the method. Needs Gradient, Taylor Series and Vector Norm. The derivation of is the step 2 walkthrough above. The second-order terms that the paper drops are discussed in its appendix.
- Section 3, empirical evaluation. Needs Data Augmentation and Label Smoothing. The tables are the results above; the label-noise comparison uses Mixup as a baseline.
- Section 4, sharpness and generalization. Needs Hessian Matrix and Eigenvalues and Eigenvectors for the spectra, and the -sharpness definition, which is a per-group version of the same quantity.
- Section 5, related work. Needs Dropout and Adversarial Training, which the paper compares against as other ways to regularize.
- Appendix A, PAC-Bayes bound. Optional. It needs the worst-case idea from Minimax Game and a formula for the KL divergence between Gaussians; skip it on a first read.
Check yourself
QuestionIn one sentence, what does SAM minimize instead of the plain training loss at the current weights?Show answer
QuestionFor the one-weight example L(w) = w^2 at w = 3 with rho = 0.5, what perturbed weight does SAM use, and why is the gradient there larger than 6?Show answer
QuestionA method needs two gradient computations per update. If an SGD run takes 100 epochs, roughly how many epochs of SAM would spend about the same compute, and how does the paper compare the two?Show answer
QuestionWhy might a model trained with SAM have a lower top Hessian eigenvalue than one trained with SGD, and what does the paper report?Show answer
QuestionA team sees that SAM improved test accuracy on its dataset but its training is now twice as slow. What trade are they making, and when is it worth it?Show answer
Sources
- Foret, Kleiner, Mobahi, Neyshabur, "Sharpness-Aware Minimization for Efficiently Improving Generalization," arXiv:2010.01412 (2020). https://arxiv.org/abs/2010.01412