FAM: Relative Flatness Aware Minimization

Linara Adilova, Amr Abourayya, Jianning Li, Amin Dada, Henning Petzka, Jan Egger, Jens Kleesiek, Michael Kamp

Abstract: Flatness of the loss curve around a model at hand has been shown to empirically correlate with its generalization ability. Optimizing for flatness has been proposed as early as 1994 by Hochreiter and Schmidthuber, and was followed by more recent successful sharpness-aware optimization techniques. Their widespread adoption in practice, though, is dubious because of the lack of theoretically grounded connection between flatness and generalization, in particular in light of the reparameterization curse—certain reparameterizations of a neural network change most flatness measures but do not change generalization. Recent theoretical work suggests that a particular relative flatness measure can be connected to generalization and solves the reparameterization curse. In this paper, we derive a regularizer based on this relative flatness that is easy to compute, fast, efficient, and works with arbitrary loss functions. It requires computing the Hessian only of a single layer of the network, which makes it applicable to large neural networks, and with it avoids an expensive mapping of the loss surface in the vicinity of the model. In an extensive empirical evaluation we show that this relative flatness aware minimization (FAM) improves generalization in a multitude of applications and models, both in finetuning and standard training.

Introduction

A persistent observation in deep learning is that models converging in "flat" regions of the loss landscape—where small perturbations to weights do not significantly change the loss—tend to generalize better to unseen data. While this has inspired techniques like Sharpness-Aware Minimization (SAM), a significant theoretical hurdle remains: the "reparameterization curse." In networks using ReLU activations, weights can be rescaled across layers to produce identical outputs (and thus identical generalization) while drastically altering traditional mathematical measures of flatness.

Furthermore, calculating the full Hessian matrix (second derivatives) for modern, massive networks is computationally prohibitive. Relative Flatness Aware Minimization (FAM) addresses these issues by introducing a theoretically grounded flatness measure that is invariant to reparameterization and computationally efficient.

Methodology

FAM functions as an explicit regularizer added to the standard loss function. Its efficiency stems from several key innovations:

  • Single-Layer Hessian Focus: Rather than assessing the entire network, FAM targets the "relative flatness" of a single layer, typically the penultimate or bottleneck layer. Theoretical evidence suggests that enforcing robustness at this critical feature layer encourages the entire network to learn robust representations.
  • Direct Gradient Calculation: By targeting only one layer, the authors analytically derived the gradient of the regularizer, allowing for direct optimization without the need for expensive double backpropagation through the entire architecture.
  • Hutchinson's Approximation: To handle very large layers, FAM utilizes Hutchinson’s method—a randomized algorithm—to efficiently approximate the trace of the Hessian using the layer's weight norm.

Experimental Results

The authors evaluated FAM across vision, medical imaging, and natural language processing tasks.

Vision Benchmarks

FAM consistently matched or outperformed standard training and SAM across several standard datasets. Notably, on CIFAR100 using an EfficientNet-B7 backbone, FAM achieved an accuracy of 87.2%, a significant improvement over the 84.48% baseline.

Comparison of classification accuracy across vision datasets.

Natural Language Processing

Fine-tuning BERT on the Recognizing Textual Entailment (RTE) dataset is notoriously unstable. FAM improved average accuracy from 67.36% to 69.82%. Crucially, FAM visibly smoothed the validation loss curve, preventing the erratic spikes often seen during baseline fine-tuning.

Evaluation loss curves for FAM vs. baseline on the RTE dataset.

Medical Shape Reconstruction

In a 3D skull reconstruction task characterized by low data and high complexity, standard models often overfit by memorizing specific defects. FAM regularization prevented this "niche overfitting," allowing the model to learn underlying anatomy and improving metrics like the Dice Similarity Coefficient (DSC) and Hausdorff distance.

Key Insights and Discussion

The success of FAM suggests that regularizing a single layer is sufficient to nudge the entire network toward better generalization. Because FAM is based on relative flatness, it accounts for weight scale and remains immune to the reparameterization curse, aligning empirical optimization with theoretical generalization bounds.

While FAM is significantly faster than full-network Hessian methods, it does introduce a computational overhead of approximately 20% to 40% compared to vanilla training. Future work will explore optimal layer selection for regularization and test the theoretical assumptions of the method across a broader range of complex tasks.

Summary updated

BibTeX
@inproceedings{adilova2023fam,
  author = {Linara Adilova and Amr Abourayya and Jianning Li and Amin Dada and Henning Petzka and Jan Egger and Jens Kleesiek and Michael Kamp},
  title = {{FAM: Relative Flatness Aware Minimization}},
  booktitle = {TAG-ML},
  year = {2023},
  url = {https://openreview.net/forum?id=HqMf88YF4u},
}
Figure