Improving Language Model Distillation through Hidden State Matching

Sayantan Dasgupta, Trevor CohnICLR 2025

Introduction

To deploy massive Large Language Models (LLMs) on resource-constrained devices, practitioners frequently rely on Knowledge Distillation (KD) to train a smaller "student" model to mimic a larger "teacher." One of the most effective KD techniques is hidden state matching, which forces the student's internal representations to align with the teacher's (a method famously used to build DistilBERT).

However, standard hidden state matching uses cosine similarity, which mathematically requires the student and teacher to have the exact same hidden dimension size. To compress models, researchers are usually forced to drop layers—making the model shallower but still wide—rather than reducing the hidden dimension. The standard workaround for shrinking the dimension is adding a linear projection layer to match sizes, but this technique falls apart at high compression ratios (e.g., >3x).

This paper tackles the challenge of effectively matching hidden states when the student is significantly narrower than the teacher, introducing a novel distillation method that allows for highly compressed student models retaining impressive performance across classification, summarization, and translation tasks.

Methodology: Centered Kernel Alignment (CKA)

The authors replace the standard cosine loss or linear projection with a loss function based on Centered Kernel Alignment (CKA). CKA is a statistical method typically used to measure the similarity between representations of heterogeneous neural networks. Because CKA compares the relational structure of the data rather than the raw vectors, it can easily compare hidden states of different dimensionalities.

Architecture of Teacher-Student distillation using CKA to match hidden states of different dimensions.

To make this computationally feasible for LLM training—since standard CKA requires computing Singular Value Decomposition (SVD) over the entire dataset—the authors use a Minibatch CKA approach. They estimate covariance matrices for every minibatch and accumulate them over time to stabilize the variance.

The training pipeline consists of two stages:

  1. Pretraining Distillation: The student is trained from scratch on a massive unsupervised or multilingual corpus (like C4 or mC4). The loss function combines Causal Language Modeling (CLM), KL Divergence (matching teacher logits), and the new CKA hidden state loss.
  2. Supervised Distillation/Fine-tuning: The pretrained student is fine-tuned on specific downstream tasks, such as translation or summarization.

Key Insights and Results

The CKA method was evaluated across a variety of architectures (BART, mBART, Flan-T5, BERT) and tasks, revealing several critical insights into model compression.

  • Narrower is Better: When trained effectively using CKA, deeper and narrower student models actually outperform wider, shallower ones.
  • Linear Projection Hits a Wall: The traditional linear projection baseline works fine up to a 3x compression ratio. Beyond that, the hidden states become too disparate, and linear projection actually degrades performance. CKA, however, continues to provide massive benefits up to 5.5x and beyond.
  • Cheaper than Sequence-Level KD: Traditional generative distillation requires running expensive beam-search decoding on the teacher to generate pseudo-labels for millions of examples. This CKA approach only requires standard forward passes to extract hidden states, making it vastly more compute-efficient for data augmentation.

Performance Highlights

Distillation loss and BLEU scores for mBART models comparing CKA against linear projection and baselines.
  • Extreme Compression (Flan-T5): The authors successfully distilled a 3B parameter Flan-T5 teacher into a tiny 145M parameter student—a ~20x compression ratio. On English-to-Romanian translation, the student achieved a 27.2 BLEU score, only 0.8 points lower than the massive teacher.
  • Machine Translation (mBART): At a 5x compression ratio (122M student from a 610M teacher), the CKA method improved the BLEU score by +9.9 (EN-RO) and +4.7 (EN-FR) compared to a baseline with no hidden state loss. Notably, the linear projection baseline failed to even converge at this size.
  • Summarization (BART): At a 5.5x compression ratio (80M student from a 440M teacher), CKA improved ROUGE-2 scores by +1.7 on CNN/Daily Mail and +1.5 on XSum.
  • Classification (BERT): A 67M parameter student trained with CKA outperformed the standard 6-layer DistilBERT on almost all GLUE tasks.

Limitations and Future Work

While highly effective, the approach has a few limitations. First, convergence instability at scale can be an issue. For the most complex models (like Flan-T5) at extreme compression ratios, the CKA loss alone struggles to converge. The authors noted that some of their smallest Flan-T5 models required weight initialization bootstrapped from other converged models to train successfully.

Second, there is still a significant pretraining cost. While cheaper than generating teacher labels via beam search, the method still relies on a compute-intensive pretraining distillation phase on massive corpora before the model is useful for downstream tasks. Furthermore, the authors note that this pretraining is non-negotiable for tasks like translation; you cannot just distill an encoder-decoder model on a small downstream dataset, as the student needs the multilingual pretraining phase to build proper word representations first.

Summary updated

BibTeX
@inproceedings{dasgupta2025improving,
  author = {Sayantan Dasgupta and Trevor Cohn},
  title = {{Improving Language Model Distillation through Hidden State Matching}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=IcVSKhVpKu},
}
Figure