Gradient-Guided Annealing for Domain Generalization

Aristotelis Ballas, Christos Diou

Abstract

Domain Generalization (DG) is a critical challenge in machine learning, where models often fail when deployed on data distributions different from their training environments. We present Gradient-Guided Annealing (GGA), a novel training strategy designed to enhance domain generalization by identifying parameter regions where gradients from multiple training domains align. By employing a simulated annealing-inspired search during the critical early stages of training, GGA steers the model toward domain-invariant features and away from local minima that overfit to domain-specific noise. Our evaluation on the DomainBed benchmark demonstrates that GGA consistently outperforms standard Empirical Risk Minimization (ERM) and provides synergistic improvements when combined with existing DG algorithms.

Introduction

A fundamental assumption in standard machine learning is that training and test data are independent and identically distributed (i.i.d.). However, real-world applications frequently encounter domain shifts—variations in lighting, background, or sensor types—that degrade model performance. Domain Generalization (DG) aims to build models that can generalize to unseen "target" domains by leveraging multiple "source" domains during training.

Standard training via Empirical Risk Minimization (ERM) often fails in DG because it treats all source data as a single pool, potentially allowing the model to learn "spurious correlations" unique to specific domains rather than robust, invariant features.

The Problem: Gradient Conflict and Early Overfitting

The trajectory of a model's generalization ability is often determined in the initial iterations of training. During this phase, gradients from different domains may conflict: Domain A might suggest a weight update in one direction, while Domain B suggests another. When these signals disagree, the model tends to settle into "lazy" local minima that rely on domain-specific noise (e.g., background color) rather than the actual object features (e.g., shape).

Methodology: Gradient-Guided Annealing (GGA)

GGA is a "plug-and-play" optimization strategy that searches for a better starting point in the weight space without manually altering gradients. The process follows four key stages:

  1. Warm-up: The model undergoes a few standard training steps to reach a reasonable region of the loss landscape.
  2. Annealing Phase: During early training, random perturbations are introduced to the model's weights: $\theta' \leftarrow \theta + \mathcal{U}(-\rho, \rho)$.
  3. Selection Criterion: A perturbation is accepted only if it satisfies two conditions:
  4. Gradient Agreement: It must increase the minimum pairwise cosine similarity between gradients from different domains, ensuring the domains "agree" on the optimization direction.
  5. Low Loss: The training loss must remain within a reasonable range to ensure accuracy is not sacrificed for agreement.
  6. Standard Finish: Following this early search, the model completes training using standard optimizers like SGD or Adam.
Comparison of ERM and GGA models and their parameter update trajectories. ERM (top) shows divergent gradients and a decision boundary that overfits to source domains, failing on the unknown target. GGA (bottom) finds a region of gradient agreement, leading to a more robust, domain-invariant decision boundary.

Experimental Evaluation

The effectiveness of GGA was evaluated using the DomainBed benchmark across five diverse datasets:

  • PACS: Art, Cartoon, Photo, and Sketch.
  • VLCS: Photographic datasets (VOC, LabelMe, Caltech, SUN).
  • OfficeHome: Art, Clipart, Product, and Real-world images.
  • TerraIncognita: Wild animal photos from varying locations.
  • DomainNet: Six domains including Infographic, Painting, and Quickdraw.

Key Results and Insights

  • Performance Gains: GGA alone improved average accuracy over the ERM baseline by 2.4% across all benchmarks. On the challenging TerraIncognita dataset, GGA achieved 50.6% accuracy compared to ERM's 46.1%.
  • Algorithmic Synergy: GGA is model-agnostic and enhances other DG methods. For instance, adding GGA to the "Mixup" algorithm resulted in significant performance boosts.
  • Agreement as Invariance: The core insight is that gradient alignment serves as a proxy for domain invariance. If all domains agree on a gradient direction, the model is likely focusing on features consistent across all environments.
  • Optimization vs. Modification: Unlike "gradient surgery" methods that modify gradients, GGA simply searches the local weight space for naturally occurring regions of alignment, making it a robust optimization-based approach.

Conclusion and Future Work

While GGA shows strong performance, it introduces additional computational costs due to the forward and backward passes required during the annealing phase. It also requires explicit domain labels during training. Future research may explore adaptive annealing schedules to optimize the search process and methods to apply GGA in single-source DG scenarios where domain labels are unavailable.

Summary updated

BibTeX
@inproceedings{ballas2025gradient,
  author = {Aristotelis Ballas and Christos Diou},
  title = {{Gradient-Guided Annealing for Domain Generalization}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2025},
  doi = {10.1109/cvpr52734.2025.01914},
}
Figure