When Flatness Does (Not) Guarantee Adversarial Robustness

Nils Philipp Walter, Linara Adilova, Jilles Vreeken, Michael Kamp

Neural networks are notoriously brittle to adversarial examples—tiny, imperceptible input perturbations that can completely flip a model's prediction. To combat this, researchers have increasingly looked at the geometry of the loss landscape. A popular intuition suggests that models resting in "flat minima" (regions where the loss doesn't change much if the parameters are perturbed) are more robust and generalize better.

However, this connection has remained mostly informal. Adversarial robustness is fundamentally about perturbations in the input space, while flatness describes perturbations in the parameter space. This paper rigorously investigates this disconnect, mathematically formalizing the relationship between the two to answer a critical question: does a flat loss surface actually prevent adversarial perturbations from succeeding, or is the reality more complex?

Bridging Parameter Space and Input Space

To connect these two distinct spaces, the authors introduce several clever theoretical and empirical techniques. First, instead of defining adversarial examples purely by prediction flips, they define them by how much a perturbation increases the loss, allowing for smoother mathematical analysis.

Mapping parameter space flatness to input space geometry.

Next, they focus on the penultimate layer. The authors derive a closed-form expression for "relative flatness" (based on the trace of the Hessian matrix) specifically at this layer, mathematically proving that it largely dictates the curvature profile of the entire network.

Finally, to test flatness empirically without introducing confounding variables from complex training regimes like Sharpness-Aware Minimization (SAM), they employ a post-hoc weight scaling trick. By scaling the penultimate layer weights by a scalar $s$ ($w_s = s \cdot w$), they can artificially flatten the loss surface without changing the model's clean predictions. This isolates the exact effect of flatness on robustness.

Key Insights: Local Basins and the "Uncanny Valley"

The theoretical and empirical analyses reveal several crucial insights that challenge the simplistic view that "flatter is always better":

  • Flatness creates local "basins" of stability: The authors mathematically prove that lower sharpness guarantees a minimum radius in input space where the loss remains relatively constant. Flatness does provide robustness, but only locally.
  • Confidence dominates flatness: The derived formula for relative sharpness reveals a surprising inverse relationship with model confidence. When a model's softmax probability approaches 1.0, the sharpness drops to near zero.
  • The "Uncanny Valley" of adversarial examples: Because confidence flattens the loss surface, adversarial examples don't just exist in sharp, chaotic regions. As an attack pushes an input across a decision boundary, the sharpness spikes due to high uncertainty. However, once it crosses over, it descends into a broad, flat valley where the model is highly confident but completely wrong.
  • Flatness $\neq$ Correctness: Standard flatness metrics conflate the geometric stability of learned features with the raw, sometimes misplaced, confidence of the final classifier. Flat regions do not naturally correspond to correct generalizations.

Empirical Validation and Key Results

The theoretical claims were validated using standard image classification benchmarks (CIFAR-10, CIFAR-100) across architectures like ResNet-18, WideResNet-28-4, DenseNet-121, and VGG-11.

Empirical results demonstrating the relationship between weight scaling, loss increase during attacks, and the correlation of basin width to relative sharpness.

By scaling the weights to flatten the network, the authors showed that flatter networks dramatically reduce the loss increase during the early steps of a Projected Gradient Descent (PGD) attack. Furthermore, there is a clear correlation between basin width and relative sharpness.

Interestingly, this local stability can lead to gradient masking. A standard ResNet-18 ($s=1$) had 0% robust accuracy against a first-order PGD attack, while its artificially flattened counterpart ($s=100$) maintained 93% robust accuracy. However, the vulnerabilities still exist—attacks transfer 100% between the models. The flat geometry simply prevents the attack optimizer from finding them.

Tracking sharpness along a 10-step PGD attack empirically confirmed the "Uncanny Valley" effect: sharpness initially peaks as the attack starts, then drops to near-zero as the loss plateaus and the adversarial example is successfully found.

Limitations and Future Directions

While this work provides a rigorous framework for understanding flatness, the derived theoretical bounds are not practically tight enough to be used as certifiable robustness guarantees. Additionally, the analysis heavily abstracts earlier layers to focus on the penultimate layer.

Ultimately, the authors suggest that achieving true global robustness requires developing entirely new notions of flatness—metrics that can successfully separate the geometric stability of the feature extractor from the raw confidence of the classifier. They also provide preliminary evidence that sharpness could be used as a feature to detect adversarial examples, offering a promising new direction for defensive mechanisms.

Summary updated

BibTeX
@inproceedings{walter2026when,
  author = {Nils Philipp Walter and Linara Adilova and Jilles Vreeken and Michael Kamp},
  title = {{When Flatness Does (Not) Guarantee Adversarial Robustness}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=sptCQnKS9X},
}
Figure