Knowledge distillation transfers dark knowledge from a cumbersome teacher model to a lightweight student by minimizing the divergence between their softened output probabilities. The teacher's logits are divided by a temperature parameter to expose the relative similarities between incorrect classes, providing richer supervisory signals than hard labels alone for the student to learn.
Glossary
Knowledge Distillation

What is Knowledge Distillation?
Knowledge distillation is a model compression technique where a compact 'student' model is trained to replicate the behavior and output distribution of a larger, high-capacity 'teacher' model, effectively transferring complex learned representations to a more efficient architecture.
In medical imaging, this technique is critical for deploying state-of-the-art diagnostic models on edge hardware. A student model can mimic the diagnostic accuracy of a large ensemble of Vision Transformers while meeting the latency and memory constraints of point-of-care ultrasound devices, preserving clinical precision without the computational burden of the original teacher.
Key Features of Knowledge Distillation
Knowledge distillation transfers the dark knowledge from a large, cumbersome teacher model to a compact, efficient student model. In medical imaging, this enables high-accuracy diagnostic models to run on edge devices and point-of-care hardware.
Teacher-Student Architecture
The core mechanism involves a two-model setup. A large, pre-trained teacher network (e.g., a Vision Transformer or deep CNN ensemble) generates soft probability distributions over classes. A smaller student network is trained not just on ground-truth hard labels, but to mimic the teacher's soft targets—the relative probabilities assigned to incorrect classes. These soft targets encode rich inter-class similarity structures (e.g., a chest X-ray with pneumonia shares visual features with one showing bronchitis) that hard labels discard. The student minimizes a combined loss: the standard cross-entropy with ground truth plus a Kullback-Leibler (KL) divergence loss between its softened outputs and the teacher's softened outputs, controlled by a temperature parameter T.
Temperature Softening
A critical hyperparameter in distillation is the temperature (T) applied to the softmax function. When T=1, the output is the standard probability distribution. When T>1, the distribution is softened, revealing the teacher's dark knowledge—the subtle, non-zero probabilities assigned to incorrect classes. For example, a teacher classifying a skin lesion as melanoma might assign a probability of 0.001 to basal cell carcinoma at T=1, but 0.15 at T=10. This reveals that the teacher considers these classes visually related. The student learns these richer relationships, achieving better generalization than training on hard labels alone. The same temperature is used during student training, but T is reset to 1 at inference.
Distillation Loss Functions
The student model is optimized using a composite loss function:
- Distillation Loss: The KL divergence between the teacher's softened outputs and the student's softened outputs, scaled by T² to maintain gradient magnitudes.
- Student Loss: Standard cross-entropy loss between the student's hard predictions (T=1) and the ground-truth labels.
- Weighted Combination: A hyperparameter α balances the two losses:
L_total = α * L_distillation + (1-α) * L_student.
In medical imaging, where ground-truth labels are scarce and expensive, a higher α (e.g., 0.9) places more trust in the teacher's rich representations. This is particularly effective when distilling from a model pre-trained on large-scale radiology datasets to a student for a niche task with limited annotations.
Feature-Based Distillation
Beyond matching output probabilities, feature-based distillation transfers knowledge from the teacher's intermediate representations. The student is trained to minimize the distance between its feature maps and the teacher's feature maps at corresponding layers. Common approaches include:
- Attention Transfer: Matching spatial attention maps between teacher and student layers.
- Hint-Based Learning: Using the teacher's middle-layer activations as hints to guide the student's earlier layers.
- Relational Knowledge Distillation: Preserving the pairwise relationships between samples in the teacher's embedding space.
In medical image segmentation, feature-based distillation ensures the student learns to activate on the same anatomical structures and lesion boundaries as the teacher, preserving spatial precision critical for diagnostic accuracy.
Self-Distillation for Medical Imaging
Self-distillation eliminates the need for a separate teacher model by using the same architecture as both teacher and student. The model is trained iteratively: a model trained in one generation serves as the teacher for the next generation of identical architecture. Alternatively, in-place self-distillation uses the model's own predictions from earlier epochs as soft targets for later epochs. This technique is valuable in medical imaging when:
- A larger pre-trained teacher is unavailable for the specific modality.
- The target architecture is constrained by edge deployment requirements.
- Privacy regulations prevent accessing external teacher models trained on multi-institutional data.
Self-distillation has been shown to improve robustness to noisy labels in chest X-ray classification and enhance segmentation consistency across different MRI scanners.
Online vs. Offline Distillation
Distillation strategies differ in training dynamics:
- Offline Distillation: A pre-trained, frozen teacher model generates soft targets once, and the student trains on these static targets. This is the standard approach and works well when a high-quality teacher already exists, such as a model pre-trained on the CheXpert or MIMIC-CXR datasets.
- Online Distillation: The teacher and student are trained simultaneously, with the teacher's parameters updated alongside the student's. This is useful when no pre-trained teacher exists for a novel medical imaging modality.
- Co-Distillation: Multiple peer models train together, each learning from the ensemble's collective soft targets. This is effective for training a fleet of modality-specific diagnostic models that share knowledge across CT, MRI, and X-ray domains.
Frequently Asked Questions
Clear answers to common questions about compressing large teacher models into efficient student models for medical imaging deployment.
Knowledge distillation is a model compression technique where a compact 'student' model is trained to replicate the behavior of a larger, pre-trained 'teacher' model. Instead of training the student solely on hard labels from a dataset, it learns from the teacher's soft labels—the probability distribution over classes output by the teacher's final softmax layer. These soft labels contain rich dark knowledge about inter-class similarities that hard labels discard. The student minimizes a combined loss: the standard cross-entropy loss with ground-truth labels and a Kullback-Leibler (KL) divergence loss that aligns its softened output distribution with the teacher's. A temperature parameter T in the softmax function controls the softness of the probability distribution, with higher T revealing more subtle relationships between classes. This process transfers the teacher's generalization capabilities to a model that may be 10-50x smaller, enabling deployment on resource-constrained edge devices in clinical settings.
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
Core concepts that interact with and complement knowledge distillation in the model compression and transfer learning landscape.
Teacher-Student Architecture
The foundational framework where a large, high-capacity teacher model generates soft targets for a compact student model to mimic. The student learns not just the correct class, but the full probability distribution over all classes, capturing dark knowledge about inter-class similarities. Key design choices include:
- Teacher and student can share the same architecture or differ completely
- The teacher is typically 5-10x larger than the student
- Intermediate layer distillation aligns hidden representations
Temperature Scaling
A hyperparameter T applied to the softmax function that controls the softness of the teacher's output distribution. Higher temperatures produce softer probability distributions that reveal more information about the teacher's learned similarities between classes. The same temperature is applied to both teacher and student during training, but set to T=1 during inference. Typical values range from 2 to 20, with higher values useful when the teacher is highly confident.
Distillation Loss
The composite objective function combining two components:
- Soft loss: Kullback-Leibler divergence between the temperature-scaled outputs of teacher and student, weighted by λ
- Hard loss: Standard cross-entropy between student predictions and ground-truth labels, weighted by (1-λ) The soft loss transfers dark knowledge, while the hard loss anchors the student to the true labels. The balance parameter λ is typically set between 0.5 and 0.9.
Feature-Based Distillation
An extension beyond output-level distillation where the student learns to match the teacher's intermediate feature representations. This transfers structural knowledge about hierarchical feature extraction. Common approaches include:
- Attention transfer: Matching spatial attention maps between corresponding layers
- Hint-based learning: Using a regressor to align student and teacher feature dimensions
- Relational distillation: Preserving pairwise relationships between samples in the feature space Particularly effective when teacher and student have different architectures.
Self-Distillation
A variant where the teacher and student share the same architecture, and the student is trained using predictions from a previously trained version of itself. This can be done iteratively across generations or simultaneously using multi-exit architectures. Benefits include:
- No need for a separate large teacher model
- Each generation can outperform the previous one
- Acts as a regularization technique that improves generalization Commonly used in Vision Transformers and large language models.
Online Distillation
A training paradigm where teacher and student are trained simultaneously rather than sequentially. The teacher is not a pre-trained static model but co-evolves with the student. Architectures include:
- Deep mutual learning: Multiple peer networks learn collaboratively
- Co-distillation: Networks train in parallel and exchange knowledge
- Ensemble distillation: An ensemble of peers serves as a dynamic teacher Eliminates the two-stage pipeline and reduces total training time.

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