Give Me Your Attention: Dot-Product Attention Considered Harmful for Adversarial Patch Robustness

Giulio Lovisotto, Nicole Finnie, Mauricio Munoz, Chaithanya Kumar Mummadi, Jan Hendrik Metzen · DOI

Abstract

While Vision Transformers (ViTs) are often praised for their robustness, this research reveals a critical "single point of failure": the dot-product attention mechanism. By using a novel attack called Attention-Fool, researchers demonstrated that an adversarial patch occupying just 0.5% of an image can "hijack" a model's attention, effectively blinding it to every other object in the scene and dropping accuracy to near zero.

Introduction

In the world of computer vision, Transformers have rapidly become the gold standard. Their attention mechanism allows them to reason about an entire scene globally rather than looking through the "keyhole" of local convolutions. However, this global connectivity is a double-edged sword. The authors identify a specific vulnerability: Adversarial Patches. Unlike subtle perturbations spread across an entire image, patches are small, visible, and localized. Standard gradient-based attacks often fail to fully exploit Transformer vulnerabilities because the "softmax" operation in attention layers often "saturates," causing gradients to vanish. This paper aims to prove that dot-product attention is fundamentally susceptible to being "hijacked" by a single malicious token.

The Attention-Fool Attack

The researchers introduce Attention-Fool, a family of adversarial loss functions designed to bypass the limitations of standard attacks. Instead of optimizing for the final classification error, Attention-Fool targets the pre-softmax dot-product similarities. This ensures a strong gradient signal even when the model is confident.

The objective is simple but devastating: force the "key" token corresponding to the adversarial patch to be the most similar token for every "query" token in the image.

Figure 3: Visualization of the projected token space where an adversarial key is optimized to move into the query cluster, effectively bridging the gap and attracting all attention.

Mathematical analysis reveals that three conditions make this hijacking easier: large singular values in projection matrices, high embedding dimensions, and non-centered inputs (where the mean of input features is far from zero). The attack utilizes a "smooth maximum" (smax) to aggregate losses across multiple attention heads and layers, ensuring the patch is effective across the entire depth of the network.

Key Insights: Why Transformers are Vulnerable

In a CNN, a patch can only affect the pixels within its receptive field. In a Transformer, because every query looks at every key, one malicious key can attract the attention of every query in the image. This effectively "mutes" the information from all other patches.

Interestingly, the fact that Transformer inputs are often not zero-centered (due to LayerNorm and affine transformations) actually makes them more vulnerable. It creates distinct clusters of queries and keys, making it easier for a single adversarial key to "bridge the gap" and become the most relevant token for the entire query cluster.

Experimental Results

The study evaluated the attack on ImageNet-1K (classification) and MS COCO (object detection). The results show that Transformers are significantly more fragile to patches than previously thought:

  • Total Blindness: For a ViT-T model on ImageNet, a patch covering only 0.5% of the image reduced robust accuracy from ~73% to 0%.
  • Object Detection Failure: On the DETR model (MS COCO), the attack reduced the Mean Average Precision (mAP) from ~53% to less than 3%.
Figure 4: An attention map demonstrating the result of the attack; the model's attention is entirely consumed by the tiny adversarial patch (red dot), ignoring the rest of the scene.

Under these specific patch attacks, ViTs were found to be considerably less robust than a standard ResNet50, contradicting some earlier studies that suggested Transformers were more resilient to spatial perturbations.

Conclusion

The paper concludes that while global reasoning is the Transformer's greatest strength, it is also its "Achilles' heel" for security. Future research will need to focus on "attention-aware" defenses, perhaps by limiting how much influence a single key token can exert over the entire query set. While the authors focused on scaled dot-product attention, other mixing mechanisms—such as those used in FNet or MLP-Mixer—might offer alternative paths toward robustness.

Summary updated

BibTeX
@misc{lovisotto2022give,
  author = {Giulio Lovisotto and Nicole Finnie and Mauricio Munoz and Chaithanya Kumar Mummadi and Jan Hendrik Metzen},
  title = {{Give Me Your Attention: Dot-Product Attention Considered Harmful for Adversarial Patch Robustness}},
  year = {2022},
  eprint = {2203.13639},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2203.13639},
}
Figure