Abstract
Standard neural networks often struggle with out-of-distribution (OOD) generalization, failing when faced with distribution shifts such as changes in lighting, background, or style. While model ensembling is a robust solution, its high inference cost makes it impractical for many real-world applications. This paper introduces Diverse Weight Averaging (DiWA), a method that achieves the performance gains of ensembling with zero additional inference overhead. By averaging the weights of multiple models trained independently with varied hyperparameters—rather than checkpoints from a single run—DiWA leverages functional diversity to improve robustness. DiWA achieves a new state-of-the-art on the DomainBed benchmark, demonstrating that diversity in weight space is a critical component for OOD generalization.
Introduction
Deep learning models typically operate under the assumption that training and test data are independent and identically distributed (i.i.d.). However, real-world deployments frequently encounter distribution shifts. To combat this, two primary strategies have emerged: Ensembling, which averages the predictions of multiple models, and Weight Averaging (WA), which averages the parameters of models directly.
While ensembling is highly effective, it requires $M$ times the computational resources during inference. Conversely, existing WA methods, such as Stochastic Weight Averaging Densely (SWAD), typically average checkpoints from a single training trajectory. While efficient, these single-run averages often lack the functional diversity necessary to handle significant distribution shifts. DiWA bridges this gap by averaging weights across independent training runs, providing a "free" ensemble at inference time.
Methodology
Diverse Weight Averaging (DiWA)
The core mechanism of DiWA involves averaging the weights of $M$ models trained independently. To ensure that the resulting average remains a functional and high-performing model, the authors identify two essential constraints:
- Shared Initialization: All models must start from the same pre-trained weight initialization (e.g., a ResNet50 pre-trained on ImageNet). This ensures the models remain within the same "basin" of the loss landscape, maintaining linear mode connectivity.
- Mild Hyperparameter Search: Hyperparameters such as learning rate and dropout are varied within a controlled range. This introduces enough diversity for the models to learn different features without pushing the weights so far apart that their average becomes incoherent.
The BVCL Decomposition
To provide a theoretical foundation for why DiWA works, the authors introduce the BVCL decomposition. This framework breaks down the expected error into four components:
- Bias (B): The inherent error of the model class.
- Variance (V): Error due to sensitivity to the training set.
- Covariance (C): The degree to which different models make the same mistakes.
- Locality (L): The distance between individual model weights and the averaged weights.
Weight averaging effectively reduces the variance and covariance terms. However, it introduces a locality penalty if the weights are too far apart. DiWA succeeds by maximizing diversity (reducing covariance) while keeping the models close enough to the shared initialization to minimize the locality penalty.
Experimental Setup
Datasets and Benchmarks
The primary evaluation utilizes the DomainBed benchmark, a rigorous suite for OOD generalization. It includes five diverse datasets:
- PACS: Photos, Art, Cartoons, and Sketches.
- VLCS: Images from four distinct photographic datasets.
- OfficeHome: Objects in Art, Clipart, Product, and Real-world styles.
- TerraIncognita: Wild animal photography across different geographical locations.
- DomainNet: A large-scale dataset featuring six domains, including Quickdraw and Sketch.
Additionally, the authors use ColoredMNIST to analyze the method's performance under "correlation shifts," where the relationship between a spurious feature (color) and the label is inverted between training and testing.
Key Insights and Results
State-of-the-Art Performance
DiWA sets a new benchmark on DomainBed, achieving an average accuracy of 68.0%. This significantly outperforms the previous state-of-the-art, SWAD (66.9%), and shows consistent improvements across all five datasets in the suite.
Efficiency and Scaling
Unlike standard ensembles, DiWA has zero inference overhead. Once the weights are averaged, the resulting model is a single neural network that runs at the same speed as a standard baseline. Furthermore, the authors found that performance scales positively with the number of models averaged ($M$); increasing $M$ from 20 to 60 consistently improved OOD accuracy, suggesting that the method can effectively utilize additional training compute to produce more robust final models.
Diversity vs. Flatness
Previous research suggested that weight averaging works primarily by finding "flatter" minima in the loss landscape. However, the DiWA results indicate that functional diversity—the models learning different representations—is a more significant driver of OOD robustness than flatness alone. By averaging independent runs rather than single-run checkpoints, DiWA captures a broader range of features.
Limitations
Despite its strengths, DiWA has notable limitations:
- Training Cost: While inference is efficient, training $M$ independent models is computationally expensive. This makes DiWA most suitable for production environments where training is a one-time investment.
- Correlation Shifts: DiWA excels at handling "diversity shifts" (changes in input appearance) but does not resolve "correlation shifts" (spurious correlations). In tests like ColoredMNIST, weight averaging alone does not prevent the model from relying on misleading features if those features are present across all training runs.
Conclusion
Diverse Weight Averaging (DiWA) demonstrates that the benefits of ensembling can be distilled into a single set of weights without sacrificing inference speed. By enforcing a shared initialization and encouraging mild hyperparameter diversity, DiWA provides a simple, scalable, and highly effective strategy for improving the robustness of neural networks against real-world distribution shifts.
Summary updated