Logits distillation is a form of knowledge distillation where the student model is trained to match the logits—the raw, unnormalized scores produced by the final layer before the softmax activation—of a pre-trained teacher model. The primary objective is to transfer the teacher's learned representation, including nuanced inter-class relationships often called dark knowledge, by minimizing a loss function like Kullback-Leibler divergence between the softened logit distributions. This direct logit matching provides a rich supervisory signal beyond simple one-hot labels.
Glossary
Logits Distillation

What is Logits Distillation?
Logits distillation is a core technique in model compression where a smaller student model is trained to directly mimic the raw, pre-activation outputs of a larger teacher model.
This method is foundational within the teacher-student framework and is often enhanced by temperature scaling, which softens the probability distributions to make the dark knowledge more accessible. Unlike feature distillation or attention transfer, which match intermediate activations, logits distillation operates on the model's final pre-softmax outputs. It is a critical component for creating efficient models like DistilBERT and TinyBERT, enabling deployment in on-device and edge AI scenarios where computational resources are constrained.
Key Characteristics of Logits Distillation
Logits distillation is a fundamental model compression technique where a student model learns by directly matching the raw, pre-softmax output logits of a teacher model. This approach transfers the teacher's 'dark knowledge'—its nuanced understanding of inter-class relationships.
Direct Logit Matching
The core mechanism of logits distillation is the direct regression of the student's logits to the teacher's logits. Unlike methods using softened probabilities, this uses the raw, unbounded outputs from the final linear layer before the softmax activation.
- Objective: Minimize a distance metric (e.g., Mean Squared Error) between teacher and student logit vectors.
- Advantage: Avoids the non-linear scaling of the softmax function, providing a more stable and direct learning signal.
- Example: For a 10-class image classification task, the student is trained to produce a 10-dimensional logit vector that closely matches the teacher's corresponding vector for the same input image.
Loss Function: KL Divergence with Temperature
While direct logit matching is possible, the most common implementation applies temperature scaling to the logits before calculating the Kullback-Leibler (KL) Divergence loss.
- Process: A temperature parameter
T > 1is used in the softmax function (softmax(logits / T)), creating a softer probability distribution that amplifies the teacher's 'dark knowledge'. - Loss Component: The student's softened probabilities are penalized for diverging from the teacher's softened probabilities via KL Divergence.
- Combined Loss: This distillation loss is typically combined with a standard cross-entropy loss using hard labels:
Loss = α * CrossEntropy(student, hard_label) + β * KL_Divergence(soft_student, soft_teacher).
Transfer of Dark Knowledge
The primary value of logits distillation is the transfer of dark knowledge—the implicit, relative similarities between different classes that the teacher model has learned.
- Mechanism: A hard label for a 'cat' image only tells the student it's a cat. The teacher's softened logits might also show a high score for 'lynx' and a moderate score for 'dog', teaching the student about visual and semantic relationships within the data manifold.
- Result: The student learns a more nuanced and generalizable representation than it would from hard labels alone, often leading to better calibration and robustness on ambiguous or out-of-distribution samples.
Architectural Agnosticism
Logits distillation is architecture-agnostic; the teacher and student models can have completely different neural network structures.
- Flexibility: A large Transformer-based teacher (e.g., BERT) can distill knowledge into a small CNN-based student, provided their final output layers produce logits for the same set of classes.
- Decoupling: The compression (achieved via a smaller student architecture) is decoupled from the knowledge transfer mechanism (matching logits). This makes it a versatile tool that can be combined with other compression techniques like pruning or quantization.
- Use Case: Enables the creation of highly efficient, specialized student models (e.g., for mobile CPUs) from large, general-purpose teacher models trained on cloud GPUs.
Foundation for Advanced Techniques
Logits distillation serves as the conceptual and practical foundation for many more sophisticated distillation variants.
- Evolution: Techniques like feature distillation and attention transfer extend the principle by matching intermediate representations instead of just final outputs.
- Hybrid Methods: Logits matching is often used in conjunction with these other losses in a multi-objective setup for more comprehensive knowledge transfer.
- Influential Models: Landmark compressed models like DistilBERT and TinyBERT use logits-based distillation as a core component of their training pipelines to achieve high performance with significantly reduced parameters.
Practical Implementation & Trade-offs
Implementing logits distillation involves key engineering decisions that balance performance, speed, and complexity.
- Inference Overhead: Requires running the teacher model in forward-pass mode during student training, adding computational cost to the training phase (but not to final deployment).
- Hyperparameter Tuning: The temperature
Tand loss weighting factors (α,β) are critical hyperparameters that require tuning for optimal results. - Data Efficiency: Can improve student performance when the original training data is limited, as the teacher provides an additional, rich supervisory signal.
- Typical Result: A distilled student model can often match 90-95% of the teacher's accuracy while being 2x to 10x smaller and faster.
Logits Distillation vs. Other Distillation Methods
A feature comparison of logits distillation against other primary knowledge distillation techniques, highlighting the core mechanisms, data requirements, and typical use cases for each approach.
| Feature / Characteristic | Logits Distillation | Feature Distillation | Online & Self-Distillation | Relational & Contrastive Distillation |
|---|---|---|---|---|
Primary Knowledge Transferred | Pre-softmax output logits (or softened probabilities) | Intermediate layer activations or feature maps | Knowledge from a co-trained or identical model | Inter-sample relationships or representation space structure |
Core Loss Function | Kullback-Leibler Divergence (KL) or Mean Squared Error (MSE) | Mean Squared Error (MSE), L1, or perceptual losses | KL Divergence, often combined with task loss | Contrastive loss (e.g., InfoNCE) or relational distance metrics |
Requires Layer Alignment | Varies (often false for self-distillation) | |||
Typical Data Requirement | Original or transfer dataset | Original or transfer dataset | Original training dataset | Datasets with relational structure (e.g., pairs, triplets) |
Primary Compression Benefit | Direct behavioral mimicry; preserves 'dark knowledge' | Improved intermediate representations; can guide deeper architectures | Efficient training from scratch; iterative model improvement | Superior representation learning; enhanced feature discrimination |
Common Application Scope | General-purpose compression of classification models | Computer vision (e.g., CNNs, ViTs), guiding thin/deep students | Training efficient models from scratch (e.g., DeiT), born-again networks | Metric learning, cross-modal tasks, representation refinement |
Computational Overhead | Low (only final layer outputs) | Medium to High (requires forward pass through teacher's intermediate layers) | Low to Medium (co-training overhead) | High (requires pairwise or set-based comparisons) |
Key Representative Technique | Original Hinton et al. distillation | Attention Transfer, Hint Learning (FitNets) | Online Distillation, Born-Again Networks | Relational KD, Contrastive Representation Distillation |
Examples and Applications
Logits distillation is a foundational technique for creating compact, efficient models. Its applications span from deploying models on mobile phones to creating specialized, high-performance architectures for specific domains.
Mobile & Edge AI Deployment
Logits distillation is a cornerstone for deploying large language and vision models on resource-constrained devices.
- Mobile NLP: Models like DistilBERT and TinyBERT use logits distillation to shrink BERT for on-device text understanding, enabling features like smart replies and local translation.
- Computer Vision: The DeiT (Data-efficient Image Transformer) architecture uses a distillation token trained against a CNN teacher's logits, achieving high accuracy without massive datasets, ideal for mobile cameras and AR applications.
- Key Benefit: Reduces model size and latency, enabling privacy-preserving local inference without cloud dependency.
Creating Specialized Student Architectures
Logits distillation enables the transfer of knowledge into student models with fundamentally different, more efficient architectures than their teachers.
- CNN to Transformer: A convolutional neural network (CNN) teacher can distill its knowledge into a more parameter-efficient vision transformer (ViT) student via logits matching.
- Dense to Sparse: A large, dense teacher model can train a student with a pruned or sparse architecture from the outset using distillation loss, combining compression techniques.
- Cross-Modal Transfer: Logits can act as an intermediary for cross-modal distillation, e.g., transferring knowledge from an image model to a text-based model for unified representation learning.
Joint Optimization with Other Compression Techniques
Logits distillation is rarely used in isolation; it is frequently combined with other compression methods in a unified training pipeline.
- Quantization-Aware Distillation (QAT): The student is trained with distillation loss while simulating low-precision (INT8) arithmetic, resulting in a model robust to the accuracy drop from quantization.
- Pruning-Aware Distillation: The student model is trained to match the teacher's logits while having its weights actively pruned, learning to perform well with a sparse connectivity pattern.
- Hardware-Aware Co-Design: Distillation objectives can be tailored to optimize for specific hardware metrics (e.g., latency, SRAM usage) of a target Neural Processing Unit (NPU).
Foundation Model Compression for Efficiency
A primary industrial application is creating cost-effective, faster versions of massive foundation models (LLMs, VLMs) for scalable API serving and research.
- API Cost & Latency Reduction: Distilled models like DistilBERT serve as drop-in replacements for full BERT in production pipelines, drastically reducing inference costs and improving throughput.
- Research & Iteration: Smaller, distilled models allow researchers to experiment with architectures and training techniques at a fraction of the computational cost of the full teacher model.
- Specialized Task Models: A general-purpose teacher LLM can be distilled into a suite of smaller, task-specific student models (e.g., for sentiment analysis, named entity recognition), each optimized for a single job.
The Distillation Loss Function in Practice
The core mechanism of logits distillation is the distillation loss, which combines the standard task loss with a measure of divergence from the teacher.
- Standard Formulation: Total Loss = α * Task Loss (Student vs. True Labels) + β * Distillation Loss (Student vs. Teacher Logits).
- Kullback-Leibler Divergence (KL Divergence): The most common distillation loss. It measures how the student's softened probability distribution diverges from the teacher's.
- Temperature Scaling (T): A critical hyperparameter applied to the softmax of both teacher and student logits. A T > 1 (e.g., 3-10) produces a softer probability distribution, revealing the dark knowledge of inter-class relationships crucial for effective transfer.
Overcoming Data & Privacy Constraints
Logits distillation enables model compression in scenarios where the original training data is unavailable or sensitive.
- Data-Free Distillation: Techniques exist to generate synthetic data or use the teacher model itself to create inputs, allowing distillation without the original dataset. The student learns solely from the teacher's output logits on this generated data.
- Federated Knowledge Distillation: In privacy-sensitive domains like healthcare, local models on different devices/servers can be distilled into a central student model by sharing only their output logits (or softened predictions) on a public anchor dataset, never the raw private data.
- Legacy Model Modernization: Knowledge can be extracted from an old, cumbersome model (where training data may be lost) into a modern, efficient architecture.
Frequently Asked Questions
Logits distillation is a core technique in knowledge distillation for creating compact, efficient models. These questions address its fundamental mechanics, applications, and distinctions from other methods.
Logits distillation is a form of knowledge distillation where a smaller student model is trained to directly match the raw, pre-softmax output logits of a larger, pre-trained teacher model. It works by using a specialized distillation loss, typically the Kullback-Leibler (KL) Divergence, to minimize the difference between the teacher's and student's logit distributions, often softened by temperature scaling.
Key Mechanism:
- A trained teacher model generates logits (z) for a batch of training data.
- A temperature parameter (T > 1) is applied to the softmax function, creating a softer probability distribution that reveals dark knowledge—the teacher's understanding of inter-class similarities.
- The student model's logits are passed through the same softened softmax.
- The KL divergence between the two softened distributions is computed as the distillation loss.
- This loss is combined with a standard cross-entropy loss using the true labels (hard targets) and weighted by a factor α. The total loss is:
L_total = α * L_KL(soft_targets_teacher || soft_targets_student) + (1-α) * L_CE(hard_labels, student_predictions).
By learning from these softened targets, the student acquires a richer, more generalized representation than it would from hard labels alone, often leading to better generalization and calibration.
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
Logits distillation is a core technique within the broader field of knowledge distillation. These related terms define the specific methods, components, and frameworks that enable the transfer of knowledge from a teacher to a student model.
Knowledge Distillation
Knowledge distillation is the overarching model compression technique where a smaller, more efficient student model is trained to mimic the behavior and outputs of a larger, more powerful teacher model. Logits distillation is one of its primary forms.
- Core Objective: Transfer the teacher's learned representation to a compact student.
- Key Benefit: Enables deployment of high-performance models on resource-constrained devices.
Teacher-Student Framework
The teacher-student framework is the foundational architecture for knowledge distillation. It consists of a pre-trained, often cumbersome teacher model whose knowledge is transferred to a trainable, lightweight student model.
- Teacher: A high-capacity, accurate model (e.g., BERT-large, ResNet-152).
- Student: A smaller, more efficient architecture (e.g., DistilBERT, MobileNet).
- Process: The student learns by minimizing a loss function that incorporates the teacher's outputs.
Soft Targets
Soft targets are the probability distributions output by a teacher model's final softmax layer. Unlike hard targets (one-hot encoded labels), they contain richer, inter-class similarity information known as dark knowledge.
- Example: For an image of a cat, a teacher might output [cat: 0.7, lynx: 0.25, dog: 0.05].
- Purpose: This probabilistic "softening" provides a more informative training signal for the student than a simple correct/incorrect label.
Temperature Scaling
Temperature scaling is a technique used to control the "softness" of the teacher's output distribution. A temperature parameter (T) is applied to the logits before the softmax function.
- Mechanism:
softmax(logits / T). Higher T (>1) produces a softer, more uniform probability distribution. - Effect: Smoothes the probability landscape, making it easier for the student to learn the relative similarities between classes that the teacher has discovered.
Kullback-Leibler Divergence (KL Divergence)
Kullback-Leibler divergence is a statistical measure of how one probability distribution diverges from a second, reference distribution. It is the most common distillation loss function for logit-based methods.
- Role in Distillation: Minimizes the difference between the student's softened output distribution and the teacher's softened output distribution.
- Formula: The distillation loss is often
KL(teacher_soft_targets || student_soft_predictions). It is typically combined with a standard cross-entropy loss with true labels.
Dark Knowledge
Dark knowledge refers to the implicit, inter-class relationships and similarities captured within a trained neural network's softened output probabilities. This information is not present in the original hard training labels but is transferred to the student during distillation.
- Origin: A model learns that certain incorrect classes are "less wrong" than others (e.g., a 'lynx' is more similar to a 'cat' than a 'truck').
- Value: This relational knowledge is what allows a distilled student model to often generalize better than one trained on hard labels alone.

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