Enhancing Transformers Through Conditioned Embedded Tokens
Hemanth Saratchandran, Simon Lucey
TL;DR
The paper tackles ill-conditioning in transformer self-attention by linking the conditioning of the first-layer attention to the condition number of embedded tokens and introduces conditioned embedded tokens via a correction term derived from the SVD of the embedding. It provides a theoretical framework with bounds showing that a suitable correction C can reduce $\kappa(X)$ and thereby improve attention conditioning, and demonstrates that $\kappa(X+C) \leq 2$. Empirically, conditioned embedded tokens yield consistent performance improvements across vision (ViT, DeiT, Swin, XCiT, DaViT), object detection (Mask R-CNN with XCiT backbones), and language models (Crammed BERT, GPT-2), including long-range sequence models (Nyströmformer). While offering a practical drop-in enhancement, the work acknowledges limitations in proving optimization guarantees via NTK and notes that the method targets embedded tokens rather than the queries/keys/values directly. The approach holds broad potential for stabilizing and accelerating training in diverse transformer-based systems, with applicability to both standard and efficient attention variants.
Abstract
Transformers have transformed modern machine learning, driving breakthroughs in computer vision, natural language processing, and robotics. At the core of their success lies the attention mechanism, which enables the modeling of global dependencies among input tokens. However, we reveal that the attention block in transformers suffers from inherent ill-conditioning, which hampers gradient-based optimization and leads to inefficient training. To address this, we develop a theoretical framework that establishes a direct relationship between the conditioning of the attention block and that of the embedded tokenized data. Building on this insight, we introduce conditioned embedded tokens, a method that systematically modifies the embedded tokens to improve the conditioning of the attention mechanism. Our analysis demonstrates that this approach significantly mitigates ill-conditioning, leading to more stable and efficient training. We validate our methodology across various transformer architectures, achieving consistent improvements in image classification, object detection, instance segmentation, and natural language processing, highlighting its broad applicability and effectiveness.
