QUEST: A robust attention formulation using query-modulated spherical attention
Organizations: Linköping University, Sweden · Qualcomm Auto Ltd Sweden Filial
Abstract
The Transformer model architecture has become one of the most widely used in deep learning and the attention mechanism is at its core. The standard attention formulation uses a softmax operation applied to a scaled dot product between query and key vectors. We explore the role played by norms of the queries and keys, which can cause training instabilities when they arbitrarily increase. We demonstrate how this can happen even in simple Transformer models, in the presence of easy-to-learn spurious patterns in the data. We propose a new attention formulation, QUEry-modulated Spherical aTtention (QUEST), that constrains the keys to a hyperspherical latent space, while still allowing individual tokens to flexibly control the sharpness of the attention distribution. QUEST can be easily used as a drop-in replacement for standard attention. We focus on vision applications while also exploring other domains to highlight the method's generality. We show that (1) QUEST trains without instabilities and (2) produces models with improved performance (3) that are robust to data corruptions and adversarial attacks.
Figures & tables
| Attention | Scaling | IN-val | IN-v2 | IN-ReaL | IN-C | IN-A | |
| Top-1 | Top-1 | Top-1 | MCE | Top-1 | Top-5 | ||
| Standard | |||||||
| QUEST | - | ||||||
| QNorm | - | ||||||
| QKNorm-HS | † | ||||||
| QKNorm-DS | ‡ | ||||||
| Model | Attention | Epochs | IN-val | IN-v2 | IN-ReaL | IN-C | IN-A | |
| Top-1 | Top-1 | Top-1 | MCE | Top-1 | Top-5 | |||
| DeiT-1 Touvron et al. (2021a) trainings | ||||||||
| ViT-S/16 | Standard | |||||||
| ViT-S/16 | QUEST | |||||||
| ViT-B/16 | Standard | –training crashed– | ||||||
| ViT-B/16 | QKNorm-DS ‡ | |||||||
| Attention | Clean Data | FGSM | PGD | ||||||
| Top-1 | Top-5 | NLL | Top-1 | Top-5 | NLL | Top-1 | Top-5 | NLL | |
| Standard | |||||||||
| QUEST | |||||||||
| Elliptical | 71.53 | 90.70 | 1.254 | 55.96 | 85.53 | 1.746 | 46.30 | 80.05 | 2.231 |
| Elliptical-QUEST | |||||||||
| Attention | SPSA | Auto | ||||
| Top-1 | Top-5 | NLL | Top-1 | Top-5 | NLL | |
| Standard | ||||||
| QUEST | ||||||
| Elliptical | 57.96 | 86.92 | 1.654 | 27.35 | 67.28 | 3.014 |
| Elliptical-QUEST | ||||||
| Model | Attention | Clean data | Corrupted data |
| mIoU | mIoU | ||
| ViT-Ti/16 | Standard | ||
| ViT-Ti/16 | QUEST | ||
| ViT-S/16 | Standard | ||
| ViT-S/16 | QUEST |
| Backbone | Attention | Method | Epochs | Pixel accuracy (%) | mIoU | DICE Score |
| ViT-B/16 | Standard | DeiT-3 | ||||
| ViT-B/16 | QUEST | DeiT-3 |
| Attention | ZINC | CIFAR10 | PATTERN | CLUSTER |
| MAE | Accuracy | Accuracy | Accuracy | |
| Standard | ||||
| QUEST |
| Attention | PascalVOC-SP | COCO-SP | Peptides-func | Peptides-struct | PCQM-Contact |
| F1 score | F1 score | AP | MAE | MRR | |
| Standard | |||||
| QUEST |
| Method | Model size (Parameters) | Attention | Clean Data PPL | Contaminated Data PPL (Corruption %) | |||
| Val | Test | Test (1.5%) | Test (2.5%) | Test (5.0%) | |||
| Transformer | Small (44M) | Standard | |||||
| Transformer | Small (44M) | QUEST | |||||
| Transformer | Medium (90M) | Standard | |||||
| Transformer | Medium (90M) | QNorm | |||||
| Transformer | Medium (90M) | QKNorm-DS | |||||
Appendix figures & tables22 assets
Supplementary material from the paper’s appendix.
Appendix
| Attention | Scaling | ImageNet-val | ||
| Top-1 (%) | Top-5 (%) | NLL | ||
| Standard | ||||
| QUEST | - | |||
| QNorm | - | |||
| QKNorm-HS | † | |||
| QKNorm-DS | ‡ | |||
| Data (%) | Attention | ImageNet-val | ||
| Top-1 | Top-5 | NLL | ||
| 5% | Standard | |||
| QUEST | ||||
| 10% | Standard | |||
| QUEST | ||||
| 25% | Standard | |||
| Learning rate | Epochs | Standard attention | QUEST attention | ||
| Top-1 | Top-5 | Top-1 | Top-5 | ||
| 66.9 | 87.9 | 68.5 | 88.7 | ||
| –training crashed– | |||||
| –training crashed– | |||||
| Model | Attention | Epochs | ImageNet-val | ||
| Top-1 | Top-5 | NLL | |||
| CrossViT-9-Dagger | Standard | ||||
| CrossViT-9-Dagger | QUEST | ||||
| CrossViT-Small | Standard | ||||
| CrossViT-Small | QUEST | ||||
| CrossViT-18-Dagger | Standard | –training crashed– | |||
| Model | Attention | Epochs | FGSM | PGD | Auto | |||
| Top-1 | NLL | Top-1 | NLL | Top-1 | NLL | |||
| ViT-S/16 | Standard | |||||||
| ViT-S/16 | QUEST | |||||||
| ViT-B/16 † | Standard | |||||||
| ViT-B/16 † | QUEST | |||||||
| ViT-L/16 | QKNorm-LN | |||||||
| Model | Parameters | Attention | Epochs | IN-val | ||
| Top-1 | Top-5 | NLL | ||||
| ViT-H/14 | 600M | Standard | ||||
| ViT-H/14 | 600M | QUEST | ||||
| ViT-H/14 | 600M | Standard | ||||
| ViT-H/14 | 600M | QUEST | ||||
| ViT-2B/16 | 2.4B | Standard | ||||
| Dataset | Standard | Standard + [CLS] |
| EthanolConcentration | 28.14 | 29.28 |
| FaceDetection | 67.99 | 65.24 |
| Handwriting | 38.24 | 42.00 |
| Heartbeat | 77.07 | 77.56 |
| JapaneseVowels | 97.84 | 98.38 |
| PEMS-SF | 84.97 | 83.82 |
| Dataset | Standard | QNorm | QKNorm | QUEST |
| EthanolConcentration | 29.28 | 29.28 | 29.28 | 30.42 |
| FaceDetection | 65.24 | 64.81 | 64.73 | 65.83 |
| Handwriting | 42.00 | 41.06 | 49.18 | 49.18 |
| Heartbeat | 77.56 | 75.61 | 77.56 | 78.54 |
| JapaneseVowels | 98.38 | 98.92 | 98.38 | 98.38 |
| PEMS-SF | 83.82 | 80.92 | 79.19 | 80.92 |
| Model | Parameters | Attention | nuScenes val. mIoU (%) |
| PointTransformer-V3 | 46.2 M | Standard | 80.40 |
| PointTransformer-V3 | 46.2 M | QKNorm-DS | 80.37 |
| PointTransformer-V3 | 46.2 M | QUEST | 80.83 |
| Hyperparameter | ZINC | CIFAR10 | PATTERN | CLUSTER |
| # GPS Layers | 10 | 3 | 6 | 16 |
| Hidden dim | 64 | 52 | 64 | 48 |
| GPS-MPNN | GINE | GatedGCN | GatedGCN | GatedGCN |
| GPS-GlobAttn | Transformer | Transformer | Transformer | Transformer |
| # Heads | 4 | 4 | 4 | 8 |
| Dropout | 0 | 0 | 0 | 0.1 |
| Hyperparameter | PascalVOC-SP | COCO-SP | PCQM-Contact | Peptides-func | Peptides-struct |
| # GPS Layers | 4 | 4 | 4 | 4 | 4 |
| Hidden dim | 96 | 96 | 96 | 96 | 96 |
| GPS-MPNN | GatedGCN | GatedGCN | GatedGCN | GatedGCN | GatedGCN |
| GPS-SelfAttn | Transformer | Transformer | Transformer | Transformer | Transformer |
| # Heads | 8 | 8 | 4 | 4 | 4 |
| Dropout | 0 | 0 | 0 | 0 | 0 |
| Attention | kNN | Linear | Finetuning | Few-shot | |||
| 1 img/cls | 2 imgs/cls | 5 imgs/cls | 1% imgs | ||||
| Standard | |||||||
| QUEST | |||||||
| Attention | Transfer linear probe | Image Retrieval | VOS | |||||
| Average | RParis | ROxford | DAVIS-2017 | |||||
| M | H | M | H | |||||
| Standard | ||||||||
| QUEST | ||||||||
| Attention | Acft. | Cal101 | DTD | Flwrs. | Food | Pets | SUN | Avg. |
| Standard | ||||||||
| QUEST |