Universal-KD: Attention-based Output-Grounded Intermediate Layer Knowledge Distillation

Yimeng Wu, Mehdi Rezagholizadeh, Abbas Ghaddar, Md. Akmal Haidar, Ali Ghodsi

Knowledge Distillation (KD) is a cornerstone technique for compressing large, high-performing "teacher" models into smaller, efficient "student" models. While traditional KD focuses on matching final outputs, Intermediate Layer Distillation (ILD) aims to transfer richer internal representations. However, ILD is often hindered by the difficulty of interpreting hidden states, the complexity of manual layer mapping, and the incompatibility of different model architectures.

Universal-KD addresses these challenges by introducing an attention-based, output-grounded framework. By mapping internal states into a shared output space and using attention for dynamic layer alignment, it enables effective distillation across diverse architectures and bridges the capacity gap between teacher and student.

The Challenges of Knowledge Distillation

Existing ILD methods face several critical limitations that Universal-KD aims to resolve:

  1. Interpretability: Hidden layers are high-dimensional vectors with no inherent semantic meaning, making it hard to track what knowledge is being transferred.
  2. Layer Mapping: Determining which teacher layers should correspond to which student layers typically requires exhaustive manual search or rigid heuristics.
  3. Architecture Mismatch: Matching the internal states of a Transformer to an LSTM or CNN is mathematically challenging due to differing representation spaces.
  4. Capacity Gap: A significant performance difference between teacher and student can lead to poor convergence, as the student struggles to mimic an overly complex teacher.
Comparison of Knowledge Distillation (KD) methods across various dimensions, highlighting the unique features of Universal-KD.

The Universal-KD Framework

Universal-KD introduces three primary innovations to overcome these hurdles:

Pseudo-Classifiers (Output-Grounded Distillation)

Instead of matching raw hidden vectors, Universal-KD attaches a small "pseudo-classifier" (a linear layer) to every intermediate layer. This maps internal states into a common "output space" of class probabilities. This "output-grounding" ensures that the student mimics the teacher's predictions at each stage, providing a semantically meaningful target.

Attention-based Layer Projection

Rather than enforcing a fixed 1-to-1 mapping, each student layer employs an attention mechanism to aggregate information from all teacher layers. This allows the student to dynamically determine which teacher layers are most relevant, effectively automating the layer-matching process.

The Universal-KD framework for Intermediate Layer Distillation (ILD), highlighting the use of pseudo-classifiers and attention-based projection for dynamic layer alignment.

Pseudo-Teacher Assistants (Pseudo-TAs)

To handle the capacity gap, the framework utilizes the teacher's intermediate pseudo-classifiers as "Teacher Assistants." The student’s final layer learns from a weighted combination of these intermediate teacher outputs, creating a more gradual and manageable learning objective.

Experimental Evaluation

The framework was evaluated on the GLUE benchmark across eight tasks, including sentiment analysis, linguistic acceptability, and natural language inference. The researchers tested several scenarios:

  • Homogeneous Distillation: BERT-base to BERT-4 and RoBERTa-large to DistilRoBERTa.
  • Cross-Architecture Distillation: BERT-base to Bi-LSTM and Gated-CNN.

Universal-KD consistently outperformed existing ILD methods like PKD, ALP-KD, and MHKD. For a 4-layer BERT student, it achieved an average GLUE score of 77.4. Notably, it demonstrated significant gains in cross-architecture settings, where a Bi-LSTM student improved its average score from 58.9 to 60.2.

Key Insights

  • Logits as a Universal Language: By distilling in the output space, architectural differences become irrelevant. A CNN can learn from a Transformer because both can produce class probabilities.
  • Dynamic Alignment: Empirical evidence from attention weights reveals that student layers often benefit from a mixture of teacher layers, particularly the more accurate later layers, rather than a simple linear mapping.
  • Efficiency: Using internal layers as "Teacher Assistants" eliminates the need to train separate intermediate models, significantly reducing computational overhead.

Conclusion

Universal-KD simplifies and enhances intermediate layer distillation by grounding hidden states in a shared output space and automating layer alignment via attention. Its ability to bridge the capacity gap and support cross-architecture transfer makes it a versatile tool for model compression in diverse NLP applications.

Summary updated

BibTeX
@inproceedings{wu2021universal,
  author = {Yimeng Wu and Mehdi Rezagholizadeh and Abbas Ghaddar and Md. Akmal Haidar and Ali Ghodsi},
  title = {{Universal-KD: Attention-based Output-Grounded Intermediate Layer Knowledge Distillation}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2021},
  doi = {10.18653/v1/2021.emnlp-main.603},
}
Figure