Introduction
Vision Transformers (ViTs) have revolutionized computer vision by applying the Transformer architecture to image patches. However, unlike Convolutional Neural Networks (CNNs), ViTs lack inherent inductive biases—such as local context—that make CNNs highly efficient for visual tasks. This paper identifies a surprising culprit for this deficiency: Layer Normalization (LN).
In standard ViTs, LN normalizes embeddings within each individual token. This process inadvertently strips away important spatial information by making all image patches "equal" in magnitude. For instance, a high-contrast "tree" patch and a low-contrast "sky" patch are forced to have the same mean and variance, reducing the semantic contrast necessary for distinguishing local features.
Dynamic Token Normalization (DTN)
To restore these vital spatial cues, the authors introduce Dynamic Token Normalization (DTN). DTN is a drop-in replacement for LN that learns to normalize both within and across tokens, allowing the model to capture local context and spatial inductive biases without sacrificing global reasoning.
Key Components of DTN
- Hybrid Statistics: DTN calculates normalization constants by balancing intra-token (LN-style) and inter-token (IN-style) statistics using a learnable weight ratio ($\lambda$).
- Position-Aware Aggregation: Unlike standard Instance Normalization, which treats all tokens equally, DTN employs a learnable, position-aware weight matrix. This ensures that a token is normalized primarily using statistics from its neighbors or semantically similar patches, avoiding the "noisy statistics" problem where unrelated domains (e.g., snow and trees) are mixed.
- Head-Specific Normalization: In Multi-Head Self-Attention (MHSA), DTN allows each head to learn its own normalization strategy. This enables some heads to specialize in local positional context while others maintain a global view.
Key Insights
The "Magnitude" Insight
The authors observe that LN's tendency to uniformize token magnitudes is often detrimental. By allowing tokens to maintain different magnitudes, DTN preserves the "saliency" of different image regions. As shown in the visualizations, DTN preserves the contrast between tokens that LN typically flattens.
Dynamic Specialization
By analyzing attention patterns, the researchers found that models equipped with DTN naturally develop heads with shorter attention spans. This indicates that the model successfully learns to "look locally," mimicking the beneficial behavior of CNNs without manual architectural constraints.
Experimental Results
DTN consistently outperforms the baseline LN across multiple architectures (ViT, Swin, PVT) with minimal computational overhead:
- ImageNet-1K Classification: DTN improved ViT-S top-1 accuracy by 1.1% and Swin-T by 0.7%.
- Object Detection (COCO): Using a PVT-Tiny backbone, DTN increased the box AP by 1.3 points over the LN baseline.
- Robustness: DTN showed significant gains on ImageNet-C and ImageNet-R, reducing the Mean Corruption Error (mCE) by up to 3.9%.
- Efficiency: For a ViT-S model, these gains were achieved with only a 5.4% increase in FLOPs and negligible extra parameters.
Conclusion
Dynamic Token Normalization offers a simple yet effective way to inject spatial inductive bias into Vision Transformers. By moving beyond the limitations of standard Layer Normalization, DTN enables models to better distinguish local features while maintaining the global reasoning capabilities that make Transformers powerful. Future work may explore combining DTN with sparse attention mechanisms to further enhance efficiency and local awareness.
Summary updated