Abstract
In recent years, prompt tuning has proven effective in adapting pre-trained vision-language models to downstream tasks. These methods aim to adapt the pre-trained models by introducing learnable prompts while keeping pretrained weights frozen. However, learnable prompts can affect the internal representation within the self-attention module, which may negatively impact performance variance and generalization, especially in data-deficient settings. To address these issues, we propose a novel approach, Read-only Prompt Optimization (RPO). RPO leverages masked attention to prevent the internal representation shift in the pre-trained model. Further, to facilitate the optimization of RPO, the read-only prompts are initialized based on special tokens of the pre-trained model. Our extensive experiments demonstrate that RPO outperforms CLIP and CoCoOp in base-to-new generalization and domain generalization while displaying better robustness. Also, the proposed method achieves better generalization on extremely data-deficient settings, while improving parameter efficiency and computational overhead.
Introduction
Large-scale vision-language models (VLMs) like CLIP have demonstrated remarkable zero-shot capabilities. However, adapting these models to specific downstream tasks remains a challenge. Traditional fine-tuning is computationally expensive and risks catastrophic forgetting. Recent advancements in "prompt tuning," such as CoOp and CoCoOp, introduce learnable context vectors to adapt the model while keeping its weights frozen.
Despite their success, these methods suffer from a critical flaw: internal representation shift. Because standard self-attention allows bidirectional interaction between learnable prompts and original image/text tokens, the prompts inadvertently "corrupt" the model's well-tuned internal features. This is particularly problematic in few-shot or "data-deficient" scenarios, where the model becomes highly sensitive to the specific training samples provided, leading to high performance variance and poor generalization to novel classes.
As shown in the figure above, methods like CoCoOp exhibit significant standard deviation in accuracy, especially when generalizing to novel categories. RPO aims to achieve the stability of linear probing while maintaining the adaptive power of prompt tuning.
Methodology
To mitigate the internal representation shift, we propose Read-only Prompt Optimization (RPO). RPO is designed to allow learnable prompts to extract information from the pre-trained model without altering its internal state.
1. Read-only Masked Attention
The core of RPO is the use of masked attention. In a standard Transformer layer, all tokens attend to each other. RPO modifies this by applying a mask that allows learnable prompts to attend to (read from) the original image and text tokens, while preventing the original tokens from attending to the prompts. This ensures that the pre-trained representations remain "read-only" and uncorrupted.
2. Special Token-based Initialization (ST-Init)
Optimization in few-shot settings is often unstable. RPO addresses this by initializing prompts using slightly perturbed versions of the pre-trained [CLS] (vision) and [EOS] (text) tokens. These tokens are already optimized to aggregate global information, providing a more stable and effective starting point than random initialization.
3. Pairwise Scoring Function
RPO utilizes $K$ pairs of visual and textual prompts. During inference, similarity scores are computed for each pair and then averaged. This ensemble-like approach provides multiple "perspectives" on the data, further enhancing robustness.
Experiments and Results
We evaluated RPO across 11 diverse datasets for base-to-new generalization and 4 variants of ImageNet for domain generalization.
Key Results
- Superior Generalization: RPO achieved a harmonic mean accuracy of 77.78% across 11 benchmarks, outperforming CoCoOp's 75.83%. It was particularly effective on novel classes, where internal representation shift typically hurts performance.
- Massive Variance Reduction: RPO significantly reduced performance variance. In 16-shot experiments, RPO's variance was 94% lower than that of CoCoOp on average. This makes RPO a much more reliable choice for real-world applications with limited data.
- Domain Robustness: RPO showed improved domain generalization on 4 out of 5 ImageNet variants, proving that "read-only" prompts are more robust to distribution shifts.
- Efficiency: Unlike CoCoOp, which requires a separate neural network to generate prompts per image, RPO maintains the computational efficiency of the original CoOp while delivering superior performance.
Conclusion
Read-only Prompt Optimization (RPO) offers a robust and efficient solution for few-shot adaptation of vision-language models. By enforcing a "read-only" constraint through masked attention, RPO preserves the integrity of pre-trained representations, leading to better generalization and significantly lower variance. Future work will explore the scalability of RPO to larger model architectures and its applicability to other modalities.
Code is available at https://github.com/mlvlab/RPO.
Summary updated