You get a bonus - 1 coin for daily activity. Now you have 1 coin

Model and Dataset Distillation

Lecture



In machine learning, knowledge distillation or model distillation — is the process of transferring knowledge from a large model to a smaller one. While large models (such as very deep neural networks or ensembles of many models) have greater knowledge capacity than small models, this capacity may not be fully utilized. Evaluating a model can be just as computationally expensive even if it uses only a small fraction of its knowledge capacity. Knowledge distillation transfers knowledge from a large model to a smaller one without loss of validity . Because smaller models are less costly to evaluate, they can be deployed on less powerful hardware (such as a mobile device ).

Model distillation should not be confused with model compression , which describes techniques for reducing the size of the large model itself without training a new model. Model compression typically preserves the architecture and the nominal number of parameters of the model while reducing the number of bits per parameter.

Knowledge extraction has been used successfully in several machine learning applications, such as object detection , acoustic models , and natural language processing . Recently it has also been introduced for building graph neural networks applicable to non-graph data.

Data distillation is needed for

  • speeding up training / testing (desirable for an entire class of models),
  • reducing the amount of data to be stored (replacing the old selection of objects),
  • answering the scientific question of how much information is contained in the data (how much we can «compress» it).

Methods

Transferring knowledge from a large model to a small one must somehow train the latter without loss of validity. If both models are trained on the same data, the smaller model may not have enough capacity to learn a compact representation of knowledge compared to the large model. However, some information about the compact representation of knowledge is encoded in the pseudo-likelihoods assigned to its outputs: when the model correctly predicts a class, it assigns a large value to the output variable corresponding to that class, and smaller values to the other output variables. The distribution of values among the outputs for a given record provides information about how the large model represents knowledge. Consequently, the goal of economically deploying a valid model can be achieved by training only the large model on the data, taking advantage of its superior ability to learn compact representations of knowledge, and then distilling that knowledge into the smaller model by training it to learn the large model's soft output.

Example

Diffusion models learn to generate data by reversing the diffusion process, i.e., the model learns to turn random noise into a coherent image (usually corresponding to a given prompt).

The problem here is the word gradually. This requires hundreds of steps, and each of them requires a large amount of computation.

Why do we do it this way? Well, we can't just jump from noise to a coherent image, that would lead to abstract, surreal results. Noise is random and does not contain an image as such (generally speaking). Gradually removing the noise allows the overall outline of the image to emerge, which can then be refined step by step, using the previous steps as a base. It's the same with people – you can't write an entire Python application in one go – you usually write the code piece by piece, and it kind of evolves.

But why do we need so many steps? Apparently, this is more a result of the initial mathematical description of the problem than anything else. It reminds me how often the formulation of a problem and the language used dictate the solution.

The idea here is that we don't do it the way described above. If you think about it, why do we need to predict every step ??. We can predict every other step, skipping a step both in training and in inference. The student no longer removes noise from a random noisy image. It removes noise from an image that has already been processed by the parent model, and the parent model is already trained and knows what it's doing (that's the benefit of teachers for you).

Thus, in the student model we will have half as many steps as in the parent model, and it turns out that the quality is almost exactly the same. We then take this student model and use it as a teacher, and create a new student model. We then train the new student using this new teacher model, and again during training try to predict only every other step, and so on. Eventually, we repeat this process many times, compressing the model and the number of steps, halving them each time. We keep doing this process until we are no longer satisfied with the results. In this way, we effectively cut the computational requirements in half with each distillation, and at this point it seems possible to have only four to six steps, with the model still performing just as well as the initial teacher model with hundreds of steps. This is called the distillation process.

Here is a diagram:

Model and Dataset Distillation

Distillation process

Visualization of two iterations of the progressive distillation algorithm. The sampler f(z; η), which maps random noise ε into samples x in 4 deterministic steps, is distilled into a new sampler f(z; θ), performing only one step.

1. Model Distillation

This method makes it possible to train a compact model (student) based on a more complex and powerful model (teacher).

Key principles:

  • Teacher Model — a large, pre-trained model with high accuracy.
  • Student Model — a smaller model trained using the outputs of the teacher model.
  • Soft Labels — instead of ordinary labels (hard labels), the student model is trained on the probabilistic outputs of the teacher model, which makes it possible to better capture hidden patterns.
  • Temperature Scaling — used in the softmax function to make the probability distribution of the outputs more informative.

Applications:

  • Reducing model size for mobile and embedded devices.
  • Reducing computational costs during deployment.
  • Speeding up inference.

Example:
In computer vision, MobileNet can be trained using ResNet as the teacher model to achieve a good balance between quality and speed.

2. Data Distillation

This method aims to reduce the amount of training data without loss of model quality.

Main techniques:

  • Data Selection — selecting the most significant data for training.
  • Data Augmentation Distillation — using augmentations to generate new useful examples.
  • Synthetic Data Distillation — creating synthetic data that preserves the informativeness of the original dataset.

Applications:

  • Speeding up model training.
  • Reducing memory consumption.
  • Improving model quality with a limited amount of data.

Example:
In NLP, a small sample of texts can be generalized through GPT-based synthesized examples, preserving key semantic properties.

Mathematical formulation

Given a large model as a function of a vector variable Model and Dataset Distillation, trained for a particular classification task, typically the last layer of the network is a softmax of the form

Model and Dataset Distillation

where Model and Dataset Distillation is the temperature , a parameter that for standard softmax equals 1. The softmax operator converts the logit values Model and Dataset Distillationinto pseudo-probabilities: higher temperature values generate softer distributions of pseudo-probabilities among the output classes. Knowledge distillation consists of training a smaller network, called the distilled model , on a dataset called the transfer set (which differs from the dataset used to train the large model), using cross-entropy as the loss function between the outputs of the distilled model Model and Dataset Distillationand the output of the large model Model and Dataset Distillationon the same record (or the average of individual outputs, if the large model is an ensemble), using a high softmax temperature valueTModel and Dataset Distillationfor both models

Model and Dataset Distillation

In this context, a high temperature increases the entropy of the outputs, thereby providing more information for training the distilled model compared with hard targets, while at the same time reducing the variance of the gradient between different records, thereby enabling a higher learning rate .

If ground-truth data is available for the transfer set, the process can be strengthened by adding to the loss the cross-entropy between the outputs of the distilled model (computed with Model and Dataset Distillation), and the known label Model and Dataset Distillation

Model and Dataset Distillation

where the loss component with respect to the large model is weighted by a coefficientT2Model and Dataset Distillationsince, as the temperature increases, the gradient of the loss with respect to the model weights increases by a factor of Model and Dataset Distillation.

Relationship to model compression

Provided that the logits have zero mean , it can be shown that model compression is a special case of knowledge distillation. The gradient of the knowledge-distillation loss Model and Dataset Distillationwith respect to the logit of the distilled model Model and Dataset Distillationis given by

Model and Dataset Distillation

wherez_iModel and Dataset Distillationare the logits of the large model. For large values ofTModel and Dataset Distillationthis can be approximated as

Model and Dataset Distillation

and under the zero-mean hypothesis Model and Dataset Distillationthis becomes Model and Dataset Distillation, which is the derivative of Model and Dataset Distillation, i.e., the loss is equivalent to matching the logarithms of the two models, as is done in model compression.

Optimal Brain Damage

The Optimal Brain Damage (OBD) algorithm is as follows:

Repeat until the desired level of sparsity or performance is achieved:

Train the network (using methods such as backpropagation) until a reasonable solution is obtained.

Compute the saliency for each parameter

Delete some of the least significant parameters

Deleting a parameter means fixing the parameter at zero. «Saliency» of a parameter Model and Dataset Distillationis defined as Model and Dataset Distillation, where Model and Dataset Distillationis the loss function.

The second derivative Model and Dataset Distillationcan be computed using the second-order backpropagation method .

The idea of Optimal Brain Damage is to approximate the loss function in the neighborhood of the optimal parameter. Model and Dataset Distillationby a Taylor expansion: Model and Dataset Distillationwhere Model and Dataset Distillation, with Model and Dataset Distillationbeing optimal, and the cross derivatives Model and Dataset Distillationare ignored to save computation.

Thus, the saliency of a parameter approximates the increase in loss if that parameter is removed.

History

A related methodology was model compression or pruning, in which a trained network was reduced in size. This was first done in 1965 by Alexey Ivakhnenko and Valentin Lapa (Ukraine) (1965). Their deep networks were trained layer by layer using regression analysis. Redundant hidden units were pruned using a separate validation set. Other methods for compressing neural networks include Biased Weight Decay and Optimal Brain Damage.

An early example of neural network distillation was published by Jürgen Schmidhuber in 1991 in the field of recurrent neural networks (RNNs). The problem was sequence prediction for long sequences, i.e., deep learning . It was solved using two RNNs. One of them ( the automatizer ) predicted the sequence, while the other ( the chunker ) predicted the automatizer's errors. At the same time, the automatizer predicted the internal states of the chunker. Once the automatizer managed to predict the chunker's internal states well, it began correcting the errors, and the chunker soon became obsolete, leaving only a single RNN in the end.

The idea of using the output of one neural network to train another neural network was also studied as a teacher-student network configuration. In 1992, several papers studied the statistical mechanics of teacher-student configurations with committee machines or both machines with parity.

The compression of the knowledge of several models into a single neural network in 2006 was called model compression : compression was achieved by training a smaller model on large amounts of pseudo-data labeled by the higher-performing ensemble, optimizing so that the logit of the compressed model matches the logit of the ensemble. In the preprint on knowledge extraction by Geoffrey Hinton et al. (2015), the concept was formulated and some results achieved on the image classification task were shown.

Knowledge distillation is also related to the concept of behavioral cloning, discussed by Faraz Torabi et al.

Conclusion

Model and data distillation — are powerful techniques for creating more compact, faster, and more efficient machine learning systems, especially relevant for mobile devices, IoT, and cloud services.

created: 2025-01-29
updated: 2026-03-09
108



Was this answer useful?
Choose a quick rating so we can improve the next answer for you.
How satisfied are you?


Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Computational Intelligence"

Terms: Computational Intelligence