On the Effectiveness of Distillation in Mitigating Backdoors in Pre-trained Encoder

Tingxu Han, Shenghan Huang, Ziqi Ding, Weisong Sun, Yebo Feng, Chunrong Fang, Jun Li, Hanwei Qian, Cong Wu, Quanjun Zhang, Yang Liu, Zhenyu Chen · OpenReview

Abstract

In this paper, we study a defense against poisoned encoders in SSL called distillation, which is a defense used in supervised learning originally. Distillation aims to distill knowledge from a given model (a.k.a the teacher net) and transfer it to another (a.k.a the student net). Now, we use it to distill benign knowledge from poisoned pre-trained encoders and transfer it to a new encoder, resulting in a clean pre-trained encoder. In particular, we conduct an empirical study on the effectiveness and performance of distillation against poisoned encoders. Using two state-of-the-art backdoor attacks against pre-trained image encoders and four commonly used image classification datasets, our experimental results show that distillation can reduce attack success rate from 80.87% to 27.51% while suffering a 6.35% loss in accuracy. Moreover, we investigate the impact of three core components of distillation on performance: teacher net, student net, and distillation loss. By comparing 4 different teacher nets, 3 student nets, and 6 distillation losses, we find that fine-tuned teacher nets, warm-up-training-based student nets, and attention-based distillation loss perform best, respectively.

Introduction

Self-supervised learning (SSL) has revolutionized AI by allowing models to learn from massive, unlabeled datasets. However, this "pre-train first, fine-tune later" paradigm introduces a significant supply chain risk. An adversary can release a "poisoned" pre-trained encoder on platforms like HuggingFace. When a developer downloads this encoder and fine-tunes it for a specific task (like traffic sign recognition), the model behaves normally on clean images but misclassifies any input containing a secret "trigger" into an attacker-chosen target class.

Existing defenses, such as trigger inversion or neuron pruning, often fail in the SSL context because they require labeled data or struggle with the scale of modern encoders. This paper explores whether Knowledge Distillation (KD)—traditionally used for model compression—can be repurposed to filter out malicious behavior while preserving benign knowledge.

Methodology: Distillation-based Backdoor Mitigation

The proposed defense framework treats the poisoned encoder as a teacher and trains a clean student model to replicate its benign feature representations. The process acts as a bottleneck: the student learns general-purpose representations but fails to pick up the anomalous, overfitted associations created by the backdoor trigger.

Overview of the distillation-based backdoor mitigation framework, illustrating the transfer of knowledge from a teacher net to a student net using a small subset of clean data.

The framework consists of three main components:

  1. Teacher Net Design: The poisoned encoder is first "purified" using a small set of clean data (5% of the dataset). Standard Fine-Tuning (FT) proved most effective here, as it anchors benign knowledge without destroying the underlying feature space.
  2. Student Net Design: The student is initialized using a "Warm-up" phase—briefly training on the small clean set before distillation—to provide a clean slate oriented toward benign features.
  3. Distillation Loss: The study evaluated six loss functions, finding that Attention-based (ATD) losses performed best. By matching the teacher's "spatial importance maps," the student learns where to look for legitimate features, effectively ignoring localized triggers.

Experimental Evaluation

The study utilized four image classification benchmarks: CIFAR10 for pre-training, and STL10, GTSRB, and SVHN for downstream tasks. The defense assumes the defender has access to a small (5%) clean subset of data to facilitate the distillation process.

Key Results

Across various attacks (such as BadEncoder and BASSL), distillation significantly improved model security with minimal impact on utility:

  • Attack Mitigation: Distillation slashed the average Attack Success Rate (ASR) from 80.87% down to 27.51%.
  • Utility Preservation: The Accuracy (ACC) on clean downstream tasks only dropped by 6.35% on average.
Comparison of Accuracy (ACC) and Attack Success Rate (ASR) between undefended and distillation-defended models across various datasets.

Conclusion and Future Work

Distillation is a potent and generalizable defense strategy for SSL encoders, remaining effective across different architectures (ResNet18 to ResNet50) and SSL algorithms (SimCLR, MoCo-v2, BYOL). While the defense relies on a small clean dataset and faces challenges with advanced bi-level optimization attacks (like BLTO), it offers a robust mechanism to mitigate supply chain risks. Future research will explore explicitly regularizing feature subspaces to better disentangle malicious triggers from legitimate object features and testing these methods in non-visual modalities like NLP.

Summary updated

BibTeX
@misc{han2024effectiveness,
  author = {Tingxu Han and Shenghan Huang and Ziqi Ding and Weisong Sun and Yebo Feng and Chunrong Fang and Jun Li and Hanwei Qian and Cong Wu and Quanjun Zhang and Yang Liu and Zhenyu Chen},
  title = {{On the Effectiveness of Distillation in Mitigating Backdoors in Pre-trained Encoder}},
  year = {2024},
  eprint = {2403.03846},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2403.03846},
}
Figure