Knowledge distillation transfers the generalization capabilities of a cumbersome teacher model to a smaller student model by training the student to mimic the teacher's softened probability distribution. The key mechanism involves minimizing the divergence between the student's predictions and the teacher's soft labels, which contain richer dark knowledge about inter-class similarities than hard one-hot ground truth labels.
Glossary
Knowledge Distillation

What is Knowledge Distillation?
Knowledge distillation is a model compression technique where a compact 'student' model is trained to replicate the output representations of a larger, more powerful 'teacher' model.
The process typically uses a temperature parameter in the softmax function to control the smoothness of the teacher's output distribution. This allows the compact student to learn not just the final prediction, but the teacher's internal representation geometry, often achieving comparable accuracy with significantly reduced computational latency and memory footprint for production deployment.
Key Characteristics of Knowledge Distillation
Knowledge distillation transfers the generalization capabilities of a complex teacher model to a compact student model by aligning their output representations, enabling efficient deployment without sacrificing predictive performance.
Teacher-Student Architecture
The teacher is typically a large, high-capacity model or ensemble, while the student is a lightweight architecture designed for inference efficiency. The student learns not from ground-truth labels alone, but by mimicking the teacher's output distribution.
- Teacher: BERT-large, GPT-4, or an ensemble of models
- Student: DistilBERT, TinyBERT, or a MobileNet variant
- The student often shares a similar architectural inductive bias but with fewer layers or reduced hidden dimensions
Soft Target Training
Instead of training on hard one-hot labels, the student learns from the teacher's softened probability distribution over classes. A temperature parameter T in the softmax function controls the smoothness of this distribution.
- High temperature (T > 1): Produces softer probabilities, revealing inter-class similarities learned by the teacher
- Low temperature (T = 1): Approaches standard supervised learning
- The soft targets carry dark knowledge—the relative probabilities of incorrect classes that encode valuable structural information about the data manifold
Distillation Loss Formulation
The training objective combines two loss terms: a distillation loss matching the student's softened outputs to the teacher's, and a student loss against ground-truth hard labels.
- Distillation loss: KL divergence between teacher and student softmax outputs, scaled by T²
- Student loss: Standard cross-entropy with ground-truth labels
- The combined loss:
L = α * L_soft + (1-α) * L_hard - The α hyperparameter balances imitation versus direct supervision
Feature-Based Distillation
Beyond output probabilities, the student can learn by matching intermediate representations from the teacher's hidden layers. This transfers richer structural knowledge.
- Hint layers: Selected teacher layers whose activations guide corresponding student layers
- Attention transfer: Matching attention maps between teacher and student
- Relation-based distillation: Preserving pairwise relationships between samples in the embedding space
- Requires a learnable regressor or projection layer when teacher and student hidden dimensions differ
Online vs. Offline Distillation
Distillation strategies differ by when and how the teacher model participates in training.
- Offline distillation: A pre-trained, frozen teacher generates soft targets once; the student trains on these static targets—most common and computationally efficient
- Online distillation: Teacher and student train simultaneously, with the teacher updating alongside the student—useful when no pre-trained teacher exists
- Self-distillation: The same architecture serves as both teacher and student, where deeper layers or later checkpoints guide earlier ones
Distillation in Language Models
In NLP, distillation compresses large transformer models while preserving linguistic capabilities. Notable examples demonstrate significant compression ratios.
- DistilBERT: Reduces BERT-base parameters by 40% while retaining 97% of performance—trained using a triple loss combining language modeling, distillation, and cosine-distance losses
- TinyBERT: Employs both output and intermediate-layer distillation, achieving 7.5x compression
- Orca-style distillation: Uses explanation traces from large language models to teach reasoning patterns to smaller models, going beyond simple output matching
Frequently Asked Questions
Clear, technically precise answers to the most common questions about transferring knowledge from large teacher models to compact student models.
Knowledge distillation is a model compression technique where a compact student model is trained to replicate the output representations of a larger, more powerful teacher model. Rather than training the student on hard labels alone, the student learns from the teacher's softened probability distribution over classes, known as soft targets. These soft targets contain rich information about inter-class similarities that one-hot labels discard—for example, a teacher classifying an image of a car might assign a small probability to 'truck' and a negligible one to 'banana', teaching the student about semantic relationships. The process uses a temperature parameter in the softmax function to control the softness of the teacher's output distribution, with higher temperatures revealing more granular knowledge. The student's loss function typically combines a distillation loss (matching the teacher's soft targets) with a standard cross-entropy loss against ground truth labels.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Knowledge Distillation vs. Other Compression Techniques
A technical comparison of knowledge distillation against alternative model compression methodologies for reducing inference latency and memory footprint.
| Feature | Knowledge Distillation | Pruning | Quantization |
|---|---|---|---|
Core Mechanism | Trains student to mimic teacher's output distribution | Removes low-magnitude weights or neurons | Reduces numerical precision of weights and activations |
Preserves Architectural Flexibility | |||
Requires Original Training Data | |||
Typical Compression Ratio | 10-50x | 5-20x | 2-4x |
Inference Speedup | 5-15x | 2-5x | 2-4x |
Accuracy Retention | 95-99% | 90-97% | 98-99.5% |
Hardware Agnostic | |||
Training Overhead | High (requires teacher training + student distillation) | Moderate (iterative pruning and fine-tuning) | Low (post-training or quantization-aware training) |
Related Terms
Knowledge distillation is one of several techniques for reducing model size and latency. Explore the broader landscape of model compression and optimization.
Teacher-Student Architecture
The foundational framework where a large, high-capacity teacher model generates soft labels or internal representations that a compact student model is trained to mimic. The student learns not just the final hard prediction but the teacher's full output distribution, capturing subtle inter-class relationships. Key configurations include:
- Offline Distillation: Pre-trained frozen teacher guides student training
- Online Distillation: Teacher and student train simultaneously
- Self-Distillation: A model's own deeper layers teach its shallower layers
Soft Targets & Temperature Scaling
Instead of training on hard one-hot labels, the student learns from the teacher's softened probability distribution. A temperature parameter (T) is applied to the softmax function to control output smoothness:
- High T (T>1): Produces softer probabilities, revealing dark knowledge about class similarities
- Low T (T=1): Reverts to standard softmax
- The student minimizes the Kullback-Leibler divergence between its own softened outputs and the teacher's, often combined with the standard cross-entropy loss on ground truth labels
Feature-Based Distillation
Beyond matching final outputs, the student can learn to replicate the teacher's intermediate representations. This transfers richer structural knowledge:
- Hint Layers: Selected intermediate layers where the student's activations are regressed to match the teacher's
- Attention Transfer: The student mimics the teacher's self-attention maps, learning where the model focuses
- Relation-Based Distillation: Preserves the mutual relations between data samples, transferring the teacher's learned embedding space geometry rather than individual outputs
Distillation vs. Pruning vs. Quantization
Knowledge distillation belongs to a family of compression techniques, each with distinct trade-offs:
- Pruning: Removes redundant weights or neurons from a trained model, creating sparsity. Often requires fine-tuning to recover accuracy
- Quantization: Reduces numerical precision of weights (e.g., FP32 to INT8), shrinking model size and accelerating inference on specialized hardware
- Distillation: Trains a new, inherently smaller architecture. Often combined with pruning and quantization for compound compression, where a distilled student is further quantized for deployment
DistilBERT & Practical Benchmarks
A landmark application of knowledge distillation to transformer models. DistilBERT was trained to replicate BERT-base using a triple loss combining language modeling, distillation, and cosine-distance losses:
- Retains 97% of BERT's performance on GLUE benchmark
- 40% fewer parameters and 60% faster inference
- Demonstrates that general-purpose language understanding can be preserved in a significantly leaner architecture, establishing a blueprint for distilling large language models
Data-Free Distillation
A technique for scenarios where the original training data is inaccessible due to privacy, proprietary, or storage constraints. The student is trained using synthetically generated samples that maximize the teacher's output diversity:
- Adversarial Generation: A generator creates inputs that cause the teacher to produce high-entropy outputs, exposing decision boundaries
- Activation Maximization: Synthesizes inputs that strongly activate specific teacher neurons
- Critical for distilling models trained on sensitive data while preserving privacy compliance

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us