Train Flat, Then Compress: Sharpness-Aware Minimization Learns More Compressible Models

Clara Na, Sanket Vaibhav Mehta, Emma Strubell

Abstract Modern NLP relies on massive Transformer models that are computationally expensive and memory-intensive. To deploy them on edge devices, researchers typically use model compression techniques like pruning and quantization. This paper, presented at EMNLP 2022, explores whether changing the initial training objective can make models inherently easier to compress. We demonstrate that optimizing for "flat minima" using Sharpness-Aware Minimization (SAM) creates BERT models that are significantly more resilient to the damage caused by compression than those trained with standard Adam. These SAM-trained models retain higher accuracy under heavy pruning and yield "winning ticket" sub-networks that transfer more effectively across different NLP tasks.

Introduction

Most research in model compression focuses on the process of compression—how to prune or quantize a pre-existing model. This paper asks a more fundamental question: Can we change how we train the model in the first place to make it easier to compress later?

The authors hypothesize that models sitting in "flat minima"—broad regions of the loss landscape where small changes to weights do not significantly hurt performance—will be more robust to the perturbations introduced by compression. In contrast, models in "sharp minima" are likely to see performance collapse when weights are zeroed out (pruning) or rounded (quantization).

Methodology

The researchers compared standard Adam optimization against Sharpness-Aware Minimization (SAM). SAM is a minimax optimization procedure that looks for points where the loss is low and the surrounding neighborhood is also low-loss, explicitly encouraging the optimizer to find flat regions.

These optimizers were evaluated across three compression regimes using BERT-base, BERT-large, and RoBERTa on the GLUE benchmark and SQuAD v1.1:

  1. Iterative Magnitude Pruning (IMP): Gradually removing the smallest weights to find "winning tickets."
  2. Structured Pruning: Removing entire layers or attention heads using the CoFi method.
  3. Post-Training Quantization (PTQ): Converting weights to 8-bit integers after training without further fine-tuning.

Key Results

Resilience to Pruning

On the GLUE benchmark, SAM-optimized models consistently outperformed Adam-optimized models across all sparsity levels. As shown in the aggregate results, SAM maintains a performance buffer that prevents the model from falling off the "cliff" of high loss even as more parameters are removed.

Figure 1: Average GLUE score vs. Sparsity level for SAM and Adam optimizers. SAM consistently maintains higher performance as sparsity increases.

Superior Winning Tickets and Transferability

SAM doesn't just find better weights; it finds better structures. The pruning masks (the specific set of weights kept) found by SAM are more effective than those found by Adam. This is evident even when the masks are re-trained using a different optimizer. Furthermore, SAM-learned "winning tickets" are more universal; a mask found on one task (like MNLI) performs better when transferred to a different task (like RTE) than an Adam-found mask.

Figure 5: Performance on RTE at 60% sparsity. The "SAM Ticket" (mask) outperforms Adam and Random tickets regardless of the optimizer used for final training.

Bridging the Quantization Gap

Usually, achieving high performance with 8-bit weights requires complex "Quantization-Aware Training." This study shows that simply training with SAM allows for "Post-Training Quantization" (fast and easy) while achieving nearly the same accuracy. For example, on the MRPC task, the SAM-quantized model achieved an F1 score of 89.37, compared to 86.81 for the Adam-quantized model.

Discussion and Insights

The core insight is that flatness acts as a physical buffer. Because the loss is stable in a flat region, the "noise" introduced by pruning or quantization doesn't push the model into high-loss territory. This suggests that SAM finds more robust representations that are less dependent on the precise values of individual weights.

While SAM is computationally more expensive (roughly a 2x slowdown in training time due to the minimax steps), the gains in compressibility and the ability to use simpler post-training quantization methods may outweigh the initial training costs for models destined for edge deployment. Future work may explore whether applying SAM during the massive pre-training phase yields even more naturally compressible foundation models.

Summary updated

BibTeX
@inproceedings{na2022train,
  author = {Clara Na and Sanket Vaibhav Mehta and Emma Strubell},
  title = {{Train Flat, Then Compress: Sharpness-Aware Minimization Learns More Compressible Models}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2022},
  doi = {10.18653/v1/2022.findings-emnlp.361},
}
Figure