SpectralKD: A Unified Framework for Interpreting and Distilling Vision Transformers via Spectral Analysis

Huiyuan Tian, Bonan Xu, Shijian Li, Gang Pan

TL;DR

SpectralKD is a new framework that uses Fourier analysis to "see" how information flows through Vision Transformers (ViTs). By discovering that information is concentrated in the first and last layers, the authors developed a simple, parameter-free distillation method that aligns these frequency patterns, boosting DeiT-Tiny's accuracy by a massive 5.2% on ImageNet-1K.

What Problem Does This Paper Address?

Vision Transformers (ViTs) are powerful but computationally expensive. While Knowledge Distillation (KD)—where a small "student" model learns from a large "teacher"—is a standard way to compress these models, it remains something of a black box for ViTs.

Specifically, researchers struggle with two questions:

  1. Layer Selection: In uniform architectures like DeiT, where every block looks identical, which layers are actually the most important to align?
  2. Feature Alignment: How do we effectively transfer internal representations when the student and teacher have different channel dimensions?

Existing methods often rely on trial-and-error or introduce complex, trainable "projector" layers that add overhead and obscure what the model is actually learning.

Methods

The authors introduce SpectralKD, which treats the feature maps of a ViT as signals to be analyzed in the frequency domain.

  • Spectral Analysis: They apply a 1D Fast Fourier Transform (FFT) along the channel dimension to calculate "Average Frequency Intensity." This allows them to quantify how much information each layer is processing.
  • Frequency Alignment for KD: To perform distillation, they apply a 2D FFT over the spatial dimensions of feature maps. They then minimize the Mean Squared Error (MSE) between the teacher’s and student’s frequency representations.
  • Parameter-Free Alignment: Instead of using trainable layers to match different channel counts, they use 3D adaptive average pooling. This preserves the spatial structure of features while remaining simple and interpretable.
  • Layer Selection Strategy: Based on their spectral analysis, they only align the "information-rich" layers (typically the first few and last few), rather than every single layer or just the middle ones.

Datasets

The primary benchmark used for training and evaluation is ImageNet-1K, the gold standard for image classification. The authors tested their method across several popular architectures, including:

  • CaiT-S24 and Swin-Small (as teachers)
  • DeiT-Tiny, DeiT-Small, and Swin-Tiny (as students)

Key Insights and Ideas

  • The U-Shaped Intensity Curve: The most striking discovery is that information intensity in ViTs follows a U-shape. As seen in Figure 1, the first and last layers have high spectral intensity, while the middle layers act as "smoothers" or feature refiners with lower intensity. This provides a clear roadmap for KD: focus on the ends of the network.
Figure 1. Model-wise frequency intensity analysis L(X) (Equa- tion 5), plotted across the Transformer depth for three models: (a) CaiT-S24 (teacher), (b) DeiT-Tiny without distillation, and (c) DeiT-Tiny distilled by our SpectralKD. SpectralKD clearly shifts the student’s intensities in different layers closer to those of the teacher, especially in the most information-rich layers in the early and final few layers. Both CaiT-S24 and baseline DeiT-Tiny check- points are taken from the timm library(Wightman, 2019).
  • Cross-Architecture Convergence: Despite their different designs, hierarchical models (like Swin) and uniform models (like CaiT) exhibit remarkably similar spectral encoding patterns. This suggests that "good" ViTs eventually converge on the same way of organizing information.
  • Distillation Dynamics: The authors found that aligning just a subset of layers induces a global change. Even layers that weren't explicitly distilled started to mimic the teacher's spectral patterns. This suggests that frequency alignment helps the student inherit the teacher's "hierarchical flow" of information.
  • Skewed Importance: As shown in Figure 2, a histogram of intensities reveals that only a few layers are truly "information-rich." Distilling from these peaks is significantly more effective than uniform distillation.
Figure 2. Histogram of the model-wise frequency intensities L(X) (Equation 5) for all 24 layers of CaiT-S24. The distribution is heav- ily skewed: most layers have relatively low spectral intensity, while only a small number exhibit substantially higher values. These peaks point to potentially critical layers for knowledge distillation.

Key Results

SpectralKD achieves state-of-the-art (SOTA) performance without adding any trainable parameters to the distillation process:

  • DeiT-Tiny: Improved top-1 accuracy from 72.2% (baseline) to 77.4% (+5.2%). It outperformed other popular methods like Manifold KD (76.5%) and MaskedKD (75.9%).
  • Swin-Tiny: Improved from 81.3% to 82.7% (+1.4%).
  • DeiT-Small: Reached 82.2%, matching or exceeding more complex distillation frameworks.

Qualitatively, Figure 5 demonstrates that SpectralKD-distilled students produce much sharper, teacher-like spectral profiles compared to non-distilled baselines, even in layers that weren't directly aligned.

Limitations and Future Work

While highly effective, the paper focuses primarily on image classification. The authors suggest that future work should explore:

  • Diverse Architectures: Extending the spectral analysis to convolutional-ViT hybrids.
  • Downstream Tasks: Testing if spectral distillation benefits object detection or semantic segmentation.
  • Ethical Considerations: Investigating if these distillation dynamics inadvertently amplify biases present in the teacher models.

The code and experimental logs are available at https://github.com/thy960112/SpectralKD.

Summary updated

BibTeX
@misc{tian2024spectralkd,
  author = {Huiyuan Tian and Bonan Xu and Shijian Li and Gang Pan},
  title = {{SpectralKD: A Unified Framework for Interpreting and Distilling Vision Transformers via Spectral Analysis}},
  year = {2024},
  eprint = {2412.19055},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2412.19055},
}
Figure