Understanding Hessian Alignment for Domain Generalization

Sobhan Hemati, Guojun Zhang, Amir Hossein Estiri, Xi Chen

Introduction

Deep learning models are notoriously brittle when encountering data from distributions different from their training sets. In Domain Generalization (DG), the goal is to train models on multiple source domains such that they generalize to unseen target domains. A common failure mode is the model's tendency to exploit spurious correlations—features that are predictive in training but irrelevant or misleading in testing. While various gradient-based regularizers have been proposed to mitigate this, their theoretical underpinnings have remained somewhat opaque. This paper addresses this gap by grounding domain alignment in second-order optimization theory, specifically focusing on the Hessian matrix.

Methodology: Aligning the Curvature

The authors propose that aligning the curvature of the loss landscape across different training domains is a robust way to achieve out-of-distribution (OOD) generalization. While the gradient provides the direction of descent, the Hessian matrix describes the "shape" of the loss valley.

Conceptual illustration of Hessian alignment. By ensuring the curvature (Hessian) is similar across domains, the performance gap (transfer measure) between source and target environments is minimized.

To implement this alignment efficiently, the paper introduces two algorithms:

  1. Hessian Gradient Product (HGP): This method aligns the product of the Hessian and the gradient. It is computationally efficient, requiring only two rounds of backpropagation without the need to store the full $O(d^2)$ Hessian matrix.
  2. Hutchinson’s Method: This approach uses random sampling to estimate the diagonal of the Hessian. While more computationally intensive, it provides a more accurate representation of the curvature, particularly near convergence where gradients are small.

Theoretical Insights: Beyond First-Order Alignment

A key theoretical contribution is the proof that the distance between Hessians across domains serves as an upper bound for the performance gap between those domains. Furthermore, the paper demonstrates that Hessian alignment implicitly performs multi-level feature matching. Aligning Hessians simultaneously aligns the model's errors, the features weighted by those errors, the logits, and the feature covariance. This framework provides a unified explanation for the success of previous methods like CORAL, which can be viewed as a specific instance of approximate Hessian alignment.

Empirical Evaluation and Results

The researchers evaluated their methods on rigorous benchmarks, including Colored MNIST (CMNIST) and the DomainBed suite (VLCS, PACS, OfficeHome, and DomainNet).

  • CMNIST Dominance: On the CMNIST benchmark, Hutchinson’s method achieved 74.0% accuracy, approaching the theoretical maximum of 75%, whereas standard Empirical Risk Minimization (ERM) collapsed to 14%.
  • Robustness to Label Shift: In scenarios with heavy label shift, Hutchinson outperformed existing methods like Fishr by a significant 12% margin (47.7% vs 35.5%).
  • Real-World Performance: On the DomainBed suite, the proposed methods were highly competitive. As shown in Figure 3, HGP and Hutchinson maintain superior target domain accuracy on datasets like OfficeHome and PACS even as the classifier shift $\delta$ increases.
Target domain accuracy on OfficeHome and PACS. The proposed HGP and Hutchinson methods show greater robustness to classifier perturbations compared to standard baselines.

Conclusion and Future Work

Aligning the second-order derivatives of the loss function provides a powerful and theoretically grounded approach to Domain Generalization. By ensuring that the loss landscape has a consistent "bowl shape" across environments, models become less sensitive to domain-specific shifts. While the computational cost of methods like Hutchinson's is higher than ERM, the gains in robustness are substantial. Future research may focus on extending these alignments to deeper layers of the network and developing even more efficient estimation techniques.

Summary updated

BibTeX
@inproceedings{hemati2023understanding,
  author = {Sobhan Hemati and Guojun Zhang and Amir Hossein Estiri and Xi Chen},
  title = {{Understanding Hessian Alignment for Domain Generalization}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2023},
}
Figure