SpecFormer: Guarding Vision Transformer Robustness via Maximum Singular Value Penalization

Xixu Hu, Runkai Zheng, Jindong Wang, Cheuk Hang Leung, Qi Wu, Xing Xie

Abstract

Vision Transformers (ViTs) have achieved state-of-the-art performance in computer vision but remain susceptible to adversarial perturbations. This paper introduces SpecFormer, a theoretically grounded approach to enhance ViT robustness by penalizing the maximum singular values of attention weights. By controlling the local Lipschitz constant of the model, SpecFormer significantly reduces sensitivity to adversarial attacks while simultaneously improving standard classification accuracy. Our method utilizes Power Iteration for efficient computation, making it a practical solution for large-scale training.

Introduction

Despite their success, Vision Transformers share a critical vulnerability with Convolutional Neural Networks: adversarial susceptibility. Small, imperceptible perturbations can lead to confident misclassifications. While empirical defenses like data augmentation exist, they often lack theoretical guarantees. A robust model should ideally be Lipschitz continuous, meaning small input changes result in bounded output changes. However, bounding the Lipschitz constant for the complex, non-linear self-attention mechanism is mathematically challenging. Existing defenses often impose heavy constraints that degrade clean accuracy or fail to provide tight bounds.

Methodology

SpecFormer addresses these challenges through Maximum Singular Value Penalization (MSVP). The approach is built on three pillars:

  1. Theoretical Local Lipschitz Bounding: We derive a new local Lipschitz bound for the self-attention layer, proving that its stability is directly linked to the maximum singular values ($\sigma_{max}$) of the weight matrices $W^Q, W^K,$ and $W^V$.
  2. Regularization Term: A penalty term proportional to the square of these maximum singular values is added to the training loss function across all layers and heads.
  3. Computational Efficiency: To avoid the high cost of exact Singular Value Decomposition (SVD), we employ the Power Iteration algorithm. This provides a fast, reliable approximation of $\sigma_{max}$, resulting in only a 1.5x to 2.5x training overhead compared to vanilla models.
Comparison of SpecFormer with existing robust Transformer architectures.

As shown in the table above, SpecFormer is unique in achieving Lipschitz continuity and robustness without relying on simplified attention mechanisms that often sacrifice performance.

Experimental Results

SpecFormer was evaluated across diverse benchmarks, including CIFAR-10/100 and ImageNet-1k, using architectures such as Vanilla ViT, DeiT, and Swin.

Robustness and Accuracy Gains

Unlike many defenses that suffer from a "robustness-accuracy trade-off," SpecFormer improves both metrics:

  • Adversarial Robustness: Under standard training, robust accuracy against FGSM and PGD attacks improved by an average of 8.96% and 3.49%, respectively. In adversarial training settings, SpecFormer outperformed competitors like LipsFormer by over 1.2% on PGD and CW attacks.
  • Clean Accuracy: Standard classification accuracy increased by 2.20% to 3.06% across various settings, suggesting that MSVP acts as an effective general regularizer.

Discussion

A key insight of this work is the focus on local rather than global Lipschitz continuity. Global bounds are often too restrictive, harming the model's ability to learn complex features. By focusing on the neighborhood of actual data points, SpecFormer maintains high representational capacity while ensuring stability. Furthermore, by interpreting self-attention as a series of linear mappings, we can apply rigorous linear algebraic principles to improve Transformer safety.

Conclusion and Future Work

SpecFormer provides a practical and theoretically sound framework for securing Vision Transformers. It demonstrates that robustness does not have to come at the cost of accuracy or extreme computational expense. Future research will explore the application of MSVP to large-scale foundation models and its effectiveness against natural corruptions and patch-based adversarial attacks.

Summary updated

BibTeX
@inproceedings{hu2024specformer,
  author = {Xixu Hu and Runkai Zheng and Jindong Wang and Cheuk Hang Leung and Qi Wu and Xing Xie},
  title = {{SpecFormer: Guarding Vision Transformer Robustness via Maximum Singular Value Penalization}},
  booktitle = {European Conference on Computer Vision},
  year = {2024},
  doi = {10.1007/978-3-031-72949-2\_20},
}
Figure