Sparse Mixture-of-Experts are Domain Generalizable Learners

Bo Li, Yifei Shen, Jingkang Yang, Yezhen Wang, Jiawei Ren, Tong Che, Jun Zhang, Ziwei Liu

TL;DR

While most research in Domain Generalization (DG) focuses on designing complex loss functions, this paper reveals that the backbone architecture is actually the secret sauce. By leveraging Sparse Mixture-of-Experts (MoE) within a Vision Transformer, the authors create a model (GMoE) that naturally aligns with invariant visual attributes, outperforming state-of-the-art DG algorithms even when trained with a simple, standard loss.

What Problem Does This Paper Address?

Machine learning models are notoriously brittle; they often fail when the "test" data looks slightly different from the "training" data (e.g., a model trained on photos of dogs failing to recognize a sketch of a dog). This is the core challenge of Domain Generalization (DG).

Traditionally, researchers have tried to solve this by designing specialized loss functions—like adversarial training or invariant risk minimization—to force models to ignore "spurious correlations" (like background or texture) and focus on "invariant features" (like shape). However, the authors noticed a surprising trend: a vanilla Vision Transformer (ViT) trained with standard Empirical Risk Minimization (ERM) often beats a ResNet (CNN) equipped with the fanciest DG algorithms. This paper investigates why this happens and how we can design better backbones specifically tailored for robustness.

Methods

The authors introduce a theoretical framework called Algorithmic Alignment. Essentially, if a network's architecture naturally "matches" the structure of the task, it learns more efficiently and generalizes better.

Building on this, they propose Generalizable Mixture-of-Experts (GMoE).

GMoE Architecture and Patch Routing

Key components of the GMoE architecture include:

  • Sparse MoE Layers: Instead of a standard feed-forward network (FFN), GMoE uses multiple "experts." For every input patch, a "router" selects only the top-$k$ most relevant experts to process it.
  • The Cosine Router: Unlike standard linear routers, the cosine router projects patches onto a hypersphere. This acts like a "cookbook" of visual attributes, where each expert specializes in a specific type of feature (e.g., "pointy ears" or "grey skin").
  • Strategic Placement: Through ablation, they found that placing MoE layers at the end of the network ("last-two" configuration) is most effective, as these layers handle high-level semantic attributes that are more likely to be invariant across domains.

Datasets

The authors evaluated their approach on the DomainBed benchmark, which includes eight large-scale datasets:

  • PACS, VLCS, OfficeHome, TerraIncognita, DomainNet: Standard DG benchmarks covering art, sketches, photos, and diverse objects.
  • SVIRO, Wilds-Camelyon, Wilds-FMOW: Real-world distribution shifts in satellite imagery, medical imaging, and synthetic vehicle interiors.

They also introduced CUB-DG, a diagnostic dataset based on Caltech-UCSD Birds. They "stylized" bird images into different domains (Candy, Mosaic, etc.) to verify if experts were actually specializing in specific biological attributes like beaks or wings.

Key Insights and Ideas

  • Backbone > Loss Function: The most provocative insight is that choosing the right architecture (ViT/MoE) provides a bigger boost to robustness than years of research into specialized DG loss functions.
  • MoEs as Attribute Detectors: The "aha moment" comes from the visual attribute routing. Without any explicit supervision, the MoE router naturally learns to send "beak" patches to one expert and "wing" patches to another, regardless of whether the image is a photo or a sketch. This "functional part" decomposition is inherently more robust to domain shifts.
  • Shape vs. Texture Bias: The paper reinforces that transformers have a natural "shape bias" (invariant), while CNNs are often distracted by "texture bias" (spurious). MoEs amplify this by allowing the model to dynamically allocate parameters to different visual concepts.

Key Results

Performance on DomainBed Datasets
  • SOTA Performance: GMoE-S/16 (trained with simple ERM) achieved state-of-the-art results on 7 out of 8 DomainBed datasets.
  • DomainNet Dominance: On the massive DomainNet dataset, GMoE achieved 48.7% accuracy, significantly outperforming the previous best DG algorithm (MIRO at 44.3%) and vanilla ViT (47.3%).
  • Complementary Nature: When GMoE was combined with existing DG algorithms (like SWAD), performance improved even further (reaching 49.6% on DomainNet), proving that backbone design and loss design can work hand-in-hand.
  • Efficiency: Despite having more total parameters, GMoE is "sparse," meaning it uses roughly the same amount of computation (FLOPs) during inference as a standard ViT-S/16.

Limitations and Future Work

The authors acknowledge that while MoEs are computationally efficient during inference, they still require significant VRAM to store all the experts, which can be a hurdle for deployment on edge devices.

For future work, they suggest exploring Neural Architecture Search (NAS) specifically for domain generalization—letting the data itself help design the most robust backbone. They also point toward the potential of developing even more specialized "expert" modules that go beyond simple feed-forward layers.

Summary updated

BibTeX
@inproceedings{li2023sparse,
  author = {Bo Li and Yifei Shen and Jingkang Yang and Yezhen Wang and Jiawei Ren and Tong Che and Jun Zhang and Ziwei Liu},
  title = {{Sparse Mixture-of-Experts are Domain Generalizable Learners}},
  booktitle = {International Conference on Learning Representations},
  year = {2023},
  url = {https://openreview.net/forum?id=RecZ9nB9Q4},
}
Figure