TL;DR
Knowledge Distillation (KD) typically relies on a fixed temperature hyperparameter to soften probability distributions, which fails to adapt to a student model's learning progress. This paper introduces the Dynamic Temperature Scheduler (DTS), a plug-and-play method that dynamically adjusts temperature based on the cross-entropy loss gap between the teacher and student. Without adding any learnable parameters, DTS consistently outperforms static baselines and complex adaptive schedulers across both computer vision and NLP tasks.
What Problem Does This Paper Address?
Knowledge Distillation (KD) transfers the "dark knowledge" of a large, pre-trained teacher model to a smaller, efficient student model by having the student match the teacher's softened output probabilities. This softness is controlled by a hyperparameter called temperature ($T$). A high temperature creates a softer, more uniform distribution that highlights relationships between incorrect classes, while a low temperature sharpens the distribution to focus heavily on the top predictions.
Traditionally, this temperature is kept static throughout training. However, a static temperature is fundamentally suboptimal:
- Early in training: The student is highly uncertain and benefits from a higher temperature to absorb broad inter-class relationships from the teacher.
- Late in training: As the student gains confidence, it requires a lower temperature to refine fine-grained distinctions and sharpen its predictions.
While previous works have attempted to dynamically adjust temperature, they usually introduce heavy computational overheads, requiring multi-stage training pipelines, reinforcement learning loops, or auxiliary learnable neural network modules.
Methods
The authors propose the Dynamic Temperature Scheduler (DTS), a lightweight, non-learnable framework that automatically tunes the temperature on the fly.
As illustrated in Figure 1, DTS computes the temperature at each epoch using three core components:
- Cosine Scheduling: A baseline curriculum that smoothly decays the temperature from an initial maximum ($T_{max}$) to a minimum ($T_{min}$) as training progresses.
- Loss Divergence Adaptive Scaling: DTS measures the real-time performance gap between the models by calculating the difference between the teacher's and student's cross-entropy losses ($d_{loss} = L_t - L_s$). This divergence dynamically scales the temperature based on how well the student is tracking the teacher.
- Clamping and Momentum Updates: To prevent abrupt temperature swings that could destabilize training, the calculated temperature is clamped within the predefined $[T_{min}, T_{max}]$ range and smoothed using a momentum-based update rule (default coefficient $\mu = 0.9$).
Datasets
The authors validated DTS across a diverse set of tasks and architectures:
- Computer Vision: Evaluated on CIFAR-100 and Tiny-ImageNet using various convolutional networks (ResNet, WRN, VGG, MobileNet) and Vision Transformers (DeiT, PvT, PiT).
- Natural Language Processing: Tested on encoder models using the GLUE benchmark (CoLA, MRPC, RTE tasks) and on autoregressive generative language models (GPT-2, OPT) trained on the Dolly-15k dataset. Generative performance was evaluated across benchmarks like DollyEval, SelfInst, S-NI, and UnNI.
Key Insights and Ideas
- The Gradient Goldilocks Zone: The authors mathematically demonstrate that if $T \rightarrow 0$ early in training, gradients grow unboundedly and destabilize learning. Conversely, if $T \rightarrow \infty$ late in training, gradients vanish, causing the student to underfit. A dynamic schedule is essential to maintain an effective gradient flow.
- Eliminating Auxiliary Modules: Unlike competing dynamic methods like CTKD (which uses learnable modules) or AKD (which requires multi-stage training), DTS achieves superior results purely through deterministic mathematical scheduling based on loss tracking.
- Architectural Gaps Matter: The optimal temperature range depends heavily on the structural similarity between the models. Cross-architecture distillation (e.g., distilling a CNN teacher into a ViT student) performs better with lower, tighter temperature ranges ($3 \rightarrow 1$) than same-architecture distillation ($8 \rightarrow 4$).
Key Results
DTS consistently outperformed static baselines and state-of-the-art dynamic temperature methods across all tested configurations:
- Vision Baselines (CIFAR-100): For a VGG13 $\rightarrow$ VGG8 distillation setup, KD + DTS achieved a top-1 accuracy of 72.77%, outperforming AKD (67.81%) and CTKD (72.02%).
- CNN to MobileNet (Tiny-ImageNet): Integrating DTS into a ResNet50 $\rightarrow$ MobileNet-V1 pipeline boosted accuracy from 56.84% (vanilla KD) to 61.18%.
- Large Language Models: When distilling generative models like GPT-2 (120M parameters) from a 1.5B teacher, DTS consistently improved ROUGE-L scores across multiple generation benchmarks (e.g., boosting the UnNI benchmark score from 18.46 to 19.66).
Limitations and Future Work
Despite its strong performance, the authors note a few limitations:
- Shared Temperature: The teacher and student still share the exact same temperature value during distillation, which might not perfectly accommodate severe architectural mismatches.
- Hyperparameter Bounds: While DTS eliminates learnable parameters, users must still manually define the initial temperature bounds ($T_{max}$ and $T_{min}$).
- Batch-wise Sensitivity: Because temperature updates happen batch-wise based on loss divergence, an anomalous or highly noisy batch could cause sudden, suboptimal temperature fluctuations.
Future Directions: The authors suggest exploring instance-wise temperature scheduling, which would dynamically adjust the temperature for individual samples based on their specific difficulty.
Summary updated