ALP-KD: Attention-Based Layer Projection for Knowledge Distillation

Peyman Passban, Yimeng Wu, Mehdi Rezagholizadeh, Qun Liu

Introduction

Knowledge Distillation (KD) has become a cornerstone of model compression, enabling the transfer of performance from large, computationally expensive "teacher" networks to smaller, efficient "student" networks. While early KD methods focused primarily on the teacher's final output, modern state-of-the-art approaches emphasize distilling "intermediate" knowledge from the teacher's internal layers.

However, a significant structural challenge arises when the teacher network is substantially deeper than the student (e.g., distilling a 12-layer BERT-Base into a 4-layer student). Traditionally, this is addressed by layer skipping—selecting a subset of teacher layers (e.g., every third layer) for the student to mimic. The authors of ALP-KD identify two critical flaws in this approach: the Skip Problem, where valuable information in ignored layers is lost, and the Search Problem, where finding the optimal subset of layers requires expensive trial-and-error.

Methodology: Attention-Based Fusion

To overcome these limitations, the authors propose ALP-KD (Attention-based Layer Projection for Knowledge Distillation). Instead of a rigid one-to-one mapping between student and teacher layers, ALP-KD employs a dynamic fusion strategy.

Comparison of layer mapping strategies: (a) skip-based mapping, (b) bucketed mapping, and (c) ALP-KD's dense attention-based fusion.

Combinatorial Fusion and Attention

ALP-KD replaces layer skipping with an attention-based combination mechanism. For every student layer, the model calculates a weighted combination of all teacher layers. This is achieved through a dot-product attention mechanism where the student layer acts as a query, "looking" at the teacher layers to determine which internal representations are most relevant to its current learning stage.

By allowing the attention mask to span the entire depth of the teacher, the model effectively eliminates the search problem. The optimal mapping is no longer a manual heuristic but a learned parameter optimized during training. The final training objective integrates standard cross-entropy for hard labels, soft-label KD, and a Mean Square Error (MSE) loss between the student’s layers and the attention-fused teacher representations.

Experimental Evaluation

The authors evaluated ALP-KD on the GLUE (General Language Understanding Evaluation) benchmark, using BERT-Base (12 layers) as the teacher and testing student versions with 6, 4, and 2 layers.

Key Results

  • 4-Layer Student: ALP-KD achieved an average GLUE score of 77.01, outperforming the popular Patient KD (PKD) baseline (76.44) and concatenation-based methods (76.73).
  • 2-Layer Student: The performance advantage was most significant here, with ALP-KD reaching 67.08, compared to the best PKD configuration of 66.28. This suggests that the benefit of attention-based fusion increases as the architectural gap between teacher and student widens.

Qualitative Analysis

Beyond raw performance metrics, the authors used Principal Component Analysis (PCA) to visualize the internal states of the models. The analysis revealed that ALP-KD student representations are mathematically much closer to the teacher's internal states than those produced by skipping-based methods.

PCA visualization of internal layer representations, demonstrating that ALP-KD (red) clusters significantly closer to the teacher (green) than the PKD baseline (blue).

This proximity is further supported by cosine similarity metrics, which show that ALP-KD maintains a higher information density by ensuring no teacher layer is "left behind." Even deep teacher layers were found to provide useful signals to early student layers, a phenomenon that traditional skipping methods fail to capture.

Discussion and Limitations

While ALP-KD offers a robust solution to the layer-mapping problem, it does introduce a slight computational overhead during the training phase due to the attention mechanism. However, this does not affect inference speed, as the student model remains compact.

Future work may explore applying this attention-based fusion to other internal components, such as individual attention heads, to provide even more granular supervision. For now, ALP-KD stands as a powerful method for closing the performance gap in extreme model compression scenarios.

Summary updated

BibTeX
@inproceedings{passban2021alp,
  author = {Peyman Passban and Yimeng Wu and Mehdi Rezagholizadeh and Qun Liu},
  title = {{ALP-KD: Attention-Based Layer Projection for Knowledge Distillation}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2021},
  doi = {10.1609/aaai.v35i15.17610},
}
Figure