ViT-Linearizer: Distilling Quadratic Knowledge into Linear-Time Vision Models

Guoyizhe Wei, Rama Chellappa

TL;DR

Vision Transformers (ViTs) offer powerful representations but suffer from quadratic computational complexity. This paper introduces ViT-Linearizer, a distillation framework that transfers ViT's knowledge into efficient, linear-time recurrent models (like Mamba-based architectures) by matching intermediate activations and using masked prediction. This allows for significant speedups on high-resolution tasks without sacrificing accuracy, making advanced vision models more practical for real-world deployment.

What Problem Does This Paper Address?

Vision Transformers (ViTs) have revolutionized visual representation learning due to their global self-attention mechanism. However, this self-attention mechanism has a quadratic computational complexity with respect to the input sequence length. This makes ViTs computationally expensive and memory-intensive, especially when dealing with high-resolution images or long sequences, posing a significant challenge for efficient inference on hardware. While this was less of an issue for standard benchmarks, the increasing demand for processing high-fidelity visual inputs necessitates more efficient alternatives. Recurrent models like Mamba offer linear complexity, but their potential has been underexplored, and they often lag behind ViTs in performance. This paper aims to bridge this gap by transferring the rich knowledge learned by ViTs into these efficient linear-time models.

Methods

The core of ViT-Linearizer is a cross-architecture distillation framework that transfers knowledge from a pre-trained ViT (teacher) to a linear-time recurrent model (student). The key novelties lie in two main techniques:

  • Activation Matching: Instead of just matching the final outputs, this method aligns intermediate activation maps between the teacher and student models. Specifically, it computes pairwise cosine similarities of token embeddings at multiple intermediate layers to capture token-wise dependencies. This is done by minimizing an L2 loss between the normalized activation maps, encouraging the student to mimic the teacher's learned representations. This is framed as a "quadratic constraint" that is crucial for distilling quadratic knowledge.
  • Masked Prediction: Inspired by masked image modeling in ViT pretraining, this technique involves masking a portion of input patches for the student model and training it to predict the teacher's representations for these masked tokens. This helps the student learn robust feature representations and reasoning capabilities.

The overall framework trains only the student model while keeping the teacher frozen. The total loss is a combination of the activation matching loss and the masked prediction loss.

Datasets

  • Training: ImageNet-1k (1.28 million images) was used for the distillation phase, without utilizing class labels.
  • Evaluation:
    • ImageNet-1k: For image classification.
  • ADE20K: For semantic segmentation (20k images, 150 categories), with inputs cropped to 512x512.
  • Cityscapes: For semantic segmentation (5,000 images), with inputs resized to 512x1024.

No new benchmarks were introduced.

Key Insights and Ideas

  • Intermediate Activations Matter: Simply distilling the final layer outputs of ViTs isn't enough. Aligning intermediate activation maps is crucial for transferring the nuanced, token-wise dependencies learned by self-attention.
  • Quadratic Constraint for Quadratic Knowledge: The activation matching loss, which involves pairwise token similarities, acts as a "quadratic constraint" that is essential for effectively distilling the quadratic knowledge from ViTs.
  • Masked Prediction Enhances Robustness: Similar to ViT pretraining, masked prediction is vital for improving the representational capabilities of the student models, especially for Mamba-based architectures.
  • Synergy of Techniques: Both activation matching and masked prediction are beneficial individually, but their combination yields the best results, demonstrating their complementary roles.
  • Teacher-Student Size Flexibility: The distillation process works effectively even when the student model is not the same size as the teacher, and surprisingly, a larger student can even benefit from a smaller, well-pretrained teacher.
  • Linearization is Practical: The approach successfully bridges the gap between theoretical efficiency (linear complexity) and practical effectiveness (high accuracy) for vision models.

Key Results

  • ImageNet Classification: The distilled Adventurer-Base model achieved a competitive 84.3% top-1 accuracy on ImageNet, outperforming existing Mamba-based models. When using a 448x448 input size, the model achieved a 2.1x speedup with only a 0.3% drop in accuracy compared to the teacher.
  • Semantic Segmentation:
    • On ADE20K (512x512 input), the distilled model achieved 51.3% mIoU, outperforming baselines and achieving a 2.74x speedup.
  • On Cityscapes (512x1024 input), the model achieved 82.0% mIoU, with a remarkable 4.21x speedup over its ViT teacher.
  • Qualitative Results: Activation maps from the distilled model closely aligned with those of the ViT teacher, showing improved contrast and highlighted salient regions compared to a purely supervised student model.
  • Generalizability: The ViT-Linearizer approach demonstrated effectiveness across different teacher models (DeiT-III, MAE, CLIP) and student model sizes, highlighting its versatility.

Limitations and Future Work

  • Computational Cost of Activation Matching: While the overall inference is linear, the activation matching loss itself involves O(L^2) computations during training. The authors acknowledge this but argue it's a necessary component for effective distillation.
  • Future Work: The authors suggest exploring larger-scale ViT-Linearizer models for more critical roles in long-sequence vision tasks. They also envision this approach leading to a new transfer learning paradigm where model complexity is reduced for inference efficiency, allowing seamless inheritance of pretraining knowledge. The potential for this approach to extend to even higher resolutions and longer sequences is highlighted.

Summary updated

BibTeX
@inproceedings{wei2025vit,
  author = {Guoyizhe Wei and Rama Chellappa},
  title = {{ViT-Linearizer: Distilling Quadratic Knowledge into Linear-Time Vision Models}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2025},
}
Figure