Abstract
Modern deep learning systems do not generalize well when the test data distribution is slightly different to the training data distribution. While much promising work has been accomplished to address this fragility, a systematic study of the role of optimizers and their out-of-distribution generalization performance has not been undertaken. In this study, we examine the performance of popular first-order optimizers for different classes of distributional shift under empirical risk minimization and invariant risk minimization. We address this question for image and text classification using DomainBed, WILDS, and Backgrounds Challenge as testbeds for studying different types of shifts---namely correlation and diversity shift. We search over a wide range of hyperparameters and examine classification accuracy (in-distribution and out-of-distribution) for over 20,000 models. We arrive at the following findings, which we expect to be helpful for practitioners: i) adaptive optimizers (e.g., Adam) perform worse than non-adaptive optimizers (e.g., SGD, momentum SGD) on out-of-distribution performance. In particular, even though there is no significant difference in in-distribution performance, we show a measurable difference in out-of-distribution performance. ii) in-distribution performance and out-of-distribution performance exhibit three types of behavior depending on the dataset---linear returns, increasing returns, and diminishing returns.
Introduction
Deep learning models are notoriously fragile. A model that performs perfectly on its training data (In-Distribution, or ID) often falls apart when deployed in the real world where lighting, backgrounds, or demographics differ slightly (Out-of-Distribution, or OOD). While researchers have spent years developing new architectures and loss functions to fix this, the role of the optimizer—the algorithm that actually updates the model weights—has been largely overlooked in the context of OOD generalization. This study provides a large-scale, systematic analysis of whether the choice of optimizer leads models toward "shortcut" features that fail when the distribution shifts.
Methodology
The authors conducted an exhaustive "battle of the optimizers," training over 20,000 models to ensure their findings were robust to hyperparameter tuning. The study compared the "Non-Adaptive" family (SGD, Momentum SGD, Nesterov Accelerated Gradient) against the "Adaptive" family (Adam, RMSProp). These were tested under both standard Empirical Risk Minimization (ERM) and Invariant Risk Minimization (IRM) across 10 diverse benchmarks, including DomainBed (PACS, VLCS, Office-Home, DomainNet), WILDS (Amazon, CivilComments), and the Backgrounds Challenge.
Generalization Patterns and the "Adaptivity Tax"
A central finding of this research is the "Adaptivity Tax": adaptive optimizers tend to fit noise and spurious correlations in the training data more aggressively. Because they adjust the learning rate for every single weight, they are often "too good" at finding complex, non-generalizable paths to zero loss.
Furthermore, the relationship between ID and OOD performance follows three distinct curves depending on the dataset:
- Linear Returns: OOD accuracy improves steadily as ID accuracy improves.
- Increasing Returns: OOD accuracy only starts to climb after the model reaches a very high threshold of ID accuracy.
- Diminishing Returns: Further fine-tuning for ID accuracy eventually stops helping (or even hurts) OOD performance.
Empirical Results
The empirical results demonstrate a clear advantage for non-adaptive methods. Non-adaptive optimizers (like Momentum SGD) achieved the best OOD accuracy in 10 out of 12 tasks. Even when models were "matched" to have the exact same ID performance, the non-adaptive versions outperformed their adaptive counterparts in 11 out of 12 cases.
In datasets like CivilComments-WILDS, the performance gap was particularly remarkable. While both optimizer types showed high ID accuracy, adaptive methods significantly failed to maintain that performance in OOD environments. The only notable exception was the synthetic ColoredMNIST task, where Adam's ability to aggressively fit training data actually helped it escape a specific task-designed trap.
Conclusion
For practitioners, the takeaway is clear: if you are building a system where real-world data might differ from your training set, speed isn't the only factor to consider. While Adam is often faster to converge, spending the extra time to tune Momentum SGD may be the most effective way to ensure model robustness and OOD generalization.
Summary updated