ON IMPROVING ADVERSARIAL TRANSFERABILITY OF VISION TRANSFORMERS
Year: 2021

Abstract:
Vision transformers (ViTs) process input images as sequences of patches via selfattention; a radically different architecture than convolutional neural networks (CNNs). This makes it interesting to study the adversarial feature space of ViT models and their transferability. In particular, we observe that adversarial patterns found via conventional adversarial attacks show very low black-box transferability even for large ViT models. We show that this phenomenon is only due to the sub-optimal attack procedures that do not leverage the true representation potential of ViTs. A deep ViT is composed of multiple blocks, with a consistent architecture comprising of self-attention and feed-forward layers, where each block is capable of independently producing a class token. Formulating an attack using only the last class token (conventional approach) does not directly leverage the discriminative information stored in the earlier tokens, leading to poor adversarial transferability of ViTs. Using the compositional nature of ViT models, we enhance transferability of existing attacks by introducing two novel strategies specific to the architecture of ViT models. (i) Self-Ensemble: We propose a method to find multiple discriminative pathways by dissecting a single ViT model into an ensemble of networks. This allows explicitly utilizing class-specific information at each ViT block. (ii) Token Refinement: We then propose to refine the tokens to further enhance the discriminative capacity at each block of ViT. Our token refinement systematically combines the class tokens with structural information preserved within the patch tokens. An adversarial attack when applied to such refined tokens within the ensemble of classifiers found in a single vision transformer has significantly higher transferability and thereby brings out the true generalization potential of the ViT’s adversarial space. Our code will be publicly released.

heading: 1 INTRODUCTION
text: Transformers compose a family of neural network architectures based on the self-attention mechanism, originally applied in natural language processing tasks achieving state-of-the-art performance (Vaswani et al., 2017; Devlin et al., 2018; Brown et al., 2020). The transformer design has been subsequently adopted for vision tasks (Dosovitskiy et al., 2020), giving rise to a number of successful vision transformer (ViT) models (Touvron et al., 2020; Yuan et al., 2021; Khan et al., 2021). Due to the lack of explicit inductive biases in their design, ViTs are inherently different from convolutional neural networks (CNNs) that encode biases e.g., spatial connectivity and translation equivariance. ViTs process an image as a sequence of patches which are refined through a series of self-attention mechanisms (transformer blocks), allowing the network to learn relationships between any individual parts of the input image. Such processing allows wide receptive fields which can model global context as opposed to the limited receptive fields of CNNs. These significant differences between ViTs and CNNs give rise to a range of intriguing characteristics unique to ViTs (Caron et al., 2021; Tuli et al., 2021; Mao et al., 2021; Paul & Chen, 2021; Naseer et al., 2021b).
Adversarial attacks pose a major hindrance to the successful deployment of deep neural networks in real-world applications. Recent success of ViTs means that adversarial properties of ViT models also become an important research topic. A few recent works explore adversarial robustness of ViTs (Shao et al., 2021; Mahmood et al., 2021; Bhojanapalli et al., 2021) in different attack settings. Surprisingly, these works show that large ViT models exhibit lower transferability in black-box attack setting, despite their higher parameter capacity, stronger performance on clean images, and
better generalization (Shao et al., 2021; Mahmood et al., 2021). This finding seems to indicate that as ViT performance improves, its adversarial feature space gets weaker. In this work, we investigate whether the weak transferability of adversarial patterns from high-performing ViT models, as reported in recent works (Shao et al., 2021; Mahmood et al., 2021; Bhojanapalli et al., 2021), is a result of weak features or a weak attack. To this end, we introduce a highly transferable attack approach that augments the current adversarial attacks and increase their transferability from ViTs to the unknown models. Our proposed transferable attack leverages two key concepts, multiple discriminative pathways and token refinement, which exploit unique characteristics of ViT models.
Our approach is motivated by the modular nature of ViTs (Touvron et al., 2020; Yuan et al., 2021; Mao et al., 2021): they process a sequence of input image patches repeatedly using multiple multi-headed self-attention layers (transformer blocks) (Vaswani et al., 2017). We refer to the representation of patches at each transformer block as patch tokens. An additional randomly initialized vector (class token1) is also appended to the set of patch tokens along the network depth to distill discriminative information across patches. The collective set of tokens is passed through the multiple transformer blocks followed by passing of the class token through a linear classifier (head) which is used to make the final prediction. The class token interacts with the patch tokens within each block and is trained gradually across the blocks until it is finally utilized by the linear classifier head to obtain class-specific logit values. The class token can be viewed as extracting information useful for the final prediction from the set of patch tokens at each block. Given the role of the class token in ViT models, we observe that class tokens can be extracted from the output of each block and each such token can be used to obtain a class-specific logit output using the final classifier of a pretrained model. This leads us to the proposed self-ensemble of models within a single transformer (Fig. 1). We show that attacking such a self-ensemble (Sec. 3) containing multiple discriminative pathways significantly improves adversarial transferability from ViT models, and in particular from the large ViTs.
Going one step further, we study if the class information extracted from different intermediate ViT blocks (of the self-ensemble) can be enhanced to improve adversarial transferability. To this end, we introduce a novel token refinement module directed at enhancing these multiple discriminative pathways. The token refinement module strives to refine the information contained in the output of each transformer block (within a single ViT model) and aligns the class tokens produced by the intermediate blocks with the final classifier in order to maximize the discriminative power of intermediate blocks. Our token refinement exploits the structural information stored in the patch tokens and fuses it with the class token to maximize the discriminative performance of each block.
Both the refined tokens and self-ensemble ideas are combined to design an adversarial attack that is shown to significantly boost the transferability of adversarial examples, thereby bringing out the true generalization of ViTs’ adversarial space. Through our extensive experimentation, we empirically demonstrate favorable transfer rates across different model families (convolutional and transformer) as well as different vision tasks (classification, detection and segmentation).
1Average of patch tokens can serve as a class token in our approach for ViT designs that do not use an explicit class token such as Swin transformer (Liu et al., 2021) or MLP-Mixer (Tolstikhin et al., 2021)

heading: 2 BACKGROUND AND RELATED WORK
text: Adversarial Attack Modeling: Adversarial attack methods can be broadly categorized into two categories, white-box attacks and black-box attacks. While the white-box attack setting provides the attacker full access to the parameters of the target model, the black-box setting prevents the attacker from accessing the target model and is therefore a harder setting to study adversarial transferability.
White-box Attack: Fast Gradient Sign Method (FGSM) (Goodfellow et al., 2014) and Projected Gradient Descent (PGD) (Madry et al., 2018) are two initially proposed white-box attack methods. FGSM corrupts the clean image sample by taking a single step within a small distance (perturbation budget ) along the objective function’s gradient direction. PGD corrupts the clean sample for multiple steps with a smaller step size, projecting the generated adversarial example onto the -sphere around the clean sample after each step. Other state-of-the-art white-box attack methods include Jacobian-based saliency map attack (Papernot et al., 2016), Sparse attack (Modas et al., 2019), Onepixel attack (Su et al., 2019), Carlini and Wagner optimization (Carlini & Wagner, 2017), Elastic-net (Chen et al., 2018), Diversified sampling (Tashiro et al., 2020), and more recently Auto-attack (Croce & Hein, 2020b). We apply white-box attacks on surrogate models to find perturbations that are then transferred to black-box target models.
Black-box Attack and Transferability: Black-box attacks generally involve attacking a source model to craft adversarial signals which are then applied on the target models. While gradient estimation methods that estimate the gradients of the target model using black-box optimization methods such as Finite Differences (FD) (Chen et al., 2017; Bhagoji et al., 2018) or Natural Evolution Strategies (NES) (Ilyas et al., 2018; Jiang et al., 2019) exist, these methods are dependent on multiple queries to the target model which is not practical in most real-world scenarios. In the case of adversarial signal generation using source models, it is possible to directly adopt white-box methods. In our work, we adopt FGSM and PGD in such a manner. Methods like (Dong et al., 2018) incorporate a momentum term into the gradient to boost the transferability of existing white-box attacks, building attacks named MIM. In similar spirit, different directions are explored in literature to boost transferability of adversarial examples; a) Enhanced Momentum: Lin et al. (Lin et al., 2019) and Wang et al. (Wang & He, 2021) improve momentum by using Nesterov momentum and variance tuning respectively during attack iterations, b) Augmentations: Xie et al. (Xie et al., 2019) showed that applying differentiable stochastic transformations can bring diversity to the gradients and improve transferability of the existing attacks, c) Exploiting Features: Multiple suggestions are proposed in the literature to leverage the feature space for adversarial attack as well. For example, Zhou et al. (Zhou et al., 2018) incorporate the feature distortion loss during optimization. Similarly, (Inkawhich et al., 2020b;a; Huang et al., 2019) also exploit intermediate layers to enhance transferability. However, combining the intermediate feature response with final classification loss is non-trivial as it might require optimization to find the best performing layers (Inkawhich et al., 2020b;a), and d) Generative Approach: Orthogonal to iterative attacks, generative methods (Poursaeed et al., 2018; Naseer et al., 2019; 2021a) train an autoencoder against the white-box model. In particular, Naseer et al. show that transferability of an adversarial generator can be increased with relativistic cross-entropy (Naseer et al., 2019) and augmentations (Naseer et al., 2021a). Ours is the first work to address limited transferability of ViT models.
The Role of Network Architecture: Recent works exploit architectural characteristics of networks to improve the transferability of attacks. While Wu et al. (2020) exploit skip connections of models like ResNets and DenseNets to improve black-box attacks, Guo et al. (2020) build on similar ideas focused on the linearity of models.
Our work similarly focuses on unique architectural characteristics of ViT models to generate more transferable adversarial perturbations with the existing white-box attacks.
Robustness of ViTs: Adversarial attacks on ViT models are relatively unexplored. Shao et al. (2021) and Bhojanapalli et al. (2021) investigate adversarial attacks and robustness of ViT models studying various white-box and black-box attack techniques. The transferability of perturbations from ViT models is thoroughly explored in (Mahmood et al., 2021) and they conclude that ViT models do not transfer well to CNNs, whereas we propose a methodology to solve this shortcoming. Moreover, Mahmood et al. (2021) explores the idea of an ensemble of CNN and ViT models to improve the transferability of attacks. Our proposed ensemble approach explores a different direction by converting a single ViT model into a collection of models (self-ensemble) to improve attack
Figure 2: Adversarial examples for ViTs have only moderate transferability. In fact transferabililty (%) of MIM (Dong et al., 2018) perturbations to target models goes down as the source model size increases such as from DeiT-T (Touvron et al., 2020) (5M parameters) to DeiT-B (Touvron et al., 2020) (86M parameters). However, the performance of the attack improves significantly when applied on our proposed ensemble of classifiers found within a ViT (MIME & MIMRE).
transferability. In essence, our proposed method can be integrated with existing attack approaches to take full advantage of the ViTs’ learned features and generate transferable adversaries.

heading: 3 ENHANCING ADVERSARIAL TRANSFERABILITY OF VITS
text: Preliminaries: Given a clean input image sample x with a label y, a source ViT model F and a target modelM which is under-attack, the goal of an adversarial attack is generating an adversarial signal, x′, using the information encoded within F , which can potentially change the target network’s prediction (M(x′)argmax 6= y). A set of boundary conditions are also imposed on the adversarial signal to control the level of distortion in relation to the original sample, i.e., ‖x− x′‖p < , for a small perturbation budget and a p-norm, often set to infinity norm (`∞).
Motivation: The recent findings (Shao et al., 2021; Mahmood et al., 2021) demonstrate low black-box transferability of ViTs despite their higher parametric complexity and better feature generalization. Motivated by this behaviour, we set-up a simple experiment of our own to study the adversarial transferability of ViTs (see Fig. 2). We note that transferability of adversarial examples found via momentum iterative fast gradient sign method (Dong et al., 2018) (MIM) at `∞ ≤ 16 on DeiT (Touvron et al., 2020) does not increase with model capacity. In fact, adversarial transferability from DeiT base model (DeiT-B) on ResNet152 and large vision transformer (ViT-L (Dosovitskiy et al., 2020)) is lower than DeiT tiny model (DeiT-T). This is besides the fact that DeiT-B has richer representations and around 17× more parameters than DeiT-T. We investigate if this behavior is inherent to ViTs or merely due to a sub-optimal attack mechanism. To this end, we exploit unique architectural characteristics of ViTs to first find an ensemble of networks within a single pretrained ViT model (self-ensemble, right Fig. 1). The class token produced by each self-attention block is processed by the final local norm and classification MLP-head to refine class-specific information (Fig. 2). In other words, our MIME and MIMRE variants attack class information stored in the class tokens produced by all the self-attention blocks within the model and optimize for the adversarial example (Sec. 3.1 and 3.2). Exploring the adversarial space of such multiple discriminative pathways in a self-ensemble generates highly transferable adversarial examples, as we show next.

heading: 3.1 SELF-ENSEMBLE: DISCRIMINATIVE PATHWAYS OF VISION TRANSFORMER
text: A ViT model (Dosovitskiy et al., 2020; Touvron et al., 2020), F , with n transformer blocks can be defined as F = (f1 ◦ f2 ◦ f3 ◦ . . . fn) ◦ g, where fi represents a single ViT block comprising of multi-head self-attention and feed-forward layers and g is the final classification head. To avoid notation clutter, we assume that g consists of the final local norm and MLP-head (Touvron et al., 2020; Dosovitskiy et al., 2020). Self-attention layer within the vision transformer model takes a sequence of m image patches as input and outputs the processed patches. We will refer to the representations associated with the sequence of image patches as patch tokens, Pt ∈ Rm×d (where d is the dimensionality of each patch representation). Attention in ViT layers is driven by minimizing the empirical risk during training. In the case of classification, patch tokens are further appended with the class token (Qt ∈ R1×d). These patch and class tokens are refined across multiple blocks (fi) and attention in these layers is guided such that the most discriminative information from patch tokens is preserved within the class token. The final class token is then projected to the number of classes by the classifier, g. Due to the availability of class token at each transformer block, we can create an ensemble of classifiers by learning a shared classification head at each block along the ViT hierarchy. This provides us an ensemble of n classifiers from a single ViT, termed as the self-ensemble:
Fk =
( k∏
i=1
fi
) ◦ g, where k = 1, 2, . . . , n. (1)
We note that the multiple classifiers thus formed hold significant discriminative information. This is validated by studying the classification performance of each classifier (Eq. 1) in terms of top-1 (%) accuracy on ImageNet validation set, as demonstrated in Fig. 3. Note that multiple intermediate layers perform well on the task, especially towards the end of the ViT processing hierarchy.
For an input image x with label y, an adversarial attack can now be optimized for the ViT’s selfensemble by maximizing the loss at each ViT block. However, we observe that initial blocks (1-6) for all considered DeiT models do not contain useful discriminative information as their classification accuracy is almost zero (Fig. 3). During the training of ViT models (Touvron et al., 2020; Yuan et al., 2021; Mao et al., 2021), parameters are updated based on the last class token only, which means that the intermediate tokens are not directly aligned with the final classification head, g in our self-ensemble approach (Fig. 3) leading to a moderate classification performance. To resolve this, we introduce a token refinement strategy to align the class tokens with the final classifier, g, and boost their discriminative ability, which in turn helps improve attack transferability. We explain the refinement process below.

heading: 3.2 TOKEN REFINEMENT
text: As mentioned above, the multiple discriminative pathways within a ViT give rise to an ensemble of classifiers (Eq. 1). However, the class token produced by each attention layer is being processed by the final classifier, g. This puts an upper bound on classification accuracy for each token which is lower than or equal to the accuracy of the final class token. Our objective is to push the accuracy of the class tokens in intermediate blocks towards the upper bound as defined by the last token. For this purpose, we introduced a token refinement module to fine-tune the class tokens.
Our proposed token refinement module is illustrated in Fig. 4. It acts as an intermediate layer inserted between the outputs of each block (after the shared norm layer) and the shared classifier head. Revisiting our baseline ensemble method (Fig. 1), we note that the shared classifier head contains weights directly trained only on the outputs of the last transformer block. While the class tokens of previous layers may be indirectly optimized to align with the final classifier, there exists a potential for misalignment of these features with the classifier: the pretrained classifier (containing weights compatible with the last layer class token) may not extract all the useful information from the previous layers. Our proposed module aims to solve this misalignment by refining the class tokens in a way such that the shared (pretrained) classifier head is able to extract all discriminative information contained within the class tokens of each block. Moreover, intermediate patch tokens may contain additional information that is not at all utilized by the class tokens of those blocks, which would also be addressed by our proposed block. Therefore, we extract both patch tokens and the class token from each block and process them for refinement, as explained next.
−Patch Token Refinement: One of the inputs to the token refinement module is the set of patch tokens output from each block. We first rearrange these patch tokens to regain their spatial relationships. The aim of this component within the refinement module is to extract information relevant to spatial structure contained within the intermediate patch tokens. We believe that significant discriminative information is contained within these patches. The obtained rearranged patch tokens are passed through a convolution block (standard ResNet block containing a skip connection) to obtain a spatially aware feature map, which is then average pooled to obtain a single feature vector (of same dimension as the class token). This feature vector is expected to extract all spatial information from patch tokens.
−Class Token Refinement: By refining the class tokens of each block, we aim to remove any misalignment between the existing class tokens and the shared (pretrained) classifier head. Also, given how the class token does not contain a spatial structure, we simply use a linear layer to refine it. We hypothesize that refined class token at each block would be much more aligned with the shared classifier head allowing it to extract all discriminative information contained within those tokens.
−Merging Patch and Class Token: We obtain the refined class token and the patch feature vector (refined output of patch tokens) and sum them together to obtain a merged token. While we tested multiple approaches for merging, simply summing them proved sufficient.
−Training: Given a ViT model containing k transformer blocks, we plugin k instances of our token refinement module to the output of each block as illustrated in Figure 4. We obtain the pretrained model, freeze all existing weights, and train only the k token refinement modules for only a single epoch on ImageNet training set. We used SGD optimizer with learning rate set to 0.001. Training finishes in less than one day on a single GPU-V100 even for a large ViT model such as DeiT-B (Touvron et al., 2020).
As expected, the trained token refinement module leads to increased discriminability of the class tokens, which we illustrate in Figure 5. Note how this leads to significant boosting of discriminative power especially in the earlier blocks, solving the misalignment problem. We build on this enhanced discriminability of the ensemble members towards better transferability, as explained next.

heading: 3.3 ADVERSARIAL TRANSFER
text: Our modifications to ViT models with respect to multiple discriminative pathways and token refinement are exploited in relation to adversarial transfer. We consider black-box attack perturbations are generated using a source (surrogate) ViT model. The source model is only pretrained on ImageNet, modified according to our proposed approach and is subsequently fine-tuned to update only the token refinement module for a single epoch. We experiment with multiple white-box attacks, generating the adversarial examples using a joint loss over the outputs of each block. The transferability of adversarial examples is tested on a range of CNN and ViT models. Given input sample x and its label y, the adversarial object for our self-ensemble (Eq. 1) for the untargeted attack is defined as,
max x′ k∑ i=1 [[Fk(x′)argmax 6= y]], s.t. ‖x− x′‖p ≤ , k ∈ {1, 2, . . . , n} (2)
where [[·]] is an indicator function. In the case of target attack, the attacker optimizes the above objective towards a specific target class instead of an arbitrary misclassification.

heading: 4 EXPERIMENTS
text: We conduct thorough experimentation on a range of standard attack methods to establish the performance boosts obtained through our proposed transferability approach. We create `∞ adversarial attacks with ≤ 16 and observe their transferability by using the following protocols: Source (white-box) models: We mainly study three vision transformers from DeiT (Touvron et al., 2020) family due to their data efficiency. Specifically, the source models are Deit-T, DeiT-S, and DeiT-B (with 5, 22, and 86 million parameters, respectively). They are trained without CNN distillation. Adversarial examples are created on these models using an existing white-box attack (e.g., FGSM (Goodfellow et al., 2014), PGD (Madry et al., 2018) and MIM (Dong et al., 2018)) and then transferred to the black-box target models.
Target (black-box) models: We test on black-box transferability across several vision tasks including classification, detection and segmentation. We consider convolutional networks BiT-ResNet50 (BiT50) (Beyer et al., 2021), ResNet152 (Res152) (He et al., 2016), Wide-ResNet-50-2 (WRN) (Zagoruyko & Komodakis, 2016), DenseNet201 (DN201) (Huang et al., 2017) and other ViT models including Token-to-Token transformer (T2T) (Yuan et al., 2021), Transformer in Transformer (TnT) (Mao et al., 2021), DINO (Caron et al., 2021), and Detection Transformer (DETR) (Carion et al., 2020) as the black-box target models.
Datasets: We use ImageNet training set to fine tune our proposed token refinement modules. For evaluating robustness, we selected 5k samples from ImageNet validation set such that 5 random samples from each class that are correctly classified by ResNet50 and ViT small (ViT-S) (Dosovitskiy et al., 2020) are present. In addition, we conduct experiments on COCO (Lin et al., 2014) (5k images) and PASCAL-VOC12 (Everingham et al., 2012) (around 1.2k images) validation set to test the cross-task transferability.
Evaluation Metrics: We report fooling rate (percentage of samples for which the predicted label is flipped after adding adversarial perturbations) to evaluate classification. In the case of object detection, we report the decrease in mean average precision (mAP) and for automatic segmentation, we use the popular Jaccard Index. Given the pixel masks for the prediction and the ground-truth, it calculates the ratio between the pixels belonging to intersection and the union of both masks.
Baseline Attacks: We show consistent improvements for single step fast gradient sign method (FGSM) (Goodfellow et al., 2014) as well as iterative attacks including PGD (Madry et al., 2018), MIM (Dong et al., 2018) and input diversity (transformation to the inputs) (DIM) (Xie et al., 2019) attacks. Iterative attacks ran for 10 iterations and we set transformation probability for DIM to default 0.7 (Xie et al., 2019). Our approach is not limited to specific attack settings, but existing attacks can simply be adopted to our self-ensemble ViTs with refined tokens. Refer to appendices A-J for extensive analysis with more ViT designs, attacks, datasets (CIFAR10 & Flowers), computational cost comparison, and latent space visualization of our refined token.

heading: 4.1 CLASSIFICATION
text: In this section, we discuss the experimental results on adversarial transferability across black-box classification models. For a given attack method ‘Attack’, we refer ‘AttackE’ and ‘AttackRE’ as self-ensemble and self-ensemble with refined tokens, respectively, which are the two variants of our approach. We observe that adversarial transferability from ViT models to CNNs is only moderate for conventional attacks (Tables 1 & 2). For example, perturbations found via iterative attacks from DeiT-B to Res152 has even lower transfer than VGG19bn. However, the same attacks when applied using our proposed ensemble strategy (Eq. 1) with refined tokens consistently showed improved transferability to other convolutional as well as transformer based models. Strength of our method is also evident by blockwise fooling rate in white-box setting (Fig. 6). It is noteworthy how MIM fails to fool the initial blocks of ViT, while our approach allows the attack to be as effective in the intermediate blocks as for the last class token. This ultimately allows us to fully exploit ViT’s adversarial space leading to high transfer rates for adversarial perturbations. We observe that models without inductive biases that share architecture similarities show higher transfer rate of adversarial
Source (→) DeiT-T DeiT-S DeiT-B No Attack MIM MIMRE MIM MIMRE MIM MIMRE
38.5 24.0 19.7 23.7 19.0 22.9 16.9 DIM DIMRE DIM DIMRE DIM DIMRE
20.5 13.7 20.3 12.0 19.9 11.1
Table 3: Cross-Task Transferability (classification→detection) Object Detector DETR (Carion et al., 2020) is fooled. mAP at [0.5:0.95] IOU on COCO val set. Our self-ensemble approach with refined token (RE) significantly improves cross-task transferability. (lower the better)
Source (→) DeiT-T DeiT-S DeiT-B No Attack MIM MIMRE MIM MIMRE MIM MIMRE
42.7 32.5 31.6 32.5 31.0 32.6 30.6 DIM DIMRE DIM DIMRE DIM DIMRE
31.9 31.4 31.7 31.3 32.0 31.0
perturbations among them (e.g., from DeiT to ViT (Dosovitskiy et al., 2020)). We further observe that models trained with the same mechanism but lower parameters are more vulnerable to black-box attacks. For example, ViT-S and T2T-T are more vulnerable than their larger counterparts, ViT-L and T2T-24. Also models trained with better strategies that lead to higher generalizability are less vulnerable to black-box attacks e.g., BiT50 is more robust than ResNet152 (Tables 1 and 2).

heading: 4.2 CROSS-TASK TRANSFERABILITY
text: Self-attention is the core component of transformer architecture regardless of the task; classification (Dosovitskiy et al., 2020; Touvron et al., 2020; Yuan et al., 2021; Mao et al., 2021), object detection (Carion et al., 2020), or unsupervised segmentation (Caron et al., 2021). We explore the effectiveness of our proposed method on two additional tasks: object detection (DETR) (Carion et al., 2020) and segmentation (DINO) (Caron et al., 2021). We select these methods considering the use of transformer modules employing the self-attention mechanism within their architectures. While the task of object detection contains multiple labels per image and involves bounding box regression, the unsupervised model DINO is trained in a self-supervised manner with no traditional image-level labels. Moreover, DINO uses attention maps of a ViT model to generate pixel-level segmentations, which means adversaries must disrupt the entire attention mechanism to degrade its performance.
We generate adversarial signals on source models with a classification objective using their initial predictions as the label. In evaluating attacks on detection and segmentation tasks at their optimal setting, the source ViT need to process images of different sizes (e.g., over 896×896 pix for DETR). To cater for this, we process images in parts (refer appendix G) which allows generation of stronger adversaries. The performance degradation of DETR and DINO on generated adversaries are summarised in Tables 3 & 4. For DETR, we obtain clear improvements. In the more robust DINO model, our transferability increases well with the source model capacity as compared to the baseline.

heading: 5 CONCLUSION
text: We identify a key shortcoming in current state-of-the-art approaches for adversarial transferability of vision transformers (ViTs) and show the potential for much strong attack mechanisms that would exploit the architectural characteristics of ViTs. Our proposed novel approach involving multiple discriminative pathways and token refinement is able to fill in these gaps, achieving significant performance boosts when applied over a range of state-of-the-art attack methods.
Reproducibility Statement: Our method simply augments the existing attack approaches and we used open source implementations. We highlight the steps to reproduce all of the results presented in our paper, a) Attacks: We used open source implementation of patchwise attack (Gao et al., 2020) and Auto-Attack (Croce & Hein, 2020b) (refer Appendix B) with default setting. Wherever necessary, we clearly mention attack parameters, e.g., iterations for PGD (Madry et al., 2018), MIM (Dong et al., 2018) and DIM (Xie et al., 2019) in section 4 (Experiments: Baseline Attack). Similarly, transformation probability for DIM is set to the default value provided by the corresponding authors that is 0.7, b) Refined Tokens: We fine tuned class tokens for the pretrained source models (used to create perturbations) using open source code base (https: //github.com/pytorch/examples/tree/master/imagenet). We provided training details for fine tuning in section 3.2. Further, we will publicly release all the models with refined tokens, c) Cross-Task Attack Implementation: We provided details in section 4.2 and pseudo code in appendix G for cross-task transferability (from classification to segmentation and detection), and d) Dataset: We describe the procedure of selecting subset (5k) samples from ImageNet val. set in section 4. We will also release indices of these samples to reproduce the results.
Ethics Statement: Since our work focuses on improving adversarial attacks on models, in the short run our work can assist various parties with malicious intents of disrupting real-world deployed deep learning systems dependent on ViTs. However, irrespective of our work, the possibility of such threats emerging exists. We believe that in the long run, works such as ours will support further research on building more robust deep learning models that can withstand the kind of attacks we propose, thus negating the short term risks. Furthermore, a majority of the models used are pre-trained on ImageNet (ILSVRC’12). We also conduct our evaluations using this dataset. The version of ImageNet used contains multiple biases that portray unreasonable social stereotypes. The data contained is mostly limited to the Western world, and encodes multiple gender / ethnicity stereotypes Yang et al. (2020) while also posing privacy risks due to unblurred human faces. In future, we hope to use the more recent version of ImageNet Yang et al. (2021) which could address some of these issues.

heading: A SELF-ENSEMBLE WITHIN ENSEMBLE
text: We created an ensemble of pre-trained Deit models (Touvron et al., 2020) including Deit-T, DeitS and DeiT-B. These models have 12 blocks (layers) and differ in patch embedding size. These models are trained in a similar fashion without distillation from CNN. As expected, adversarial transferability improves with an ensemble of models (Table 5). We also note that unlike such multiple-model ensemble approaches, our self-ensemble attack achieves performance improvements with minimal increase in computational complexity of the attack that is from a single ViT. Our self-ensemble extended three classifiers ensemble to an ensemble of 36 classifiers. Such multi-model ensemble combined with our proposed self-ensemble with refined tokens approach leads to clear attack improvements in terms of transferability (refer Table 5).

heading: B SELF-ENSEMBLE FOR MORE ATTACKS: PATCHWISE AND AUTO-ATTACK
text: We conducted additional experiments with recent methods such as Patch-wise attack Gao et al. (2020) and Auto-Attack Croce & Hein (2020b) to show case that our approach does not need special setup and can be used as plug-and-play with the existing attacks. Patch-wise Gao et al. (2020) is a recent black-box attack while Auto-Attack is a combination of PGD with novel losses and other attacks such as bounday-based, FAB (Croce & Hein, 2020a) and, query based Square attack (Andriushchenko et al., 2020). In each case, attack transferability is increased significantly using our approach of self-ensemble with refined tokens (refer Table 6).

heading: C SELF-ENSEMBLE FOR DIFFERENT : 4, 8, 16
text: We evaluate if adversarial transferability boost provided by our method also hold for large number of attack iterations such PGD with 100 iterations and Auto-Attack which is based on multiple random restarts, thousands of queries, etc. We further evaluate adversarial transfer at various perturbation budgets, such as 4, 8, and 16. Our self-ensemble with refined tokens approach consistently improves black-box adversarial transfer under such attack setting, thus making them not only powerful in white-box but also in black-box setting. Results are presented in Table 7.

heading: D SELF-ENSEMBLE FOR MORE DATASETS: CIFAR10 AND FLOWERS
text: We extended our approach to CIFAR10 and Flowers datasets. Since ViT training from scratch on small datasets is unstable Touvron et al. (2020); Yuan et al. (2021), we fine-tuned ViTs trained on ImageNet on CIFAR10 and Flowers. Transferability of adversarial attacks increases with notable gains by using our approach based on self-ensemble and refined tokens (refer Tables 8, 9, 10 and 11).
E VULNERABILITY OF SWIN TRANSFORMER
We show how the black-box vulnerability of ViT architecture without explicit class token (Swin transformer (Liu et al., 2021)) increases against our approach (refer Table 12).

heading: F FULL IMAGENET VALIDATION SET
text: In line with most existing attack methods, we use subset of ImageNet (5k samples, 5 samples from each class) for all our experiments. Our subset from ImageNet is balanced as we sample from each class. We will release the image-indices of ours subset publicly to reproduce the results.
Additionally, we re-run our best performing attacks (MIM and DIM) on the whole ImageNet val. set (50k samples) to validate the merits of our approach ( refer Table 13). Our approach shows considerable improvements in attack transferability regardless the dataset size.

heading: G CROSS-TASK TRANSFERABILITY WITH LARGER IMAGES (>224)
text: We generate adversarial signals on source models with a classification objective using their initial predictions as the label (Algorithm 1). In the case of ViT models trained on 224x224 images, we rescale all larger images to a multiple of 224x224, split them into smaller 224x224 image portions, obtain the prediction of the source (surrogate) model for each smaller image portion, and apply the attack separately for each image portion using the prediction as the label for the adversarial objective function (Algorithm 2). For example, in the case of DETR, we use an image size of 896 x 896, split
it into 16 portions of size 224x224, and use these to individually generate adversarial signals which we later combine to build a joint 896x896 sized adversary.
Algorithm 1 Cross-Task Attack
0 for samples, targets in (dataloader): 1 orig_shape = samples.shape 2 3 # run attack 4 with torch.no_grad(): 5 clean_out = src_model(temp) 6 label = clean_out.argmax(dim=-1).detach() 7 8 adv = generate_adversary(src_model, temp, label) 9 # done running attack
10 11 samples = adv 12 # continue model evaluation
We run a generic attack on crosstasks where a single image level label is not available. The source model is used to generate a label (its original prediction) which is used as the target for the whitebox attack. The adversarial signal we thus generate is applied onto the target task.
Algorithm 2 Attack for different input sizes
0 for samples, targets in (dataloader): 1 orig_shape = samples.shape 2 3 # run attack 4 product_list = product([0, 1, 2, 3], [0, 1, 2, 3] 5 temp = torch.cat([ 6 samples[:,:,224*x:224*(1+x),224*y:224*(1+y] 7 for x, y in product_list)], dim=0) 8 9 with torch.no_grad():
10 clean_out = src_model(temp) 11 label = clean_out.argmax(dim=-1).detach() 12 13 adv = generate_adversary(src_model, temp, label) 14 temp = torch.zeros_like(samples) 15 for idx, (x, y) in enumerate(product_list): 16 temp[:,:,224*x:224*(1+x),224*y:224*(1+y)] = 17 adv[orig_shape[0]*idx:orig_shape[0]*(idx+1)] 18 adv = temp 19 assert orig_shape == adv.shape 20 # done running attack 21 samples = adv 22 # continue model evaluation
We run a modified version of the attack for cross-task experiments requiring specific input sizes not compatible with the ViT models’ input size. We split larger images into smaller image portions, generate adversarial signals separately for each portion, and combine these to obtain a joint adversarial signal relevant to the entire image. For each image portion, we use the source model to generate a label (its prediction for that image portion), and use it as the target when generating the adversarial signal.

heading: H COMPUTATION COST AND INFERENCE SPEED ANALYSIS
text: In this section, we analyze the parameter complexity and computational cost of our proposed approach. The basic version of our self-ensemble (AttackE) only uses an off the shelf pretrained ViT without adding any additional parameters. However, we introduce additional learnable parameters with token refinement module to solve misalignment problem between the tokens produced by an intermediate block and the final classifier of a vision transformer (Sec. 3.2). Our refinement module processes
Attack Inference Speed Analysis
Model Self-ensemble Refined Tokens Attacks
FGSM PGD MIM DIM
Deit-T 7 7 0.19 1.48 1.49 1.51 3 7 0.19 1.59 1.69 1.6 3 3 0.23 2.12 2.13 2.15
Deit-S 7 7 0.34 3.22 3.21 3.23 3 7 0.36 3.34 3.32 3.35 3 3 0.54 5.19 5.22 5.24
Deit-B 7 7 0.97 9.45 9.32 9.27 3 7 1.0 9.66 9.43 9.44 3 3 1.64 16.15 15.88 15.9
Table 14: We compare inference speed (in minutes) of attacks on the conventional model against the attack on our proposed selfensemble (with and without refinement module). We used 5k selected samples (Sec. 4) from ImageNet validation set for this experiment and all iterative attacks (PGD, MIM, DIM) ran for 10 iterations. Inference speed is computed using Nvidia Quadro RTX 6000 with Pytorch library.
class and patch tokens using MLP (linear layer) and Convolutional block (Fig. 8) and its parameter complexity is dependent on the embedding dimension of these pretrained tokens. For example, DeiT-S produces tokens with embedding dimension of size R384 and our refinement module adds 1.47 million parameters to its sub-model within the self-ensemble trained with refined tokens.
Fine tuning with additional parameters provides notable gains in recognition accuracy. Our approach increases top-1 (%) accuracy (averaged across self-ensemble) by 12.43, 15.21, and 16.70 for Deit-T, Deit-S, and DeiT-B, respectively. Similar trend holds for the convolutional vision transformer (Wu et al., 2021) and MLP-Mixer (Tolstikhin et al., 2021) as well (Fig. 10).
Further, we analyze inference speed for different attacks in Table 14. The computational cost difference between the attack on a conventional model and the attack on our self-ensemble (without refinement module) is only marginal. As expected, attacking self-ensemble with refinement module is slightly more expensive, however, the notable difference is only with very large models such as DeiT-B. In fact, the increase in computational cost is a function of he original complexity of the pre-trained ViT model e.g., DeiT-B with an original parametric complexity of 86 million generates high-dimensional tokens R784, which leads to higher compute cost in our refinement module.
H.1 LATENT SPACE OF REFINED TOKENS
We visualize the latent space of our refined tokens in Fig. 9. We randomly selected 10 classes from ImageNet validation set distributed across the entire dataset. We extracted class tokens with and without refinement from the intermediate blocks (5,6,7,8) of Deit-T, Deit-S, and Deit-B. Our refined tokens have lower intra-class variations i.e., feature representations of samples from the same class are clustered together. Furthermore, the refined tokens have better inter-class separation than the original tokens. This indicates that refinement minimizes the misalignment between the final classifier and intermediate class tokens, which leads to more disentangled representations. Attacking such disentangled representations across the self-ensemble allows us to find better adversarial direction that leads to more powerful attacks.

heading: I SELF-ENSEMBLE FOR HYBRID VIT AND MLP-MIXER
text: In this section, we apply our proposed approach to a diverse set of ViT models including a hybrid vision transformer (convolutional vision transformer (CvT) (Wu et al., 2021)) as well as a MLP-Mixer (Tolstikhin et al., 2021). CvT design incorporates convolutional properties into the ViT architecture. We apply our approach on two CvT models, CvT-Tiny (CvT-T) and CvT-Small (CvT-S). We create 10 and 16 models within self-ensemble of CvT-T and CvT-S, respectively. On the other hand, MLP-Mixer thrives on a simplistic architecture design. It does not have self-attention layers or class token. We use an average of patch tokens as class token in this case and create 12 models within self-ensemble of MLP-Mixer-Base (Mixer-B). We train refinement module for each of these models using the same setup as described in Sec. 3.2. The refined class tokens show clear improvements in top-1 (%) accuracy on ImageNet validation set (Fig. 10). Similarly attacking self-ensemble with refined tokens has non-trivial boost in attack transferability (Table 15). The successful application of our approach to such diverse ViT designs highlights the generality of our method.

heading: J CAN SELF-ENSEMBLE IMPROVE TRANSFERABILITY FROM CNN?
text: Our proposed idea of the self-ensemble can be applied to a CNN model (e.g., ResNet50) with an average pooling operation over the intermediate layer outputs. However, due to the varying channel dimension of feature maps across a pretrained CNN , building an ensemble with a shared classifier is not as straight-forward as in ViT (where equidimensional class token is available at each level). For example, ResNet50 has four intermediate blocks that produce feature maps of sizes R256×56×56, R512×28×28, R1024×14×14, and R2048×7×7, respectively. Then, the final classifier processes the average pooled features from the last block. Since there is a mismatch between feature dimensions of the intermediate layers and the final classifier, therefore applying the basic version of our self-ensemble approach (AttackE) is not possible for the pretrained ResNet.
An intermediate layer is essential to project intermediate feature vectors to the same dimension as the final feature vector in the case of CNNs. Therefore, for the refined embedding variant of
our approach, we finetune ResNet50 features to create self-ensemble with the procedure described in Sec. 3.2. We report the relative improvements of self-ensemble with refined features w.r.t the original (single) model and compare ResNet50 with Deit-S (Fig. 11). Both these off-the-shelf models, ResNet50 (25 million parameters) and Deit-S (22 million parameters), are comparable in terms of their computational complexity. We observe that feature refinement also helps to boost adversarial transferability from the ResNet50 model. However, adversarial transferability improvement of our self-ensemble with token refinement on ViTs is considerably better than for the case of ResNet50.
These results suggest that the proposed approach is well-suited for improving adversarial transferability of ViT models.

Review summaries:
The paper looks at Vision Transforms (ViTs) models and transferability of adversarial examples, which is previously known to be challenging between ViTs to CNNs and vice versa. The paper leverages the discriminative information stored in the lower layers' tokens and proposes two methods that modify and fine-tune the ViTs in order to extract the adversarial samples. The paper conducts extensive experiments to show the effectiveness in adversarial transferability across different models, including CNN's and ViT's variants, and tasks.

In this paper,  authors improve adversarial transferability of ViT by Self-Ensemble and Token Refinement method. 'Self-Ensemble' implies it treats each transformer block of ViT as the 'last block' and apply a shared classifier to it. So that the trivial discriminative path can be attacked. 'Token Refinement' tries to improve the classification ablity of shallow blocks by using extra non-shared module on each block's output tokens. This paper successfully improved the adversarial ability of ViT attacks. Sufficient experimental results and detailed description ensure its reproducibility.

 This paper enhances transferability of vision transformers (ViT) by introducing two strategies specific to the architecture of ViT models, i.e. Self-Ensemble and Token refinement. Specifically,  Self-Ensemble finds multiple discriminative pathways by dissecting a single ViT model into an ensemble of networks, leading to an explicit utilization of class-specific information at each ViT block. In addition, the proposed Token Refinement can potentially enhance the discriminative capacity at each block of ViT.   The high-level motivation of this paper is that the adversarial patterns found via conventional adversarial attacks show very low black-box transferability for ViT models. The authors claim that this phenomenon is due to the sub-optimal attack procedures that do not leverage the true representation potential of the ViTs. Thus, this paper introduces a highly transferable attack approach that augments the current adversarial attacks and increases their transferability from ViTs to the unknown models.   The paper conduct experiments on a range of standard attack methods to establish the performance boost obtained through the proposed transferablility approach by using the Source (white-box) models, Target (black-box) models. The experiments conducted on ImageNet/COCO dataset, and PASCAL demonstrate that the proposed method can outperform the baselines on some of the experimental settings. The paper also provides a detailed analysis of the model and experimental results.