Fishr: Invariant Gradient Variances for Out-of-distribution Generalization

Alexandre Ramé, Corentin Dancette, Matthieu Cord

Introduction

Standard deep learning models often fail when training and test data come from different distributions. This failure is frequently attributed to "simplicity bias," where models learn spurious correlations—like background colors—instead of robust, invariant features. While methods like Invariant Risk Minimization (IRM) aim to address this, they often struggle to outperform simple Empirical Risk Minimization (ERM) on rigorous benchmarks like DomainBed.

The Fishr Method: Invariant Gradient Variances

Fishr introduces a regularization technique centered on Invariant Gradient Variances. Unlike previous methods that focus on matching first-order statistics (mean gradient directions), Fishr aligns the second-order statistics (variances) of gradients across training domains.

Conceptual overview of Fishr: matching the variances of domain-level gradient distributions to synchronize training dynamics.

The process involves:

  1. Per-sample Gradient Computation: Calculating individual loss gradients for every data point. To maintain efficiency, the authors utilize the BackPACK library, which allows for these computations during a single backpropagation pass.
  2. Domain Variance Calculation: Estimating the variance of these individual gradients within each domain.
  3. Variance Matching Penalty: Minimizing the squared Euclidean distance between domain-level variances and the global average variance across all domains.

By applying this penalty, often just to the final classifier head, Fishr forces the model to find a representation where the optimization landscape is consistent across all domains.

Key Insights: The Hessian Connection

A pivotal insight of Fishr is the mathematical link between gradient variance, the Fisher Information Matrix, and the Hessian (the curvature of the loss landscape). By matching gradient variances, Fishr effectively aligns the local curvature of the loss function across domains. This ensures that a weight update beneficial for one domain is likely to be beneficial for others, reducing domain-specific "inconsistency."

Training dynamics showing the alignment of gradient variances, risks, and Hessian diagonals over epochs.

As shown in the training dynamics, the distance between domain-level gradient variances closely tracks the distance between Hessian diagonals. This empirical evidence supports the theoretical claim that matching variances aligns the underlying loss landscapes, leading to better generalization.

Experimental Results

Fishr was evaluated on the DomainBed benchmark, covering both synthetic (Colored MNIST) and diverse real-world datasets (PACS, VLCS, OfficeHome, TerraIncognita, DomainNet).

  • State-of-the-Art Performance: Fishr achieved an average accuracy of 70.8% on DomainBed, outperforming ERM (68.7%) and other strong baselines like CORAL (69.2%).
  • Robustness to Spurious Correlations: On the notoriously difficult Colored MNIST benchmark, where ERM typically fails (~14% accuracy), Fishr reached ~71%, demonstrating its ability to ignore strong domain-specific shortcuts.
  • Practical Efficiency: The method adds minimal computational overhead—between 2.7% and 7% for a ResNet-50—making it a practical choice for large-scale applications.

Conclusion

Fishr represents a significant advancement in Domain Generalization by moving beyond simple feature alignment. By synchronizing the optimization landscapes of different domains through invariant gradient variances, it provides a theoretically grounded and empirically robust solution for out-of-distribution generalization.

Summary updated

BibTeX
@inproceedings{rame2022fishr,
  author = {Alexandre Ramé and Corentin Dancette and Matthieu Cord},
  title = {{Fishr: Invariant Gradient Variances for Out-of-distribution Generalization}},
  booktitle = {International Conference on Machine Learning},
  year = {2022},
  url = {https://openreview.net/forum?id=igOH506X-s},
}
Figure