Masked Autoencoders Enable Efficient Knowledge Distillers

Yutong Bai, Zeyu Wang, Junfei Xiao, Chen Wei, Huiyu Wang, Alan L. Yuille, Yuyin Zhou, Cihang Xie · DOI

Abstract

This paper studies the potential of distilling knowledge from pre-trained models, especially Masked Autoencoders. Our approach is simple: in addition to optimizing the pixel reconstruction loss on masked inputs, we minimize the distance between the intermediate feature map of the teacher model and that of the student model. This design leads to a computationally efficient knowledge distillation framework, given 1) only a small visible subset of patches is used, and 2) the (cumbersome) teacher model only needs to be partially executed, i.e., forward propagate inputs through the first few layers, for obtaining intermediate feature maps. Compared to directly distilling fine-tuned models, distilling pre-trained models substantially improves downstream performance. For example, by distilling the knowledge from an MAE pre-trained ViT-L into a ViT-B, our method achieves 84.0% ImageNet top-1 accuracy, outperforming the baseline of directly distilling a finetuned ViT-L by 1.2%. More intriguingly, our method can robustly distill knowledge from teacher models even with extremely high masking ratios: e.g., with 95% masking ratio where merely TEN patches are visible during distillation, our ViT-B competitively attains a top-1 ImageNet accuracy of 83.6%; surprisingly, it can still secure 82.4% top-1 ImageNet accuracy by aggressively training with just FOUR visible patches (98% masking ratio).

Introduction

Vision Transformers (ViTs) have set new benchmarks in computer vision, yet their computational demands often preclude deployment on edge devices or real-time applications. Knowledge Distillation (KD) offers a path forward by training a compact "student" model to replicate the behavior of a larger "teacher." However, traditional KD faces two significant hurdles: a reliance on labeled data for logit-based alignment and the high computational overhead of running large teacher models during training.

This work introduces DMAE (Distilling Masked Autoencoders), a framework that shifts distillation from the task-specific fine-tuning phase to the self-supervised pre-training phase. By focusing on fundamental feature representations rather than final predictions, DMAE achieves superior performance with significantly reduced computational costs.

The DMAE Framework

DMAE extends the standard Masked Autoencoder (MAE) paradigm. In MAE, the model learns by reconstructing missing pixels from a sparse subset of image patches. DMAE augments this with a feature alignment objective.

The DMAE framework aligns intermediate features between a student and a partially executed teacher.

Key components of the architecture include:

  • Feature Alignment: The student minimizes the distance (using L1 norm) between its intermediate feature maps and those of a pre-trained teacher.
  • Partial Teacher Execution: Efficiency is maximized by only executing the teacher model up to the layer required for feature extraction, discarding the remaining high-level layers.
  • Projection Head: A 2-layer MLP aligns the student's feature dimensions with the teacher's space.

Experimental Results

Evaluated on ImageNet-1k, DMAE demonstrates remarkable efficiency and accuracy. A ViT-B student distilled from a ViT-L teacher reaches 84.0% top-1 accuracy, surpassing a standard MAE-trained ViT-B (83.6%) while requiring significantly fewer training epochs (100 vs. 1600).

Efficiency and Low-Data Performance

DMAE is not only faster to train—achieving its peak performance in 195 GPU hours compared to 208 hours for traditional distillation—but also excels in low-data regimes. In a 1% ImageNet challenge, DMAE achieved 50.3% accuracy, a substantial improvement over the 33.9% baseline.

The Power of Sparsity

A standout finding is the model's robustness to extreme masking. Because the teacher provides a dense semantic signal, the student can learn effectively even when 95% to 98% of the image is obscured.

Performance impact of masking ratios on ImageNet Top-1 accuracy.

As shown in the figure above, the student maintains a competitive 82.4% accuracy even when only four patches (98% masking) are visible. This suggests that the teacher's intermediate features contain highly compressed, yet sufficient, information to guide the reconstruction process.

Key Insights

  • Representation over Logits: Distilling during self-supervised pre-training captures a more general understanding of visual structures than task-specific logit distillation.
  • Optimal Layer Alignment: Performance peaks when aligning features at approximately 3/4 depth (e.g., the 9th layer of a 12-layer ViT-B). This avoids the "noise" of early layers and the over-specialization of the final layers.
  • Loss Function: The L1 norm proved more robust than L2 for feature alignment, likely due to its reduced sensitivity to feature map outliers.

Conclusion

DMAE demonstrates that self-supervised pre-training is an ideal stage for knowledge distillation. By leveraging sparse inputs and partial teacher execution, it provides a highly efficient path to training high-performance compact models. While currently optimized for Transformers, future work may extend these principles to convolutional architectures and multi-teacher setups.

Summary updated

BibTeX
@misc{bai2022masked,
  author = {Yutong Bai and Zeyu Wang and Junfei Xiao and Chen Wei and Huiyu Wang and Alan L. Yuille and Yuyin Zhou and Cihang Xie},
  title = {{Masked Autoencoders Enable Efficient Knowledge Distillers}},
  year = {2022},
  eprint = {2208.12256},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2208.12256},
}
Figure