Knowledge distillation is a model compression technique where a compact student model is trained to mimic the output distribution of a larger, pre-trained teacher model, rather than training solely on ground-truth labels. The student learns from both hard labels and the teacher's soft targets—the class probability outputs—which encode rich inter-class similarity information that one-hot labels discard.
Glossary
Knowledge Distillation

What is Knowledge Distillation?
A technique for transferring the generalization ability of a large, complex model to a smaller, efficient one.
The student minimizes a composite loss function combining the standard cross-entropy with ground truth and the Kullback-Leibler divergence between its softened output and the teacher's softened output, controlled by a temperature parameter that smooths the probability distribution. This transfers the teacher's dark knowledge to a smaller network suitable for low-latency inference.
Core Characteristics of Knowledge Distillation
Knowledge distillation transfers the generalization ability of a large, cumbersome teacher model to a compact, deployment-ready student model by training the student to mimic the teacher's output distribution.
Teacher-Student Architecture
The fundamental framework involves a two-model setup. A high-capacity teacher (often an ensemble or large transformer) generates soft probability distributions over classes. A lightweight student is trained not just on hard labels, but to replicate these soft targets, capturing the teacher's nuanced generalization patterns and inter-class similarities.
Soft Targets & Temperature
The key mechanism uses a temperature parameter (T) in the final softmax layer. A high T > 1 softens the probability distribution, revealing the 'dark knowledge' of the teacher—such as which incorrect classes are more similar to the correct one. The student is trained to minimize the Kullback-Leibler (KL) divergence between its softened outputs and the teacher's.
Distillation Loss Formulation
The total training loss is a weighted combination of two objectives:
- Distillation Loss: KL divergence between the softened student and teacher outputs, scaled by T².
- Student Loss: Standard cross-entropy between the student's hard predictions and the ground-truth labels. This dual-objective ensures the student learns both the correct answer and the teacher's reasoning structure.
Offline vs. Online Distillation
Offline distillation pre-trains a static teacher, then transfers knowledge to the student in a separate phase—the most common industrial approach. Online distillation updates both models simultaneously during training, allowing the teacher and student to co-evolve. Self-distillation uses the same architecture for both roles, where a deeper network teaches a shallower version of itself.
Feature-Based Distillation
Beyond output probabilities, knowledge can be transferred from intermediate representations. The student is trained to match the teacher's feature maps or attention patterns at specific layers using L2 or cosine similarity losses. This is critical for compressing deep vision models where spatial hierarchies encode essential structural knowledge.
Distillation for Deployment
The primary industrial application compresses massive models like GPT-4 or BERT-Large into latency-optimized variants (e.g., DistilBERT) for production serving. Benefits include:
- Reduced latency: 10-50x faster inference
- Lower memory footprint: Enables on-device deployment
- Minimal accuracy loss: Often retains 95-97% of teacher performance
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.
Frequently Asked Questions
Addressing the most common technical and strategic questions about transferring knowledge from large teacher models to compact student networks for production deployment.
Knowledge distillation is a model compression technique where a compact 'student' model is trained to replicate the behavior of a larger, more complex 'teacher' model, transferring its generalization capabilities to a smaller architecture suitable for low-latency deployment. The process works by using the teacher's softened output probabilities—rather than hard labels—as training targets for the student. Instead of learning solely from ground-truth labels, the student learns from the teacher's logits (pre-softmax activations), which contain rich information about inter-class similarities. A temperature parameter T in the softmax function controls the softness of these probability distributions: higher temperatures reveal the 'dark knowledge' of which classes the teacher considers similar, providing a more informative training signal than one-hot labels alone. The student is trained with a combined loss function that balances mimicking the teacher's softened outputs against matching the original hard labels, enabling the compact model to achieve accuracy approaching the teacher's while requiring a fraction of the computational resources.
Related Terms
Knowledge distillation is part of a broader toolkit for deploying performant models under strict latency and resource constraints. These related concepts define the teacher-student dynamic and complementary compression strategies.
Teacher-Student Architecture
The foundational framework of knowledge distillation. A high-capacity teacher model (often an ensemble or large transformer) generates soft probability distributions over outputs. A compact student model is trained not just on hard labels, but to match these soft targets, which encode rich inter-class similarity structures that hard labels discard. The student learns the teacher's generalization patterns, often outperforming a model trained on raw data alone.
Temperature Scaling
A critical hyperparameter in the distillation loss function. A temperature parameter (T) is applied to the softmax of both teacher and student logits before computing the KL divergence. Higher temperatures (e.g., T=20) soften the probability distribution, revealing the dark knowledge of which classes the teacher considers similar. This prevents the student from overfitting to the teacher's overconfident predictions on easy examples.
Weight Pruning
A complementary compression technique that removes individual weights or entire neurons from a trained network based on a saliency criterion, such as magnitude. Unstructured pruning zeroes out individual weights, leading to sparse matrices, while structured pruning removes entire channels or layers, yielding immediate inference speedups on commodity hardware without specialized sparse compute libraries.
Post-Training Quantization
Reduces model footprint by converting 32-bit floating-point weights and activations to lower-precision formats like INT8 or FP16. This technique is often applied to a distilled student model for a second stage of compression. Quantization-aware training (QAT) simulates quantization noise during distillation, while post-training quantization (PTQ) requires only a small calibration dataset, making it ideal for edge deployment.
Feature-Based Distillation
An extension beyond matching final output probabilities. The student is trained to mimic the intermediate representations of the teacher, such as feature maps in convolutional layers or attention patterns in transformers. A regression loss (L2 or cosine similarity) aligns the student's hidden states with the teacher's, transferring the hierarchical feature extraction process directly. This is especially effective when the student and teacher have similar depth but different widths.
Ensemble Distillation
A technique where the teacher is an ensemble of diverse models. The student learns to mimic the averaged soft predictions of the entire committee, effectively compressing the collective wisdom of multiple high-capacity models into a single fast one. This captures model uncertainty and often yields a student that generalizes better than any single teacher, at a fraction of the ensemble's inference cost.

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