Layerwise Early Stopping for Test Time Adaptation

Sabyasachi Sahoo, Mostafa ElAraby, Jonas Ngnawé, Yann Pequignot, Frédéric Precioso, Christian Gagné · OpenReview

TL;DR

This paper introduces GALA, a novel layer selection approach for Test Time Adaptation (TTA) that dynamically identifies and adapts the most beneficial layers per sample. By focusing adaptation on these layers, GALA effectively mitigates performance degradation and improves generalization to unseen domains, outperforming existing TTA methods.

What Problem Does This Paper Address?

Deep learning models often struggle when deployed in real-world scenarios due to "distribution shifts" – changes in the data distribution between training and testing. Test Time Adaptation (TTA) aims to address this by adapting a pre-trained model to a new domain during inference, without access to labels. However, existing TTA methods often adapt all layers of the model, which can lead to performance degradation, especially with severe shifts. This happens because not all layers are equally receptive to adaptation; some might learn irrelevant features or forget crucial pre-trained knowledge. The paper tackles the challenge of identifying which layers to adapt and when, to achieve better adaptation without harming performance.

Methods

The core contribution is the Gradient-Aligned Layer Adaptation (GALA) framework. GALA operates by:

  • Gradient Alignment Criterion: For each layer, GALA measures the alignment of the current sample's gradient update with the accumulated historical gradient updates for that layer. This is done using a cosine distance metric. The intuition is that layers with gradients well-aligned with past updates are more likely to be learning beneficial features for the new domain.
  • Layer Selection: Based on this alignment score, GALA ranks layers and selects the one with the highest alignment (above a certain threshold) to adapt for the current sample. This allows for dynamic, sample-wise adaptation of specific layers.
  • Reset Window: To prevent the model from getting stuck in a local minimum or adapting to a temporary shift, GALA incorporates a "reset window." Periodically, the accumulated historical gradients are reset, allowing the model to re-evaluate and potentially change its adaptation direction.

This approach is designed to be flexible and can be integrated with various existing TTA loss functions.

Datasets

The paper evaluates GALA on several standard benchmarks:

  • Domainbed: A benchmark for domain generalization, used with datasets like PACS, VLCS, Terra Incognita, and Office-Home.
  • Continual TTA benchmark: Used with corrupted versions of CIFAR10-C and CIFAR100-C.
  • Tiny-Domainbed: A smaller, curated version of Domainbed created by the authors to facilitate detailed per-layer analysis, focusing on critical shifts.

Key Insights and Ideas

  • Layer Receptivity Varies: Not all layers in a neural network are equally beneficial for adaptation. Some layers might be more sensitive to shifts, while others might be more stable.
  • Misaligned Gradients Cause Degradation: Adapting layers with misaligned gradients can lead to performance degradation, suggesting that these layers are learning irrelevant or noisy information for the new domain.
  • Dynamic Layer Selection is Crucial: A fixed layer selection strategy across all samples and shifts is suboptimal. GALA's sample-wise, gradient-aligned selection offers a more adaptive and effective approach.
  • Resetting Helps in Changing Environments: The reset mechanism in GALA is particularly beneficial in multi-domain shift scenarios, allowing the model to adapt to evolving data distributions.
  • Single Best Layer is Often Enough: GALA's analysis suggests that identifying and adapting the single best layer (based on alignment) is often more effective than adapting multiple top-ranked layers, highlighting the importance of precise selection.

Key Results

  • Outperforms Baselines: GALA consistently outperforms ERM (no adaptation) and "all layers" TTA baselines by a significant margin (e.g., 2% overall on Domainbed, and up to 15% on Continual TTA).
  • Competitive with Other Layer Selection Methods: GALA also surpasses existing layer selection baselines like AutoRGN and AutoSNR, particularly on challenging datasets and losses.
  • Robustness: GALA shows robustness to hyperparameter choices, with a fixed threshold and window size performing well across various settings.
  • Mitigates Forgetting: By focusing adaptation on beneficial layers, GALA effectively reduces the forgetting of pre-trained source domain knowledge.
  • Effective on Diverse Settings: GALA demonstrates strong performance across different datasets, model architectures (ResNet-18, ResNet-50), and TTA losses (Pseudo-Labeling, SHOT).

Limitations and Future Work

  • Hyperparameter Sensitivity (Minor): While GALA is generally robust, the paper notes that tuning hyperparameters like the mask threshold can further improve performance, especially in scenarios where the initial few samples might be misleading.
  • Identifying the "Best" Set of Layers: GALA excels at identifying the single best layer to adapt. However, it might struggle to precisely determine the optimal set of multiple layers to update when multiple layers are beneficial. The authors suggest that tuning hyperparameters could help address this.
  • Future Research: The authors suggest that GALA's principles could be extended to other areas requiring regularization for learning stability, selective parameter updates, or gradient-aligned feature learning, contributing to the development of more robust and adaptive AI systems.

Summary updated

BibTeX
@inproceedings{sahoo2025layerwise,
  author = {Sabyasachi Sahoo and Mostafa ElAraby and Jonas Ngnawé and Yann Pequignot and Frédéric Precioso and Christian Gagné},
  title = {{Layerwise Early Stopping for Test Time Adaptation}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2025},
  doi = {10.1609/aaai.v39i19.34229},
}
Figure