When does Contrastive Learning Preserve Adversarial Robustness from Pretraining to Finetuning?

Lijie Fan, Sijia Liu, Pin-Yu Chen, Gaoyuan Zhang, Chuang Gan

While self-supervised contrastive learning (CL) has become a powerhouse for learning general, transferable features, it harbors a hidden weakness: the adversarial robustness gained during pretraining often "evaporates" when the model is finetuned for downstream tasks.

To address this, researchers introduced ADVCL (Adversarial Contrastive Learning), a framework designed to preserve robustness by bridging the gap between unsupervised pretraining and supervised downstream tasks. By leveraging adversarial views, high-frequency image components, and pseudo-label supervision, ADVCL ensures that robustness survives the finetuning process.

The Problem: Task Mismatch and "Evaporating" Robustness

The "pretrain then finetune" paradigm is the current gold standard in computer vision. Models trained using Contrastive Learning (like SimCLR) learn to distinguish between individual images (instance discrimination) without relying on labels.

While this pretraining can be made "robust" by exposing the model to adversarial examples, that robustness frequently fails to transfer to downstream tasks like object classification. If you perform a simple "linear evaluation"—freezing the backbone and training only the last layer—the model’s robustness drops significantly compared to standard supervised adversarial training. The authors identify a "task mismatch" between the unsupervised pretraining objective and the supervised finetuning objective as the primary culprit behind this drop.

The ADVCL Framework

To solve this, the authors propose ADVCL, which introduces two major innovations to the standard contrastive pipeline:

AdvCL Framework Architecture

1. Robustness-aware View Selection

Standard CL relies on data augmentations like cropping and color jittering to create different "views" of an image. ADVCL introduces two specialized views to explicitly target robustness:

  • Adversarial Views: The framework generates perturbations that maximize the contrastive loss. This forces the encoder to learn features that are invariant to these adversarial attacks.
  • High-Frequency Components (HFC): Adversarial attacks often exploit high-frequency patterns that are imperceptible to the human eye. ADVCL explicitly extracts HFC versions of images (via Fourier Transform) and includes them as a contrastive view, improving both generalization and robustness against these invisible perturbations.

2. Pseudo-supervision Stimulus (CLUSTERFIT)

To resolve the task mismatch, ADVCL incorporates an offline clustering step. Using a pretrained (but non-robust) model, the unlabeled data is clustered using K-means, assigning "pseudo-labels" to every image.

During the robust pretraining phase, the model minimizes a supervised adversarial cross-entropy loss on these pseudo-labels alongside the standard contrastive loss. This critical step forces the model to learn class-discriminative features early on, rather than just instance-discriminative ones.

Key Insights

  • Solving the "Aha" Moment on Task Mismatch: Unsupervised robustness is typically "forgotten" because the model learns which features are essential for individual instances, not classes. Pseudo-labels provide the necessary "hint" to keep class-relevant features intact during finetuning.
  • High Frequencies Matter: Explicitly training on high-frequency components helps the model ignore the "noise" typically exploited by adversarial attacks, leading to simultaneous improvements in standard and robust accuracy.
  • Linear Finetuning Efficiency: ADVCL is designed so that expensive adversarial training isn't needed during the finetuning stage. A simple, fast linear classifier on top of the frozen ADVCL backbone is enough to achieve state-of-the-art robustness.
  • Flatter Landscapes: Qualitative analysis shows that ADVCL results in a much "flatter" loss landscape, which is a strong indicator of a model's ability to generalize and transfer its knowledge to new tasks.

Key Results

ADVCL was evaluated on standard benchmarks (CIFAR-10, CIFAR-100, and STL-10) and consistently outperformed existing self-supervised robust learning methods like ACL and RoCL.

Standard vs Robust Accuracy Comparison
  • Robustness (Auto-Attack): On CIFAR-10, using standard linear finetuning, ADVCL achieved 42.57% robust accuracy, significantly higher than ACL (39.13%) and RoCL (28.38%).
  • Standard Accuracy: Unlike many adversarial defense methods that trade off standard accuracy for robustness, ADVCL often improved both. On CIFAR-100, it achieved 48.34% standard accuracy, outperforming other robust self-supervised baselines.
  • Transferability: When pretraining on CIFAR-100 and finetuning on STL-10, ADVCL maintained a lead in robustness, proving that the learned representations are highly transferable and not just overfitted to a single dataset.

Limitations and Future Work

While highly effective, ADVCL does come with computational overhead. Generating adversarial views and performing K-means clustering adds significant time to the pretraining phase compared to standard SimCLR. Additionally, the method's success is partially tied to the quality of the initial pseudo-labels; if the initial "teacher" model used for clustering is poor, the pseudo-labels could mislead the robust training.

Future work will need to explore how these principles scale to massive datasets like ImageNet-22K and modern "foundation model" architectures.

Summary updated

BibTeX
@inproceedings{fan2021when,
  author = {Lijie Fan and Sijia Liu and Pin-Yu Chen and Gaoyuan Zhang and Chuang Gan},
  title = {{When does Contrastive Learning Preserve Adversarial Robustness from Pretraining to Finetuning?}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2021},
}
Figure