Abstract
Vision Transformers (ViTs) have demonstrated significant potential in visual recognition, yet their architectural design remains largely manual and sub-optimal. We present AutoFormer, the first one-shot architecture search framework specifically tailored for pure vision transformers. By introducing a novel "weight entanglement" strategy, AutoFormer enables a single supernet to train thousands of high-performing subnets concurrently. This approach allows discovered architectures to be deployed directly without retraining, consistently outperforming state-of-the-art models such as DeiT and ViT across various resource constraints.
Introduction
The rise of Vision Transformers (ViTs) has shifted the landscape of computer vision. However, unlike Convolutional Neural Networks (CNNs), which benefit from decades of architectural intuition, ViTs involve a complex configuration of hyperparameters, including network depth, embedding dimensions, attention heads, and MLP ratios. Manual design is labor-intensive and often fails to find the optimal balance between performance and efficiency.
While Neural Architecture Search (NAS) has successfully automated CNN design, applying it to transformers has proven challenging. Traditional weight-sharing NAS methods often suffer from slow convergence and poor performance in the transformer search space, typically requiring the discovered models to be retrained from scratch.
Methodology: Weight Entanglement
AutoFormer addresses these challenges through two primary innovations: a massive, elastic search space and a "weight entanglement" training strategy.
Search Space
The defined search space encompasses approximately $1.7 \times 10^{16}$ candidate architectures. In this space, every layer can independently vary its embedding dimension, number of heads, and MLP ratio. Furthermore, the network depth is elastic, allowing the search to determine the optimal number of layers.
Weight Entanglement Strategy
The core of AutoFormer is weight entanglement. In standard one-shot NAS, different candidate blocks within a layer often maintain independent weights. AutoFormer instead mandates that different blocks share weights for their common components. For instance, an MLP with a hidden dimension of 192 will "extract" its weights from the first 192 channels of a larger 384-dimension MLP.
This strategy ensures that weights for the largest blocks are updated more frequently, leading to faster convergence. It also acts as a regularizer, reducing co-adaptation between units—similar to the effect of Dropout—by forcing units to perform well even when neighboring units are not sampled.
Experimental Results
AutoFormer was primarily evaluated on ImageNet-1K, with additional tests on downstream classification tasks like CIFAR and fine-grained datasets (e.g., Stanford Cars, Flowers-102).
ImageNet Performance
The searched models, categorized as AutoFormer-tiny, -small, and -base, consistently outperformed manually designed counterparts.
- AutoFormer-tiny: 74.7% top-1 accuracy with 5.7M parameters.
- AutoFormer-small: 81.7% top-1 accuracy (22.9M params), surpassing DeiT-S by 1.8%.
- AutoFormer-base: 82.4% top-1 accuracy (53.7M params).
Transferability
A key advantage of AutoFormer is that subnets inherited from the supernet perform nearly as well as those retrained from scratch, eliminating the costly search-then-retrain cycle. On transfer learning tasks, AutoFormer-S matches or exceeds the performance of much larger models like ViT-B while using significantly fewer parameters.
Conclusion and Future Work
AutoFormer demonstrates that weight entanglement is a natural and effective strategy for searching transformer architectures due to their homogeneous block structure. While it sets new benchmarks for ViTs, a performance gap remains relative to highly optimized "mobile-first" CNNs on edge devices. Future research may explore hybrid search spaces combining convolutional operators with transformer blocks to leverage both local efficiency and global modeling.
Summary updated