Abstract
There has been a debate about the superiority between vision Transformers and ConvNets, serving as the backbone of computer vision models. Although they are usually considered as two completely different architectures, in this paper, we interpret vision Transformers as ConvNets with dynamic convolutions, which enables us to characterize existing Transformers and dynamic ConvNets in a unified framework and compare their design choices side by side. In addition, our interpretation can also guide the network design as researchers now can consider vision Transformers from the design space of ConvNets and vice versa. We demonstrate such potential through two specific studies. First, we inspect the role of softmax in vision Transformers as the activation function and find it can be replaced by commonly used ConvNets modules, such as ReLU and Layer Normalization, which results in a faster convergence rate and better performance. Second, following the design of depth-wise convolution, we create a corresponding depth-wise vision Transformer that is more efficient with comparable performance. The potential of the proposed unified interpretation is not limited to the given examples and we hope it can inspire the community and give rise to more advanced network architectures.
Introduction
For years, the computer vision community has debated whether Vision Transformers (ViTs) are fundamentally superior to Convolutional Neural Networks (ConvNets). While ConvNets rely on static filters that slide across an image, ViTs use self-attention to weight features dynamically based on their content. Because these architectures were developed using different terminologies, comparing them "apples-to-apples" has been difficult. This paper addresses this fragmentation by providing a unified mathematical framework that interprets ViTs as a special case of dynamic ConvNets.
A Unified Framework: Self-Attention as Dynamic Convolution
The authors re-interpret the core building block of Transformers—self-attention—through the lens of convolution. They demonstrate that the query-key multiplication and the attention-value multiplication in a Transformer are essentially two $1 \times 1$ dynamic convolutions.
In this view, the "Keys" and "Values" in a Transformer act as a "kernel bank"—a set of filters that are dynamically selected and applied to the "Query" (the input). This perspective allows researchers to characterize various models (ViT, Swin Transformer, Linformer, and traditional Dynamic ConvNets) across shared dimensions like Kernel Bank, Kernel Selection, and Kernel Size.
Empirical Studies: Softmax and Depth-wise ViTs
Using this framework, the researchers conducted two key studies:
- Softmax Ablation: They identified that softmax performs three roles: normalization, channel-wise communication, and non-linearity. By treating it as an activation function, they tested replacing it with ConvNet staples like ReLU and LayerNorm.
- Depth-wise ViT: Following the design of depth-wise convolution, they simplified the two-step dynamic convolution of a Transformer into a single depth-wise dynamic convolution to create a more efficient "Depth-wise Vision Transformer."
Key Results
The unified interpretation yielded significant performance and efficiency gains. Replacing softmax with LayerNorm + ReLU improved the top-1 accuracy of a Swin-Tiny model from 81.13% to 81.56% without adding computational overhead.
As illustrated in the training curves, models using ReLU variants reached higher accuracy levels much earlier in the training process compared to standard softmax-based ViTs. Additionally, the proposed Depth-wise ViT achieved comparable performance to standard models while saving approximately 10% in FLOPs, 8% in learnable parameters, and reducing activation counts by 20-40%.
Conclusion
This research suggests that the gap between Transformers and ConvNets is narrower than previously thought. By viewing ViTs through the lens of dynamic convolutions, researchers can leverage established ConvNet design principles to optimize Transformer architectures. Future work may explore generating larger dynamic kernels (e.g., $3 \times 3$) to bake spatial awareness directly into the dynamic convolution, potentially reducing the reliance on positional embeddings.
Summary updated