- Also called:
- model distillation
- Related Topics:
- large language model
- neural network
- machine learning
knowledge distillation
What is knowledge distillation in machine learning?
Why is knowledge distillation important in the context of large language models?
How does a neural network learn?
What are the three categories of knowledge in neural networks?
What are the three methods of knowledge distillation?
knowledge distillation (KD), process in machine learning and deep learning for replicating the performance of a large model or set of models on a smaller model. The process is especially useful in the context of transferring learning techniques to smaller, more efficient models from large language models (LLMs), such as ChatGPT and Google Gemini.
Background
Knowledge distillation (KD) techniques are used to improve complex neural network models, which may have multiple layers and learnable parameters. Such models have been used since the early 2010s across a range of applications, including image recognition, natural language processing (NLP), and speech recognition. KD gained increased attention for its importance in the development of LLMs, which entered widespread public use in the early 2020s.
The sheer size and complexity of an LLM complicates its use. Compared with a smaller model, an LLM needs more computational resources to run, has greater inference times, and is harder to manage. Indeed, the money, time, memory, and other assets that an LLM requires make its use impractical in many applications. Training a smaller, specialist model to match the abilities of a generalist LLM effectively solves such issues.
Initial steps
A neural network conventionally âlearnsâ by using a loss function, which produces a vector that represents the divergence (loss) between a modelâs outputs and the correct outputs across various inputs. Correct outputs are typically referred to as âground truth.â The model is trained by adjusting its parameters, or the weights or biases that are applied to its mathematical operations, to minimize the gradient (or change over time) of this vector, thereby bringing the modelâs outputs closer to the ground truth. A networkâs learned parameters are thought of as its âknowledge.â KD is different: âknowledgeâ is redefined as the steps by which a network reasons its way from its input vectors to its output vectorsâi.e., as how the network generalizes to new data.
KD transfers these reasoning steps from larger (âteacherâ) models to smaller (âstudentâ) models by introducing a new function that measures distillation loss. To understand distillation loss, consider the following. A neural networkâs outputs may be understood as predictions. For instance, an image classification model will predict the category of a specified image, such as that of a horse. The modelâs final predictionâits answer to the question it has been posedâis called a âhard target.â Prior to arriving at its final prediction, the model will make multiple preliminary predictions, assigning to each a probability of being correct. These intermediate predictions from which the final prediction is chosen are sometimes called âsoft targetsâ but are more commonly called âlogits.â
Perhaps counterintuitively, how the model arrives at its logits is more-valuable information than how the model decides between logits when choosing its hard target. This is because the former process provides a great deal more insight into how the teacher model generalizes. For example, an image classification model is more likely to incorrectly categorize a horse as a cow than as a building. A student model can train on fewer examples of how its teacher model reaches logits than examples of how it reaches hard targets.
Measuring ability to generalize
A student model measures its ability to generalize in comparison with the teacher model via two functions. The first function operates on âhard loss,â or the divergence between the student modelâs hard target and the ground truth. The second function operates on aforementioned distillation loss, also known as âsoft lossâ because it measures the divergence in logits between the student model and the teacher model. Specifically, it measures the difference between the probability distribution of the student modelâs logits and that of its teacherâs logits.
Although logits are the primary focus of knowledge transfer between teacher and student models, there are other forms of knowledge that require consideration. All forms of knowledge in neural networks can generally be placed in one of three categories: response-based knowledge, feature-based knowledge, or relation-based knowledge. Logits constitute response-based knowledge, since those generated by teacher and student models are compared for training purposes. Feature-based knowledge relates to a modelâs discrimination of features at each reasoning step (or layer) of its logit generation. One might describe logit-based knowledge as concerned with the âwhatâ and feature-based knowledge as concerned with the âhow.â Finally, relation-based knowledge involves the relationships or correlations between the modelâs layers and feature activations. This can describe how the student copies the teacherâs âthought process.â
Methods of knowledge distillation
KD can also be classified according to the method of teaching a student model. There are three distinct KD methods: offline distillation, online distillation, and self-distillation. Each method differs from the others on the basis of whether the teacher model is modified at the same time as the student model. The most common KD technique is offline distillation, wherein the teacher model is pretrained on a dataset and then has its knowledge distilled into the student model.
Less common is online distillation, which simultaneously trains both the teacher and the student models via a single end-to-end training process. Finally, self-distillation involves one model acting as both teacher and student. The model essentially trains its âshallowâ layers (those that are closer to the input layer and hence learn only basic features) with its âdeeperâ layers (those that are closer to the output layer and hence deal with representations that are more complex and abstract).

" height="20" alt="HEW Logo">
