Flatness Guided Test-Time Adaptation for Vision-Language Models

Aodi Li, Liansheng Zhuang, Xiao Long, Houqiang Li, Shafei Wang

TL;DR

Flatness-Guided Adaptation (FGA) is a novel framework that bridges the gap between training and inference for Vision-Language Models (VLMs). By finding "flat" loss minima during training and selecting test-time augmentations that align with those minima, FGA achieves state-of-the-art accuracy on out-of-distribution data. Remarkably, it does so while being nearly 9x faster and using 4x less memory than standard test-time prompt tuning.

The Challenge of Distribution Shifts

Vision-Language Models (VLMs) like CLIP are powerful, but they often stumble when encountering "distribution shifts"—situations where the test data visually diverges from the training data (e.g., sketches instead of standard photos).

To address this, researchers employ Test-Time Adaptation (TTA), which tweaks the model on the fly as it processes new data. The current gold standard, Test-Time Prompt Tuning (TPT), optimizes a set of "prompts" for every single test image using backpropagation. While effective, this approach is incredibly slow and computationally expensive, making it impractical for real-time applications or edge devices. Furthermore, these traditional methods often treat the test phase as a standalone problem, ignoring the geometric properties of the model's original training history.

Methodology: Flatness-Guided Adaptation (FGA)

The authors propose Flatness-Guided Adaptation (FGA), a framework that treats the "flatness" of the loss landscape as a universal guide for both training and testing.

Overview of the Flatness-Guided Adaptation (FGA) framework, detailing the training and test-time stages.

The framework operates in two main phases:

  1. Sharpness-Aware Prompt Tuning (SAPT): During the initial training (fine-tuning) phase, the model doesn't just look for the lowest error; it actively seeks a "flat minimum." In a flat minimum, small changes to the model's parameters don't significantly change the loss. This geometric property is a classic indicator of a model that generalizes well to unseen data.
  2. Sharpness-based Test Sample Selection (STSS): This is the core innovation for inference. Instead of updating model weights for every test image via slow backpropagation, FGA generates multiple augmented views of the test image. It then calculates a "sharpness score" for each view by measuring how much the prediction changes when the prompt is slightly perturbed.
  3. Alignment over Optimization: FGA selects the augmented views that are the "flattest" around the pre-trained minimum. By picking views that align with the model's existing robust regions, it achieves adaptation without a single gradient update at test time.

Key Insights

  • Flatness as a Proximity Metric: Theoretical analysis in the paper suggests that a lower sharpness score correlates with a test sample being "closer" to the training distribution. Essentially, if the model's loss landscape is flat for a specific image, the model's prediction for that image is more reliable.
  • Geometric Alignment: Instead of moving the model parameters to fit the test data (as seen in traditional TTA), FGA effectively "moves" the test data (via augmentation selection) to fit the model's most robust parameter regions.
  • Semantic Integrity: Visualizations of the loss landscapes reveal that "flat" regions correspond to augmentations that maintain the object's semantic meaning, while "sharp" regions often correspond to heavily distorted or unrecognizable views.

Key Results

The authors evaluated FGA on two major benchmarks: ImageNet Out-of-Domain (OOD) variants (ImageNet-A, ImageNet-V2, ImageNet-R, and ImageNet-Sketch) and a Cross-Dataset Generalization suite of 10 diverse datasets.

Performance comparison on ImageNet out-of-domain datasets.
  • Superior Accuracy: On ImageNet OOD variants, FGA (using a ViT-B/16 backbone) outperformed the strong TPT+CoOp baseline by an average of 4.88%.
  • Massive Speedup: By avoiding test-time backpropagation, FGA is 8.86x faster than TPT (0.07s vs 0.62s per image) and 23.86x faster than the more complex DiffTPT.
  • Memory Efficiency: FGA uses only 4.14 GB of VRAM, compared to the 19.33 GB required by TPT, making it highly suitable for consumer-grade hardware.
  • Consistency: FGA achieved the highest average accuracy (67.60%) across the 10-dataset cross-domain benchmark, proving it generalizes broadly rather than just overfitting to ImageNet.

Limitations and Future Work

While FGA successfully eliminates the need for backpropagation during inference, it still relies on generating multiple augmentations (the paper uses 64 views) to find the best alignment. This "multi-view" approach incurs a computational cost, even if it remains significantly lower than gradient-based methods.

Future work could involve integrating FGA with more advanced prompt tuning methods or exploring how this "flatness-guided" philosophy applies to other foundational models beyond vision-language tasks. Extending FGA to larger-scale, more complex experimental configurations also remains an exciting engineering challenge.

Summary updated

BibTeX
@inproceedings{li2026flatness,
  author = {Aodi Li and Liansheng Zhuang and Xiao Long and Houqiang Li and Shafei Wang},
  title = {{Flatness Guided Test-Time Adaptation for Vision-Language Models}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=S90g7NE88b},
}
Figure