Knowledge distillation is a model compression technique where a smaller student model is trained to mimic the output logits and intermediate representations of a larger, pre-trained teacher model. Rather than training on hard labels alone, the student learns from the teacher's softened probability distribution, which encodes rich inter-class similarity information known as dark knowledge. This transfers the teacher's generalization capabilities into a compact, deployment-efficient architecture.
Glossary
Knowledge Distillation

What is Knowledge Distillation?
A model compression technique where a compact student model is trained to replicate the behavior of a larger, more powerful teacher model, transferring dark knowledge through softened probability distributions.
The process uses a temperature parameter in the softmax function to soften the teacher's output distribution, revealing subtle relationships between classes that hard labels obscure. The student is optimized using a weighted combination of the standard task loss and a distillation loss—typically Kullback-Leibler divergence—between its softened outputs and the teacher's. Variants include feature-based distillation, where the student matches the teacher's intermediate activations, and self-distillation, where a model's own predictions serve as the teacher.
Key Characteristics of Knowledge Distillation
A teacher-student training paradigm where a compact model learns to replicate the generalized behavior of a larger, more complex model by matching its softened output distribution.
Teacher-Student Architecture
The core framework involves two distinct models: a large, pre-trained teacher and a compact, untrained student. The student is trained on a composite loss function that combines the standard hard-label loss with a distillation loss that penalizes divergence from the teacher's softened probability distribution. The teacher's weights are frozen during this process, and the student's architecture is typically a shallower or thinner variant of a convolutional or transformer backbone.
Soft Targets and Temperature Scaling
The teacher's raw output logits are passed through a softmax function with a raised temperature parameter (T > 1). This softens the probability distribution, revealing the dark knowledge of inter-class similarities learned by the teacher. For example, a teacher classifying a car might assign a higher probability to 'truck' than to 'apple', providing richer supervisory signal than a one-hot hard label. The student is trained to match this softened distribution using Kullback-Leibler divergence.
Distillation Loss Formulation
The total training objective for the student is a weighted sum of two loss terms:
- Student Loss: Cross-entropy between the student's predictions (at T=1) and the ground-truth hard labels.
- Distillation Loss: KL divergence between the softened student output (at T>1) and the softened teacher output (at T>1), scaled by T² to maintain gradient magnitudes. The weighting hyperparameter α balances the influence of the true labels against the teacher's guidance.
Feature-Based and Relation-Based Distillation
Beyond matching output probabilities, distillation can occur at intermediate layers:
- Feature-based distillation: The student is trained to minimize the L2 distance between its intermediate feature maps and those of the teacher, often after a learned linear projection to align dimensions.
- Relation-based distillation: The student learns to preserve the pairwise similarity structure of the teacher's representations, transferring the manifold geometry of the embedding space rather than individual activations.
Self-Distillation and Online Distillation
Distillation variants that eliminate the need for a separate pre-trained teacher:
- Self-distillation: A model is iteratively trained where a later checkpoint serves as the teacher for an earlier one, or the same architecture is used for both roles, improving generalization without a larger model.
- Online distillation: The teacher and student are trained simultaneously from scratch, with the teacher's parameters updated as an exponential moving average of the student's weights, as seen in frameworks like DINO.
Application in Vision Transformers
Knowledge distillation is critical for deploying Vision Transformers on resource-constrained devices. The DeiT (Data-efficient Image Transformer) training recipe uses a convolutional RegNet as a teacher to train a ViT student on ImageNet-1k without external data. The distillation token, a dedicated learnable embedding, interacts with the teacher's hard-label predictions through a separate cross-entropy loss, enabling the transformer to learn convolutional inductive biases.
Frequently Asked Questions
Clear, technically precise answers to the most common questions about model compression via knowledge distillation, targeting the mechanisms, trade-offs, and implementation details that matter to engineering teams.
Knowledge distillation is a model compression technique where a smaller, computationally efficient student model is trained to mimic the behavior of a larger, pre-trained teacher model. Instead of training the student solely on hard ground-truth labels, the student learns from the teacher's softened output probability distribution over classes, known as soft labels or soft targets. These soft targets are generated by raising the temperature parameter T in the final softmax layer of the teacher, which reveals the dark knowledge—the relative similarities between incorrect classes that the teacher has learned. The student is trained with a composite loss function that combines the standard cross-entropy loss against the true labels and a distillation loss, typically Kullback-Leibler divergence, against the teacher's soft targets. This process transfers the generalization capabilities and inter-class relationships of the cumbersome teacher into a compact, deployable student model without requiring the original massive training dataset.
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.
Related Terms
Knowledge distillation relies on a constellation of architectural and training paradigms. These related terms define the core mechanisms that enable a compact student model to effectively mimic a high-capacity teacher.
Vision Transformer (ViT)
A neural network architecture that applies a standard Transformer encoder directly to sequences of image patches for image classification, replacing convolutional inductive biases with global self-attention. ViTs serve as powerful, high-capacity teacher models in medical imaging distillation pipelines, providing rich, globally contextualized feature representations for a student to learn.
Data-efficient Image Transformer (DeiT)
A training recipe and architecture variant that enables Vision Transformers to be trained effectively on mid-sized datasets like ImageNet-1k using a distillation token. This token is a learned embedding that interacts with the teacher's output during training, making DeiT a canonical example of a student architecture designed from the ground up to leverage knowledge distillation.
Self-Supervised Learning (DINO)
A self-supervised learning framework that trains a Vision Transformer via self-distillation without labels. A student network learns to match the output of a momentum-updated teacher network. DINO demonstrates that the teacher-student dynamic central to knowledge distillation can emerge organically without external supervision, producing explicit semantic segmentation in attention maps.
Masked Autoencoder (MAE)
A self-supervised pre-training method that masks a high proportion of random image patches and trains a Vision Transformer to reconstruct the missing pixels. The resulting encoder learns rich visual representations from unlabeled data and serves as an excellent initial teacher or a pre-trained weight source for a student model before task-specific distillation.
Token Merging (ToMe)
A training-free acceleration technique that reduces the number of tokens in a Vision Transformer by gradually merging similar redundant tokens together. This is a complementary post-hoc compression strategy to knowledge distillation, often used in conjunction with a distilled student to further reduce computational cost with minimal accuracy loss.
Low-Rank Adaptation (LoRA)
A parameter-efficient fine-tuning method that freezes pre-trained model weights and injects trainable rank decomposition matrices into Transformer layers. While not distillation itself, LoRA is often used to efficiently adapt a large, frozen teacher model to a specialized medical domain before its softened logits are used to train a smaller student.

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