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

Huiyuan Tian, Bonan Xu, Shijian Li, Gang Pan · DOI

Knowledge Distillation (KD) has become a cornerstone technique for deploying high-performance Vision Transformers (ViTs) on resource-constrained edge devices. By training a compact "student" model to replicate the behavior of a large "teacher," researchers can achieve significant performance gains. However, the internal mechanisms of this process have largely remained a "black box." A new framework, SpectralKD, addresses this gap by utilizing spectral analysis to provide a unified theoretical foundation for both interpreting ViT behavior and optimizing the distillation process.

The "Spectral Signature" of Vision Transformers

The core innovation of SpectralKD is the application of Fast Fourier Transforms (FFT) to the intermediate feature maps of ViTs. By analyzing the "spectral intensity" across different layers, the authors discovered a consistent pattern: information is not processed uniformly throughout the network. Instead, ViTs exhibit a U-shaped intensity curve, where the majority of information encoding occurs in the very first and last few layers. The middle layers typically act as "smoothers," showing a decay in high-frequency intensity.

Surprisingly, this spectral signature appears to be a point of convergent evolution. Despite their architectural differences, models like the hierarchical Swin Transformer and the uniform CaiT exhibit remarkably similar spectral encoding patterns. This suggests that efficient vision models naturally converge toward a specific organization of information across their depth.

The SpectralKD Framework

Building on these insights, the SpectralKD framework optimizes distillation through a two-pronged approach:

  1. Strategic Layer Selection: Rather than distilling every layer uniformly, SpectralKD targets the "information-rich" peaks identified by the U-shaped curve (the early and late layers). This focuses the student's learning capacity on the most critical representations.
  2. Frequency-Domain Alignment: The framework aligns the student and teacher in the frequency domain using a 2D FFT across spatial dimensions. This captures both global structural information (low frequencies) and fine-grained details (high frequencies) more effectively than standard spatial-domain MSE losses.
  3. Parameter-Free Architecture: Unlike many KD methods that require additional trainable "projection heads" to match feature dimensions, SpectralKD utilizes 3D adaptive pooling. This keeps the distillation process pure, interpretable, and computationally efficient.

Distillation Dynamics and Results

A key discovery of this research is the phenomenon of "distillation dynamics." When a student is distilled using SpectralKD, it doesn't just improve its accuracy; its entire internal spectral profile shifts to mirror the teacher's. Even layers that were not explicitly targeted for distillation begin to adopt the teacher's U-shaped signature.

Spectral intensity profiles for teacher (CaiT-S24), baseline student (DeiT-T), and student distilled via SpectralKD. Note how the distilled student (c) mirrors the teacher's U-shape (a) compared to the undistilled baseline (b).

The empirical results on ImageNet-1K are significant. SpectralKD achieved state-of-the-art performance without adding any inference-time overhead:

  • DeiT-Tiny: Accuracy improved from 72.2% to 77.4% (+5.2%).
  • Swin-Tiny: Accuracy increased by +1.4%, reaching 82.7%.

Conclusion and Future Directions

SpectralKD provides a principled way to understand and optimize Vision Transformers. By revealing the underlying spectral signatures of these models, it moves KD from a trial-and-error process to a theoretically grounded engineering task. Future work may extend this spectral framework to dense prediction tasks like object detection or explore its application in Large Language Models (LLMs), potentially offering new avenues for compressing massive text transformers.

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