Test-Time Model Adaptation with Only Forward Passes

Shuaicheng Niu, Chunyan Miao, Guohao Chen, Pengcheng Wu, Peilin Zhao

Introduction

Deep learning models deployed in real-world scenarios frequently encounter "distribution shifts"—environmental variations such as weather conditions, sensor noise, or stylistic changes that differ from the training data. Test-Time Adaptation (TTA) has emerged as a critical technique to mitigate these shifts by updating the model dynamically during inference. However, conventional TTA methods typically rely on backpropagation, which presents significant challenges for deployment on resource-constrained edge devices and specialized hardware.

This paper introduces Forward-Optimization Adaptation (FOA), a gradient-free framework designed to adapt models using only forward passes. By bypassing the need for backpropagation, FOA enables effective adaptation on quantized hardware and devices with hard-coded weights, where traditional gradient-based optimization is either impossible or prohibitively expensive.

The Limitations of Gradient-Based TTA

Existing TTA methods, such as TENT or SAR, update model parameters by calculating gradients through the network. This approach faces three primary hurdles:

  1. Hardware Constraints: Edge devices like smartphones and FPGAs often lack the memory capacity required to store intermediate activations for backpropagation.
  2. Quantization Sensitivity: To optimize for power and speed, models are often compressed into low-bit integer formats (e.g., INT8 or INT6). These discrete formats are non-differentiable, causing standard gradient-based methods to fail.
  3. Immutable Weights: Certain AI accelerators hard-code weights into silicon to maximize efficiency, preventing any modification to the core model parameters during deployment.

Forward-Optimization Adaptation (FOA)

FOA addresses these challenges through a two-pronged strategy that adapts the model's behavior without modifying its internal weights.

1. Forward-Only Prompt Adaptation

Instead of updating millions of weights, FOA introduces a small set of learnable input prompts (embeddings) at the network's input layer. These prompts are optimized using the Covariance Matrix Adaptation Evolution Strategy (CMA-ES), a derivative-free optimization technique. Since ground-truth labels are unavailable at test time, FOA utilizes a "fitness function" based on two unsupervised metrics:

  • Prediction Entropy: A measure of the model's confidence in its predictions.
  • Activation Distribution Discrepancy: This metric compares the internal feature statistics (specifically the [CLS] token in Vision Transformers) of the shifted test data against the statistics of the original clean training data.

By restricting the optimization to a low-dimensional prompt space, FOA makes evolutionary strategies computationally feasible for real-time adaptation.

2. Back-to-Source Activation Shifting

To further bridge the domain gap, FOA employs a "shifting" mechanism at the final layer. This component calculates the mean difference between current test features and original source features. It then applies a direct shift to the test features, "pushing" them back toward the source domain before they reach the classification head. This process requires zero learning and zero gradients, providing a computationally "free" boost to adaptation performance.

Experimental Evaluation

The authors evaluated FOA across several rigorous out-of-distribution (OOD) benchmarks, including ImageNet-C (corruptions), ImageNet-R (renditions), ImageNet-V2, and ImageNet-Sketch. The experiments utilized Vision Transformers (ViT) and ResNet architectures.

Memory and Accuracy

FOA demonstrates remarkable efficiency. On ImageNet-C, FOA requires only 208 MB of memory when running an 8-bit quantized ViT, representing a 24-fold reduction compared to the 5,165 MB required by the gradient-based TENT method.

Furthermore, FOA proves highly effective on quantized hardware. An 8-bit quantized model adapted with FOA achieved 63.5% accuracy, outperforming a full-precision 32-bit model adapted with TENT (59.6%). This suggests that derivative-free optimization is more robust than gradients in discrete, low-precision environments.

In-Distribution Stability

A common pitfall of TTA is "catastrophic forgetting," where a model's performance on clean data degrades after adapting to noisy data. Because FOA only modifies external prompts and feature shifts—leaving the original weights untouched—it maintains nearly identical accuracy on clean, in-distribution data.

Discussion and Limitations

While FOA offers a breakthrough for edge-based TTA, it has certain limitations. The method is sensitive to batch size, performing most reliably when multiple samples are available to calculate feature statistics. Additionally, while highly effective for Vision Transformers, the performance gains are less pronounced for CNNs like ResNet due to the difficulty of integrating location-invariant prompts into local convolutional operations. Finally, because CMA-ES requires multiple forward passes per update (the "population size"), FOA may introduce higher inference latency compared to a single forward pass, a trade-off that must be managed based on the specific application requirements.

Conclusion

Forward-Optimization Adaptation (FOA) represents a significant step toward making Test-Time Adaptation practical for the edge. By replacing backpropagation with evolutionary prompt optimization and feature shifting, FOA achieves high accuracy and extreme memory efficiency, particularly on the quantized hardware that defines modern edge computing.

Summary updated

BibTeX
@inproceedings{niu2024test,
  author = {Shuaicheng Niu and Chunyan Miao and Guohao Chen and Pengcheng Wu and Peilin Zhao},
  title = {{Test-Time Model Adaptation with Only Forward Passes}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=qz1Vx1v9iK},
}
Figure