CASAM: Consistency-Anchored Sharpness-Aware Minimization for Improved Model Generalization

Chengli Tan, Tianyu Wang, Junmin Liu, Yong XuNeurIPS 2026

TL;DR

Why does Sharpness-Aware Minimization (SAM) generalize so much better than standard SGD? Conventional wisdom points to "flat minima," yet you can easily engineer flatter landscapes that generalize worse. This paper solves that paradox by showing that SAM has a built-in anti-overfitting compass—driven by "easy" examples pulling back against dominant gradient directions—and introduces CASAM, a nearly zero-overhead tweak that amplifies this effect to crush overfitting and label noise.

What Problem Does This Paper Address?

When training neural networks, SAM is famous for finding wide, flat valleys in the loss landscape rather than sharp ravines. It works via a two-step dance: first taking a tiny step uphill (gradient ascent) to find a local worst-case parameter perturbation, and then computing the downhill update (gradient descent) from that perturbed "adversarial" spot.

Most researchers attribute SAM’s generalization magic to implicit regularization—specifically, shrinking the gradient norm and the top eigenvalues of the Hessian (which measure landscape curvature).

Here’s the catch: flatness doesn't tell the whole story. During the uphill step, a mini-batch splits into "hard" examples ($\mathcal{B}^+$, where loss goes up) and "easy" examples ($\mathcal{B}^-$, where loss actually goes down). If you throw away the easy examples to save compute and optimize only on the hard ones, the model lands in an even flatter region (smaller Hessian eigenvalues)—yet test accuracy drops!

Figure 1: Easy examples from B−cannot be simply eliminated when trained with SAM. The adopted neural network is ResNet-56 and trained on CIFAR-10 for 200 epochs with a perturbation radius ρ = 0.05. (a) Evolution of the size of B+ and B−during training. Namely, how many examples of the mini-batch belongs to B+ and B−. (b) Top five eigenvalues of the Hessian for SAM using the mini-batch B and SAM only using the hard examples from B+. The average accuracy on the test set is also reported. It is worth noting that the performance deterioration is not due to the reduced mini-batch size (|B+| < |B|). As many studies (Keskar et al., 2017; He et al., 2019) suggest, smaller mini-batches introduce more gradient noise and tend to yield better generalization.

Flatness alone cannot explain why we need those easy examples. The authors set out to discover what SAM is secretly doing at the per-example level.

Methods

Normally, computing how much a single data point aligns with the overall mini-batch gradient is prohibitively expensive in SGD or Adam. However, because SAM already performs two forward-backward passes, we get extra geometric information for free.

The authors introduce gradient consistency, $\mathcal{C}(z)$, defined for an example $z$ as the change in its loss minus the Kullback–Leibler (KL) divergence between the model's predictive distributions before and after the uphill step. Remarkably, $\mathcal{C}(z)$ turns out to be a tight linear approximation of the inner product between that single example's gradient and the aggregate mini-batch gradient.

Figure 2: The gradient consistency C(z) linearly correlates with the inner product between the per-example gradient ∇fω(z) and the mini-batch gradient ∇FB(ω). In the middle and the terminal phase of training, a random mini-batch is selected to visualize this correlation. The y-axis represents the inner product multiplied by the factor ρ/∥∇FB(ω)∥2.

Building on this, the authors propose CASAM (Consistency-Anchored SAM). Instead of treating all examples equally during SAM's downhill step, CASAM reweights each example's loss using its gradient consistency:

  1. It passes $\mathcal{C}(z)$ through a smooth squeezing function—specifically arctan, which outperformed exponential functions like sigmoid because its gentler tails don't saturate as aggressively.
  2. It raises this term to a tunable exponent $\gamma$.

Setting $\gamma < 0$ rewards examples with low consistency (easy examples) and dampens high-consistency ones, intentionally widening the angle between the ascent and descent directions to prevent the network from memorizing noise.

Datasets

The authors evaluate CASAM across standard vision benchmarks, synthetic/real-world noisy datasets (no new benchmarks are introduced), and natural language tasks (detailed in their appendix):

  • Clean Vision: CIFAR-10, CIFAR-100, and ImageNet-1K.
  • Synthetic Noise: Binary Moon dataset (10% flipped labels) and CIFAR-10 corrupted with asymmetric and instance-dependent label noise (corruption rates from 10% to 70%).
  • Real-World Noisy Vision: Animal-10N, Food-101N, and Clothing1M.

Key Insights and Ideas

  • Sharpness has two parts: At the mini-batch level, SAM's sharpness approximately equals the gradient norm plus the KL-divergence between the current and perturbed predictions. Late in training, when gradient norms vanish, this KL term (which implicitly penalizes the Hessian) keeps SAM hunting for flat regions.
  • Easy examples are an anti-overfitting brake: For confident, easy examples, gradient consistency $\mathcal{C}(z)$ is negative—meaning their individual gradients point at an obtuse angle against the mini-batch gradient! Keeping them acts as a natural counterweight that stops the optimizer from over-committing to dominant, potentially noisy directions.
  • Universal self-damping: Across all examples (both easy and hard), $\mathcal{C}(z)$ decreases monotonically as model confidence grows. SAM naturally soft-dampens high-confidence updates, maximizing angular separation between individual and batch gradients.

Key Results

CASAM consistently improves generalization with virtually zero extra compute over standard SAM:

  • CIFAR-100: Beats SGD, SAM, and five recent SAM variants (including ASAM and EigenSAM) across ResNet-56 (75.89%), WRN-28-10 (84.12%), and PyramidNet-110 (85.06%).
  • ImageNet-1K: Boosts top-1 validation accuracy over vanilla SAM on ResNet-50 (from 76.19% to 76.73%) and ViT-S-16 (from 74.23% to 74.78%).
  • Heavy Label Noise: Under 50% asymmetric noise on CIFAR-10, CASAM jumps to 75.65% accuracy compared to SAM's 68.13%. Under 70% instance-dependent noise, it hits 46.25% versus SAM's 40.24%. On real-world noisy datasets (Animal-10N, Food-101N, Clothing1M), CASAM adds another 0.5–1% accuracy on top of SAM's 3–4% gains over SGD.

Limitations and Future Work

The authors do not include a dedicated limitations or future work section in the main text. However, two practical constraints are apparent from the methodology:

  • SAM's baseline cost remains: While CASAM adds almost no overhead beyond SAM, it still inherits SAM's fundamental drawback—requiring two gradient backpropagations per step (roughly $2\times$ the cost of SGD).
  • An extra knob to tune: CASAM introduces the hyperparameter $\gamma$ (the authors generally recommend $\gamma = -1$ or $-2$ when overfitting is a concern, though optimal values depend on whether the model is under- or over-fitting).

Summary updated

Abstract

Many studies argue that the success of sharpness-aware minimization (SAM) is due to the implicit regularization of the gradient norm or the eigenvalues of the Hessian. However, they cannot fully explain why the flatness-based measures do not always correlate well with generalization. For instance, we can easily construct a counterexample by only optimizing with hard examples. In this paper, we propose to resolve such a contradiction from the perspective of anti-overfitting. First, we show that the sharpness at the mini-batch level approximately equals the sum of the gradient norm and the Kullback–Leibler (KL) divergence between the predictive distributions evaluated at the current point and its adversary. Second, we show that the \emph{gradient consistency}, which approximately quantifies the inner product between the mini-batch gradient and the per-example gradient, decreases consistently during training. This result explains why SAM is less likely to suffer from overfitting. At last, building on these insights, we further introduce CASAM, an algorithm that reweights each example according to gradient consistency to enhance the generalization performance. Extensive experiments on popular benchmarks such as ImageNet-1K and Clothing1M corroborate its efficacy.
BibTeX
@inproceedings{tan2026casam,
  author = {Chengli Tan and Tianyu Wang and Junmin Liu and Yong Xu},
  title = {{CASAM: Consistency-Anchored Sharpness-Aware Minimization for Improved Model Generalization}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=WABAB6cGkw},
}
Figure