Skip to content

Training, adaptation, compression, and systems techniques · Training, fine-tuning, adaptation, compression, and systems techniques · TRN015 · Training method

Knowledge distillation

Trains a student to reproduce information from a teacher’s predictions or intermediate representations, often with a supervised task loss.

Runs in CodeSplash Component demo, not a trained model CodeSplash's run and the reference's record

In CodeSplash

A CodeSplash method runs this entry in Python and R. Set it up from the method's page.

Do it in CodeSplash Run it on your own data, in Python or R.

Availability
Runs in CodeSplash
Code example
Component demo, not a trained model
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
Verified in Python and R through learn.cnn, learn.deep_ensemble, learn.ft_transformer, learn.tabm, learn.torch_mlp. The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Trains a student to reproduce information from a teacher’s predictions or intermediate representations, often with a supervised task loss.

Question / hypotheses

Does this intervention improve the intended quality, adaptation, resource, or reliability objective under a controlled comparison? It defines a method, not an intrinsic null-hypothesis test.

Architecture / computational structure

A frozen or separately trained teacher produces targets; the student may have a smaller or different architecture.

Assumptions

Teacher competence, target-domain coverage, aligned output spaces, and data rights/availability matter. Soft targets can carry teacher errors as well as useful similarities.

Formula / computational definition

L=αLhard+(1−α)T2DKL(softmax(zt/T)∥softmax(zs/T)).L=\alpha L_{hard}+(1-\alpha)T^2D_{KL}(softmax(z_t/T)\|softmax(z_s/T)).

Parameters and notation

Learned: student weights; teacher usually fixed. Hyperparameters: temperature T, loss weight alpha, transfer dataset, feature layers, projection heads, student capacity.

Fitting, fine-tuning, and adaptation

Initialize the student deliberately, freeze the teacher, and optimize only intended modules. For domain adaptation, mix target-domain data with representative retention data when appropriate.

How to use and calibrate

Compare student versus teacher on task quality, calibration, latency, memory, and subgroup behavior. Example: compress a speech encoder for local inference.

Example application

compress a speech encoder for local inference.

Interpretation / pitfalls

Watch out

Distillation is not guaranteed to remove harmful biases or reproduce capabilities outside the transfer data. Matching logits with different vocabularies needs an explicit mapping.

Python and R code examples

Scope: numerical mechanism demonstration. Validation: Python executed successfully on the supplied synthetic inputs; R reviewed but not executed (Rscript unavailable).

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — numerical mechanism demonstration. · needs numpy

import numpy as np
# Supplied teacher p and student q have already been softened at T=2.
p=np.array([.7,.2,.1]); q=np.array([.6,.25,.15]); T=2.
print(T*T*np.sum(p*np.log(p/q)))
R

Component demo, not a trained model — numerical mechanism demonstration.

# Supplied p and q are already temperature-softened distributions at T=2.
p <- c(.7,.2,.1); q <- c(.6,.25,.15); T <- 2
print(T*T*sum(p*log(p/q)))

Sources

From the CodeSplash reference, entry TRN015.