As-ViT: Auto-scaling Vision Transformers without Training [PDF]
Wuyang Chen, Wei Huang, Xianzhi Du, Xiaodan Song, Zhangyang Wang, Denny Zhou
In ICLR 2022.
Note: We implemented topology search (sec. 3.3) and scaling (sec. 3.4) in this code base in PyTorch. Our training code is based on Tensorflow and Keras on TPU, which will be released soon.
We present As-ViT, a framework that unifies the automatic architecture design and scaling for ViT (vision transformer), in a training-free strategy.
Highlights:
- Trainig-free ViT Architecture Design: we design a "seed" ViT topology by leveraging a training-free search process. This extremely fast search is fulfilled by our comprehensive study of ViT's network complexity (length distorsion), yielding a strong Kendall-tau correlation with ground-truth accuracies.
- Trainig-free ViT Architecture Scaling: starting from the "seed" topology, we automate the scaling rule for ViTs by growing widths/depths to different ViT layers. This will generate a series of architectures with different numbers of parameters in a single run.
- Efficient ViT Training via Progressive Tokenization: we observe that ViTs can tolerate coarse tokenization in early training stages, and further propose to train ViTs faster and cheaper with a progressive tokenization strategy.
Left: Length Distortion shows a strong correlation with ViT's accuracy. Middle: Auto scaling rule of As-ViT. Right: Progressive re-tokenization for efficient ViT training.
- Ubuntu 18.04
- Python 3.6.9
- CUDA 11.0 (lower versions may work but were not tested)
- NVIDIA GPU + CuDNN v7.6
This repository has been tested on V100 GPU. Configurations may need to be changed on different platforms.
- Clone this repo:
git clone https://github.com/VITA-Grou/AsViT.git
cd AsViT
- Install dependencies:
pip install -r requirements.txt
CUDA_VISIBLE_DEVICES=0 python ./search/reinforce.py --save_dir ./output/REINFORCE-imagenet --data_path /path/to/imagenet
This job will return you a seed topology. For example, our search seed topology is 8,2,3|4,1,2|4,1,4|4,1,6|32
, which can be explained as below:
Stage1 | Stage2 | Stage3 | Stage4 | Head | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Kernel K1 | Split S1 | Expansion E1 | Kernel K2 | Split S2 | Expansion E2 | Kernel K3 | Split S3 | Expansion E3 | Kernel K4 | Split S4 | Expansion E4 | |
8 | 2 | 3 | 4 | 1 | 2 | 4 | 1 | 4 | 4 | 1 | 6 | 32 |
CUDA_VISIBLE_DEVICES=0 python ./search/grow.py --save_dir ./output/GROW-imagenet \
--arch "[arch]" --data_path /path/to/imagenet
Here [arch]
is the seed topology (output from step 1 above).
This job will return you a series of topologies. For example, our largest topology (As-ViT Large) is 8,2,3,5|4,1,2,2|4,1,4,5|4,1,6,2|32,180
, which can be explained as below:
Stage1 | Stage2 | Stage3 | Stage4 | Head | Initial Hidden Size | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Kernel K1 | Split S1 | Expansion E1 | Layers L1 | Kernel K2 | Split S2 | Expansion E2 | Layers L2 | Kernel K3 | Split S3 | Expansion E3 | Layers L3 | Kernel K4 | Split S4 | Expansion E4 | Layers L4 | ||
8 | 2 | 3 | 5 | 4 | 1 | 2 | 2 | 4 | 1 | 4 | 5 | 4 | 1 | 6 | 2 | 32 | 180 |
Tensorflow and Keras code for training on TPU. To be released soon.
@inproceedings{chen2021asvit,
title={Auto-scaling Vision Transformers without Training},
author={Chen, Wuyang and Huang, Wei and Du, Xianzhi and Song, Xiaodan and Wang, Zhangyang and Zhou, Denny},
booktitle={International Conference on Learning Representations},
year={2022}
}