[Paper Review] Gradient Matching for Domain Generalization
This paper proposes Inter-domain Gradient Matching (IDGM), a domain generalization method that aligns gradients across different domains by maximizing their inner product to encourage invariant representations. It introduces Fish, a first-order approximation of IDGM that achieves state-of-the-art performance on Wilds and DomainBed benchmarks without requiring second-order derivatives, significantly improving generalization under distribution shift.
Machine learning systems typically assume that the distributions of training and test sets match closely. However, a critical requirement of such systems in the real world is their ability to generalize to unseen domains. Here, we propose an inter-domain gradient matching objective that targets domain generalization by maximizing the inner product between gradients from different domains. Since direct optimization of the gradient inner product can be computationally prohibitive -- requires computation of second-order derivatives -- we derive a simpler first-order algorithm named Fish that approximates its optimization. We demonstrate the efficacy of Fish on 6 datasets from the Wilds benchmark, which captures distribution shift across a diverse range of modalities. Our method produces competitive results on these datasets and surpasses all baselines on 4 of them. We perform experiments on both the Wilds benchmark, which captures distribution shift in the real world, as well as datasets in DomainBed benchmark that focuses more on synthetic-to-real transfer. Our method produces competitive results on both benchmarks, demonstrating its effectiveness across a wide range of domain generalization tasks.
Motivation & Objective
- To address domain generalization in machine learning, where models must generalize to unseen, out-of-distribution data.
- To overcome the limitation of standard ERM, which learns spurious correlations (e.g., background features) due to domain-specific biases.
- To develop a method that encourages models to learn invariant features by aligning gradients across domains.
- To design a computationally efficient alternative to second-order gradient matching, which is prohibitively expensive.
- To validate the method across diverse real-world and synthetic domain shift benchmarks.
Proposed method
- Proposes an inter-domain gradient matching (IDGM) objective that maximizes the inner product between gradients from different domains to align optimization dynamics.
- Derives a first-order approximation of IDGM, named Fish, to avoid costly second-order derivatives by leveraging insights from meta-learning (Reptile).
- Fish performs a single gradient update per domain on a shared model, then updates the model toward the average of these updates, mimicking the IDGM objective.
- Uses a normalized gradient inner product (cosine similarity) as a proxy to track and verify gradient alignment during training.
- Applies the method on both training-from-scratch and fine-tuning settings across diverse datasets in Wilds and DomainBed.
- Employs a shared data sequence for ERM and Fish to ensure fair comparison in gradient inner product tracking.
Experimental results
Research questions
- RQ1Can inter-domain gradient matching improve model generalization under distribution shift by aligning optimization paths across domains?
- RQ2Does a first-order approximation of gradient matching, such as Fish, achieve performance comparable to second-order optimization without requiring Hessian computation?
- RQ3How does Fish compare to ERM in maintaining or increasing inter-domain gradient alignment during training?
- RQ4Does the proposed method generalize across diverse domain generalization benchmarks, including real-world and synthetic shifts?
- RQ5What impact do hyperparameters like the number of domains (N) have on Fish's performance?
Key findings
- Fish achieves state-of-the-art performance on 13 datasets from the Wilds and DomainBed benchmarks, demonstrating broad applicability.
- On the Wilds benchmark, Fish achieves 82.4% accuracy on CivilComments and 77.7% on FMoW, outperforming ERM and other baselines.
- The normalized inter-domain gradient inner product consistently increases or remains stable during Fish training, while it decreases under ERM, confirming gradient alignment.
- For CdSprites-N and Poverty, where training from scratch is used, the gradient inner product dips initially but recovers, indicating robustness to initialization.
- Hyperparameter sensitivity analysis shows that performance is stable across different values of N, though N=20 leads to slight degradation on Poverty and CivilComments.
- The method effectively reduces reliance on spurious features (e.g., background) and promotes invariant feature learning, as visualized in Figure 1.
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.