[Paper Review] Sharpness-Aware Gradient Matching for Domain Generalization
This paper proposes Sharpness-Aware Gradient Matching (SAGM), a novel domain generalization method that simultaneously minimizes empirical risk, perturbed loss, and the gap between them to converge to flat minima with low loss. By implicitly aligning gradient directions between the empirical and perturbed losses, SAGM improves generalization over SAM and GSAM without extra computational cost, achieving state-of-the-art performance on five DG benchmarks with a 66.1% average accuracy on DomainBed.
The goal of domain generalization (DG) is to enhance the generalization capability of the model learned from a source domain to other unseen domains. The recently developed Sharpness-Aware Minimization (SAM) method aims to achieve this goal by minimizing the sharpness measure of the loss landscape. Though SAM and its variants have demonstrated impressive DG performance, they may not always converge to the desired flat region with a small loss value. In this paper, we present two conditions to ensure that the model could converge to a flat minimum with a small loss, and present an algorithm, named Sharpness-Aware Gradient Matching (SAGM), to meet the two conditions for improving model generalization capability. Specifically, the optimization objective of SAGM will simultaneously minimize the empirical risk, the perturbed loss (i.e., the maximum loss within a neighborhood in the parameter space), and the gap between them. By implicitly aligning the gradient directions between the empirical risk and the perturbed loss, SAGM improves the generalization capability over SAM and its variants without increasing the computational cost. Extensive experimental results show that our proposed SAGM method consistently outperforms the state-of-the-art methods on five DG benchmarks, including PACS, VLCS, OfficeHome, TerraIncognita, and DomainNet. Codes are available at https://github.com/Wang-pengfei/SAGM.
Motivation & Objective
- Address the limitation of SAM-like methods in converging to flat minima with low loss in domain generalization.
- Identify two key conditions for effective generalization: low loss in a neighborhood and flatness of the loss landscape.
- Develop a method that jointly optimizes empirical risk, perturbed loss, and their gap to satisfy both conditions.
- Improve generalization without increasing computational cost by leveraging gradient alignment.
- Demonstrate consistent performance gains over state-of-the-art methods on standard domain generalization benchmarks.
Proposed method
- Propose a three-objective optimization: minimize empirical risk $\mathcal{L}(\theta)$, perturbed loss $\mathcal{L}_p(\theta)$, and the surrogate gap $h(\theta) = \mathcal{L}_p(\theta) - \mathcal{L}(\theta)$.
- Formulate the objective as minimizing $\mathcal{L}(\theta)$, $\mathcal{L}_p(\theta)$, and the angle between their gradients to enable gradient alignment.
- Use a perturbation direction $\epsilon = \alpha \nabla\mathcal{L}(\theta)$ to compute the perturbed loss at $\theta + \epsilon$, approximating the sharpness-aware update.
- Introduce implicit gradient matching by ensuring consistent gradient directions between $\mathcal{L}(\theta)$ and $\mathcal{L}_p(\theta)$, avoiding gradient conflicts.
- Maintain computational efficiency by avoiding additional forward passes or complex Hessian approximations.
- Apply the method end-to-end in a standard training pipeline, compatible with standard deep learning frameworks.
Experimental results
Research questions
- RQ1Can minimizing the empirical risk, perturbed loss, and their gap jointly lead to flatter minima with lower loss in domain generalization?
- RQ2Does gradient alignment between the empirical and perturbed loss objectives improve convergence to generalizable minima?
- RQ3How does SAGM compare to SAM and GSAM in terms of generalization performance across diverse domain shift scenarios?
- RQ4Can SAGM achieve state-of-the-art performance without relying on pre-trained models or additional data augmentation?
- RQ5Does the proposed method maintain computational efficiency while improving generalization in domain generalization tasks?
Key findings
- SAGM achieves a 66.1% average accuracy on the DomainBed benchmark, outperforming ERM, SAM, GSAM, and ERM+SAM across five domain generalization datasets.
- On the PACS dataset, SAGM achieves 86.6% accuracy on the Sketch domain, surpassing SAM (85.8%) and GSAM (85.9%) by a significant margin.
- SAGM consistently improves generalization performance across all five benchmarks: PACS, VLCS, OfficeHome, TerraIncognita, and DomainNet.
- Local sharpness analysis shows SAGM converges to flatter minima than SAM and GSAM, with the smallest loss gap $h_\rho(\theta)$ across varying perturbation radii.
- Abllation studies confirm that gradient matching in SAGM contributes to a 1.3% average performance gain over ERM+SAM, validating its effectiveness.
- SAGM outperforms the Miro method, which uses a CLIP-based pre-trained model, demonstrating its strong generalization capability without external pretraining.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.