[Paper Review] When Adversarial Training Meets Vision Transformers: Recipes from Training to Architecture
This paper presents a comprehensive study on adversarial training for Vision Transformers (ViTs), identifying pre-training and SGD as essential training components for robustness. It introduces two novel architectural-aware methods—Attention Random Dropping (ARD) and Perturbation Random Masking (PRM)—that significantly improve adversarial robustness by randomly masking gradients in attention blocks or perturbations on patches during training, achieving state-of-the-art performance on CIFAR-10 and ImageNet-1K benchmarks.
Vision Transformers (ViTs) have recently achieved competitive performance in broad vision tasks. Unfortunately, on popular threat models, naturally trained ViTs are shown to provide no more adversarial robustness than convolutional neural networks (CNNs). Adversarial training is still required for ViTs to defend against such adversarial attacks. In this paper, we provide the first and comprehensive study on the adversarial training recipe of ViTs via extensive evaluation of various training techniques across benchmark datasets. We find that pre-training and SGD optimizer are necessary for ViTs' adversarial training. Further considering ViT as a new type of model architecture, we investigate its adversarial robustness from the perspective of its unique architectural components. We find, when randomly masking gradients from some attention blocks or masking perturbations on some patches during adversarial training, the adversarial robustness of ViTs can be remarkably improved, which may potentially open up a line of work to explore the architectural information inside the newly designed models like ViTs. Our code is available at https://github.com/mo666666/When-Adversarial-Training-Meets-Vision-Transformers.
Motivation & Objective
- To identify essential training techniques that enhance adversarial robustness in Vision Transformers (ViTs) under adversarial training.
- To investigate whether ViT's unique architectural components can be leveraged to further improve robustness beyond standard training recipes.
- To provide a practical, empirically validated benchmark (a 'bag of tricks') for adversarially training ViTs.
- To propose and evaluate novel architectural-aware defense mechanisms—ARD and PRM—based on gradient and perturbation masking.
Proposed method
- Empirically evaluate various training techniques (optimizer, pre-training, data augmentation, loss functions) on ViTs under adversarial training across CIFAR-10 and ImageNet-1K.
- Propose Attention Random Dropping (ARD), which randomly masks gradients from selected attention blocks during backpropagation to regularize feature learning.
- Introduce Perturbation Random Masking (PRM), which randomly masks perturbations on selected image patches during adversarial example generation to improve robustness.
- Apply ARD and PRM as warming-up strategies during early training epochs, using a shared hyperparameter $ n_w $ for both methods.
- Combine ARD and PRM with existing defense methods like TRADES and MART to evaluate their generalization and effectiveness.
- Conduct ablation studies on hyperparameters $ n_w $, including individual tuning for ARD and PRM, to optimize performance.
Experimental results
Research questions
- RQ1Which training techniques—such as optimizer choice, pre-training, or data augmentation—are most critical for adversarial robustness in ViTs?
- RQ2How does the architectural design of ViTs, particularly its self-attention mechanism, influence adversarial robustness compared to CNNs?
- RQ3Can architectural inductive biases in ViTs be exploited to improve adversarial robustness beyond standard adversarial training?
- RQ4What is the optimal configuration for ARD and PRM in terms of warm-up epochs and their interaction with standard defense methods?
- RQ5Does the combination of ARD and PRM consistently improve robustness across different ViT variants and datasets?
Key findings
- Pre-training and the use of SGD optimizer are essential for achieving high adversarial robustness in ViTs, with AdamW underperforming in adversarial training settings.
- Adversarial training with ARD and PRM improves robustness by up to 1.63% on PGD-100 attacks for DeiT-Ti on CIFAR-10, with consistent gains across multiple models.
- The combination of ARD and PRM with TRADES and MART yields state-of-the-art performance, increasing AA robustness on DeiT-Ti by 0.77% and 1.63% respectively.
- ARD shows a positive correlation with longer warm-up periods ($ n_w $), while PRM shows diminishing returns beyond optimal $ n_w $, indicating different sensitivity profiles.
- The proposed methods are robust to hyperparameter tuning, with performance improvements stable across $ n_w \in \{10,15,20\} $, enabling easy deployment.
- ARD and PRM are effective across diverse ViT architectures, including DeiT-Ti, ConViT-Ti, and Swin-Ti, demonstrating generalizability.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.