FOZO: Forward-Only Zeroth-Order Prompt Optimization for Test-Time Adaptation

Xingyu Wang, Tao Wang

TL;DR

Deploying deep learning models to edge devices often fails when real-world data shifts from training conditions. FOZO (Forward-Only Zeroth-Order Prompt Optimization) solves this by adapting Vision Transformers (ViTs) at test-time using only forward passes—completely eliminating memory-heavy backpropagation. By dynamically adjusting its optimization perturbations and aligning internal feature statistics, FOZO achieves state-of-the-art accuracy on corrupted data streams with a fraction of the memory footprint of traditional methods.

What Problem Does This Paper Address?

When deep learning models encounter real-world distribution shifts (e.g., bad weather, compression artifacts, or stylistic changes), their performance plummets. Test-Time Adaptation (TTA) attempts to fix this by updating the model on the fly using unlabeled test data.

However, existing TTA methods hit a wall in practical deployment:

  1. Gradient-based methods rely on backpropagation, which demands massive GPU memory and computation—making them unusable on low-power edge devices like microcontrollers or FPGAs. They also modify core model weights, risking catastrophic forgetting.
  2. Forward-only methods avoid backpropagation but typically rely on slow, complex evolutionary algorithms (like CMA-ES) that struggle to scale, leading to sluggish convergence and suboptimal accuracy.

The authors tackle this dilemma by asking: Can we achieve highly accurate, fast-converging test-time adaptation using only forward passes, without ever modifying the base model's weights?

Methods

FOZO introduces a backpropagation-free paradigm that optimizes a small set of learnable visual prompts injected into the input layer of a frozen Vision Transformer (ViT).

Overview of FOZO and Deep-Shallow Aligning Loss

Its core components include:

  • Zeroth-Order Gradient Estimation: Instead of calculating exact gradients via backpropagation, FOZO estimates them using Simultaneous Perturbation Stochastic Approximation (SPSA). It feeds the model two slightly altered versions of the prompts (positive and negative random perturbations) and evaluates the difference in the loss function.
  • Dynamic Perturbation Scheme: Standard zeroth-order optimization uses a fixed perturbation scale, which fails when data distributions shift unpredictably. FOZO introduces a dynamically decaying perturbation scale ($\epsilon_t$). It uses larger perturbations early on or when a domain shift is detected to aggressively explore the loss landscape, and decays the scale as optimization stabilizes to ensure precise convergence.
  • Deep-Shallow Aligning Loss Function: To guide this unsupervised optimization, FOZO minimizes a refined loss function combining prediction entropy (for high confidence) and group-wise feature statistics alignment. It extracts [CLS] token activations from both shallow and deep layers of the ViT and aligns their means and variances with pre-computed source domain statistics.

Datasets

The authors evaluated FOZO on three widely recognized out-of-distribution benchmarks under a continual adaptation setting (where domain boundaries are unknown):

  • ImageNet-C: Contains 15 different types of algorithmically generated corruptions (blur, noise, weather effects) at various severity levels.
  • ImageNet-R: Features real-world renditions (art, cartoons, graffiti) of ImageNet classes.
  • ImageNet-Sketch: Consists of sketch drawings of ImageNet categories.

Key Insights and Ideas

  • Domain-Aware Re-initialization: The dynamic perturbation reset mechanism acts as an automated "radar" for domain shifts. When the loss fluctuates wildly due to a new corruption type, resetting the perturbation scale allows the model to break out of local minima and rapidly adapt to the new environment.
  • The Power of the [CLS] Token: Rather than aligning massive feature maps, simply tracking and aligning the statistics of the [CLS] token across shallow and deep layers provides a highly effective, low-overhead anchor to the source domain's knowledge.
  • Compatibility with Quantization: Because FOZO treats the model as a black box and never alters its internal weights, it is uniquely suited for quantized (INT8) models, which are notoriously difficult to fine-tune using standard gradient descent.

Key Results

FOZO demonstrates an exceptional balance of speed, accuracy, and memory efficiency:

  • Superior Accuracy: On ImageNet-C (5K, level 5), FOZO achieves 59.52% Top-1 accuracy using just 2 forward passes, outperforming the previous state-of-the-art forward-only method, FOA (58.13%). When allowed 28 forward passes, its accuracy climbs to 62.67%, outperforming major backpropagation-based methods like TENT and EATA.
  • Blazing Fast Convergence: FOZO reaches a target accuracy of 65% in only 66% of the runtime required by competing forward-only methods (FOA and ZOA), as shown in the convergence curves below.
Figure 1. Convergence Curves of Forward-Only Test-Time Adap- tation Algorithms. Average ACC@1 (%) of various Test-Time Adaptation (TTA) methods on ImageNet-C (level 5) versus adap- tation time (s). Per original settings, FOA and ZOA use 28 for- ward propagation (FP), while our FOZO method employs 26 FP. FOZO (Dynamic) consistently surpasses FOZO (Base) in accu- racy, demonstrating the effectiveness of our dynamic perturbation strategy. Furthermore, FOZO achieves superior performance and faster convergence than FOA and ZOA. Notably, FOZO reaches 65% ACC@1 in only 66% of the runtime required by FOA and ZOA, respectively.
  • Minimal Memory Footprint: FOZO requires only 831 MiB of peak GPU memory, compared to the ~5,495 MiB demanded by backpropagation-based TTA methods—a massive 85% reduction in memory usage.
  • Quantized Model Excellence: On 8-bit quantized ViT models (PTQ4ViT), FOZO achieves the highest overall average Top-1 accuracy of 58.00%, proving its readiness for hardware-constrained edge deployments.

Limitations and Future Work

Not discussed in the paper.

Summary updated

BibTeX
@inproceedings{wang2026fozo,
  author = {Xingyu Wang and Tao Wang},
  title = {{FOZO: Forward-Only Zeroth-Order Prompt Optimization for Test-Time Adaptation}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2026},
  url = {https://openreview.net/forum?id=P27TV5dzwB},
}
Figure