Test-Time Prompt Tuning for Zero-Shot Generalization in Vision-Language Models

Manli Shu, Weili Nie, De-An Huang, Zhiding Yu, Tom Goldstein, Anima Anandkumar, Chaowei Xiao · DOI

Introduction

Large-scale vision-language models (VLMs), such as CLIP, have established a new frontier in zero-shot learning by aligning visual and textual representations. However, the performance of these models is significantly influenced by the specific text prompts used to describe target classes. While techniques like "prompt tuning" have been developed to automate the discovery of optimal prompts, they typically rely on labeled training datasets. This requirement introduces a paradox: achieving peak "zero-shot" performance often necessitates a "few-shot" training phase. Moreover, prompts learned on specific datasets frequently fail to generalize to out-of-distribution (OOD) data, such as sketches or adversarial examples.

To resolve these issues, we present Test-Time Prompt Tuning (TPT). TPT is a novel approach that optimizes prompts on the fly using only a single unlabeled test sample. By adapting the prompt to the specific instance encountered at inference time, TPT enhances the model's robustness and generalization without requiring any task-specific training data or human annotations.

Methodology

TPT shifts the focus from learning a static, dataset-wide prompt to learning a dynamic, instance-specific prompt. The process involves three primary components:

1. Test-Time Optimization

For every individual test image, TPT generates $N$ randomly augmented views (e.g., via random cropping). These views provide a diverse set of perspectives on the same underlying object, which the model uses to refine its understanding of the sample.

2. Entropy Minimization

The core objective of TPT is to ensure that the model produces consistent and confident predictions across all augmented views of the same image. This is achieved by minimizing the marginal entropy of the model’s averaged predictions. By reducing entropy, the model effectively "tunes" its prompt to better align with the visual features present in the specific test instance.

3. Confidence Selection

A critical challenge in test-time augmentation is that some views (e.g., a crop of a blank background) may be uninformative or misleading. To mitigate this "noise," TPT employs a confidence selection mechanism. It ranks the augmented views by their self-entropy and utilizes only the most confident views (the top 10%) to calculate the optimization loss. This filtering ensures that the prompt is not corrupted by low-quality augmentations.

4. Context-Dependent Reasoning

For complex tasks like the Bongard-HOI visual puzzles, TPT adapts the prompt to maximize the distinction between "positive" and "negative" support images provided within the test sample. This allows the model to perform a form of "reasoning" about the underlying concept before classifying the query image.

Experimental Evaluation

The authors evaluated TPT across a diverse range of benchmarks to test its versatility and robustness:

  • Natural Distribution Shifts: Performance was measured on ImageNet variants, including ImageNet-V2, ImageNet-A (adversarial), ImageNet-R (renditions), and ImageNet-Sketch.
  • Cross-Dataset Generalization: TPT was tested on 10 distinct datasets, such as Flower102, OxfordPets, EuroSAT (satellite imagery), and UCF101 (action recognition).
  • Visual Reasoning: The Bongard-HOI benchmark was used to assess the model's ability to identify human-object interactions from limited examples.

Key Insights and Results

The experimental results highlight several strengths of the TPT framework:

  • Superior Generalization: TPT improved CLIP’s average top-1 accuracy by 3.6% across distribution shift datasets. Notably, on the challenging ImageNet-A dataset, it achieved a 6.9% boost in accuracy.
  • Outperforming Few-Shot Methods: Despite using zero training data, TPT outperformed state-of-the-art prompt tuning methods like CoOp—which are trained on 16-shot ImageNet data—when evaluated on OOD benchmarks. This suggests that instance-level adaptation is more effective for generalization than static dataset-level tuning.
  • State-of-the-Art Visual Reasoning: On the Bongard-HOI benchmark, TPT surpassed the previous best method by 4.1%, demonstrating its capability in complex reasoning tasks.
  • Efficiency of Prompt Tuning: The study found that tuning the text prompt is more effective than tuning the vision encoder. Prompt tuning preserves the foundational knowledge of the VLM, whereas encoder tuning can distort pre-trained features. Furthermore, most performance gains are realized with just a single step of gradient descent.

Limitations and Future Work

While TPT offers significant performance gains, it introduces certain trade-offs. The primary limitation is inference latency; because TPT requires a backpropagation step for every test sample, it is slower than standard zero-shot inference (0.25s vs. 0.10s per image). Additionally, the process of generating multiple views and storing gradients increases the memory footprint, which may limit deployment on resource-constrained edge devices.

Future research could focus on developing more efficient optimization processes or exploring task-specific objectives to further refine the test-time adaptation. There is also significant potential in extending the TPT paradigm to other modalities, including large language models (LLMs).

Summary updated

BibTeX
@inproceedings{shu2022test,
  author = {Manli Shu and Weili Nie and De-An Huang and Zhiding Yu and Tom Goldstein and Anima Anandkumar and Chaowei Xiao},
  title = {{Test-Time Prompt Tuning for Zero-Shot Generalization in Vision-Language Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2022},
}
Figure