TinyViT: Fast Pretraining Distillation for Small Vision Transformers

Kan Wu, Jinnian Zhang, Houwen Peng, Mengchen Liu, Bin Xiao, Jianlong Fu, Lu Yuan

Abstract

Vision Transformers (ViTs) have demonstrated exceptional performance on large-scale datasets, yet their efficiency remains a challenge for resource-constrained devices. Small ViTs often suffer from performance saturation when trained on massive datasets like ImageNet-21k. TinyViT addresses this by introducing a novel "fast distillation" framework that enables small models to benefit from large-scale pretraining without the prohibitive computational cost of standard knowledge distillation. By storing sparsified teacher knowledge and replicating data augmentations via random seeds, TinyViT achieves state-of-the-art performance, with the 21M parameter variant reaching 84.8% Top-1 accuracy on ImageNet-1k.

The Challenge of Scaling Small ViTs

While massive ViTs scale effectively with data, smaller models often hit a performance ceiling. Standard Knowledge Distillation (KD)—where a large "teacher" model guides a small "student"—is a potential solution, but it is computationally expensive for large-scale pretraining. Running a giant teacher model (e.g., Swin-L) alongside a student for millions of images requires immense GPU memory and significantly slows down training cycles. TinyViT aims to bridge this gap by making large-scale distillation both efficient and effective for tiny architectures.

Methods

Fast Pretraining Distillation

To eliminate the overhead of running a teacher model during every training step, the authors move the teacher's workload offline. This is achieved through two key mechanisms:

  1. Sparsified Logits: Instead of saving the full probability distribution (which can exceed 21,000 classes for ImageNet-21k), the framework only stores the top-$K$ (e.g., $K=100$) predictions and their indices. This reduces storage requirements by orders of magnitude.
  2. Data Augmentation Encoding: To ensure the student sees the exact same augmented image as the teacher, the system stores a 4-byte random seed used to generate the augmentation (crops, flips, etc.) rather than the images themselves. During training, the student uses that seed to perfectly replicate the teacher's input.
The Fast Pretraining Distillation framework decouples teacher and student training by storing sparse logits and augmentation seeds.

TinyViT Architecture

The TinyViT family is built using a hierarchical structure optimized via Progressive Model Contraction. The architecture features a hybrid design: the initial stages use MBConvs (Mobile Inverted Bottleneck Convolutions) to capture low-level features with strong inductive bias, while later stages utilize transformer blocks with window attention to manage computational complexity. The final dimensions are determined by systematically shrinking a large "seed" model to find the optimal accuracy-to-speed trade-off.

Key Results and Insights

TinyViT demonstrates significant performance gains over traditional small-scale models. The distillation process acts as a "filter," providing soft labels that help small models navigate the noisy labels and multi-object images common in large datasets like ImageNet-21k.

  • State-of-the-Art Efficiency: TinyViT-21M achieves 84.8% top-1 accuracy on ImageNet-1k, matching the performance of a Swin-B model while using 4.2x fewer parameters.
  • Superior Scaling: When scaled to 512x512 resolution, TinyViT-21M reaches 86.5% accuracy, slightly outperforming the massive Swin-L while using only 11% of the parameters.
  • Downstream Versatility: On the COCO object detection benchmark, TinyViT-21M achieved 50.2 AP, outperforming the larger Swin-T by 2.1 points.
Comparison of TinyViT variants against DeiT and Swin baselines, highlighting the significant accuracy boost provided by pretraining and distillation.

Conclusion

TinyViT proves that with efficient distillation techniques, small vision transformers can successfully leverage massive datasets. While the initial generation of teacher logits requires a significant one-time computational investment and substantial disk space (approx. 481 GB for ImageNet-21k), the resulting student models offer unprecedented performance-per-parameter for mobile and edge applications. Future work may explore even larger datasets and multi-modal teacher models to further push the boundaries of tiny vision architectures.

Summary updated

BibTeX
@inproceedings{wu2022tinyvit,
  author = {Kan Wu and Jinnian Zhang and Houwen Peng and Mengchen Liu and Bin Xiao and Jianlong Fu and Lu Yuan},
  title = {{TinyViT: Fast Pretraining Distillation for Small Vision Transformers}},
  booktitle = {European Conference on Computer Vision},
  year = {2022},
  doi = {10.1007/978-3-031-19803-8\_5},
}
Figure