NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Diverse Weight Averaging for Out-of-Distribution Generalization

Alexandre Ramé, Matthieu Kirchmeyer, Thibaud Rahier, Alain Rakotomamonjy, Patrick Gallinari, Matthieu Cord

TL;DR

Diverse Weight Averaging (DiWA) improves out-of-distribution (OOD) generalization by averaging the weights of neural networks trained across independent runs rather than a single trajectory. By leveraging a new bias-variance-covariance-locality decomposition, the authors show that maximizing functional diversity while maintaining weight averageability achieves state-of-the-art performance on the DomainBed benchmark with zero additional inference cost.

What Problem Does This Paper Address?

Standard deep neural networks frequently fail when deployed on data from a different distribution than their training data (out-of-distribution or OOD settings). While traditional functional ensembling (averaging model predictions) significantly improves robustness, it incurs a massive computational overhead at test time because every single model in the ensemble must perform a forward pass.

Weight Averaging (WA) has emerged as a powerful alternative that directly averages the parameters of multiple networks, resulting in a single model with no inference overhead. However, existing WA methods only sample checkpoints along a single training run. This paper addresses the limitation of low model diversity in single-run WA and provides a rigorous theoretical foundation explaining why and when weight averaging actually succeeds under distribution shifts.

Methods

The authors introduce Diverse Weight Averaging (DiWA). Instead of averaging weights from a single trajectory, DiWA averages weights obtained from independent training runs initialized with the same pretrained weights but varied by hyperparameters (learning rate, weight decay, dropout), batch ordering, and data augmentations.

To make this work, DiWA relies on two core ingredients to satisfy the "locality constraint" (ensuring the averaged weights still form a functional network):

  1. Shared Initialization: Models must be fine-tuned from a shared pretrained initialization (e.g., ImageNet), which ensures linear mode connectivity—the property that independent models can be connected via a low-loss path in weight space.
  2. Mild Hyperparameter Search: Hyperparameters are sampled from a restricted, "mild" range to prevent models from drifting into completely different valleys of the loss landscape.

The authors propose two weight selection strategies:

  • Uniform: Equally averages all $M$ available models.
  • Restricted: A greedy strategy that ranks models by validation accuracy and sequentially adds them only if they improve the validation performance of the averaged model.

Datasets

The method is evaluated on the DomainBed benchmark, the standard for domain generalization, which includes five multi-domain real-world classification datasets:

  • PACS (Photos, Art, Cartoons, Sketches)
  • VLCS (VOC2007, LabelMe, Caltech101, SUN09)
  • OfficeHome (Art, Clipart, Product, Real-World)
  • TerraIncognita (Wilderness camera trap images across different locations)
  • DomainNet (Large-scale dataset across six distinct domains)

Additionally, ColoredMNIST is utilized specifically to analyze performance under severe correlation shifts.

Key Insights and Ideas

  • Moving Beyond Flatness: Previous work attributed WA's success to finding "flatter" minima. The authors prove this is incomplete: flatness-seeking methods like Sharpness-Aware Minimization (SAM) achieve similar flatness to WA but perform worse OOD.
  • WA as an Ensemble Approximation: The authors prove that WA acts as a first-order approximation of functional ensembling (ENS). As shown in Figure 1, weight averaging closely tracks—and often slightly outperforms—prediction ensembling.
Figure 1: Each dot displays the accuracy (↑) of weight averaging (WA) vs. accuracy (↑) of prediction averaging (ENS) for M models.
  • The Error Decomposition: The paper introduces a bias-variance-covariance-locality decomposition for WA. It reveals that WA reduces variance and covariance but leaves bias untouched.
  • Diversity Shift vs. Correlation Shift: Because WA only reduces variance, it excels under diversity shift (changes in input marginal distributions, common in DomainBed). However, it fails under correlation shift (changes in label posterior distributions, like ColoredMNIST) because correlation shift is dominated by bias.

Key Results

  • State-of-the-Art on DomainBed: DiWA combined with Linear Probing (LP) initialization achieves a new state-of-the-art average accuracy of 68.0% across DomainBed, outperforming the previous best method, SWAD (66.9%).
  • Independent Runs Outperform Single Trajectories: As shown in Figure 4, averaging weights from independent runs consistently yields higher OOD accuracy than averaging checkpoints from a single run as the number of models ($M$) increases.
Single vs Independent Runs
  • Zero Inference Overhead: Unlike standard ensembles that scale linearly in compute cost at test time, DiWA compresses the ensemble into a single set of weights, maintaining identical inference speed to a standard ERM model.

Limitations and Future Work

  • Failure Under Correlation Shift: DiWA cannot resolve distribution shifts where the relationship between features and labels changes fundamentally (e.g., ColoredMNIST), as it does not inherently reduce model bias.
  • The Locality Constraint: DiWA breaks down if models diverge too much. If initializations differ or hyperparameter ranges are too extreme, the linear mode connectivity is lost, causing the averaged model's performance to collapse (see Figure 5).
Figure 5: Each dot displays the accuracy (↑) gain of WA over its members vs. prediction diversity (↑) for 2 ≤M < 10 models.
  • Future Directions: The authors suggest exploring weight averaging across models trained with entirely different optimization objectives (e.g., combining ERM, Mixup, and Coral) to safely inject even more functional diversity.

Summary updated

BibTeX
@inproceedings{rame2022diverse,
  author = {Alexandre Ramé and Matthieu Kirchmeyer and Thibaud Rahier and Alain Rakotomamonjy and Patrick Gallinari and Matthieu Cord},
  title = {{Diverse Weight Averaging for Out-of-Distribution Generalization}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2022},
}
Figure