Prepare teacher and data
Train or obtain a high-capacity teacher model on your real labelled dataset and prepare a held-out calibration set for distillation targets.
Perform knowledge distillation. Compare student and teacher.
Knowledge distillation trains a compact student model to mimic a larger teacher model, typically using teacher soft-labels or intermediate representations. Important failure modes include mismatch between teacher and student capacity, overfitting to soft labels, calibration errors, and degraded performance on out-of-distribution samples.
Learning concept · Not a validated service
Knowledge distillation trains a compact student model to mimic a larger teacher model, typically using teacher soft-labels or intermediate representations. Important failure modes include mismatch between teacher and student capacity, overfitting to soft labels, calibration errors, and degraded performance on out-of-distribution samples.
A proposed application is compressing a high-accuracy model for low-latency inference on edge devices, trading some accuracy for reduced memory, compute and latency. Any deployment should keep a human-in-the-loop for validation during rollout.
Train or obtain a high-capacity teacher model on your real labelled dataset and prepare a held-out calibration set for distillation targets.
Design a smaller student network suitable for target hardware and initialise training with the original labels and teacher soft labels (temperature-scaled logits).
Train with a weighted loss combining hard labels and teacher soft labels; evaluate top-k accuracy, calibration and latency on representative inputs.
Export the student to an inference format (ONNX/TorchScript), measure real-device latency and add monitoring for drift and performance regressions.
The supplied starter generates a synthetic classification dataset with sklearn.make_classification, fits a DecisionTreeClassifier, times repeated single-sample predictions, and prints latency plus tree statistics. It does not implement knowledge distillation, contains no teacher/student training, and uses synthetic data rather than a real model/dataset.
X, y = make_classification(n_samples=1000, n_features=12, n_informative=8, random_state=42)
model = DecisionTreeClassifier(max_depth=6, random_state=42)
model.fit(X, y)
sample = X[:1]
start = time.perf_counter()
for _ in range(1000):
model.predict(sample)
latency_ms = (time.perf_counter() - start) * 1000 / 1000The code uses a single DecisionTreeClassifier trained on synthetic sklearn data and measures prediction latency; it does not create a teacher model, does not train a student model using teacher soft labels or intermediate representations, and contains no distillation loss or real dataset.
Proposed extension: use a pretrained high-capacity vision teacher (ResNet or ViT) and distil a compact student (MobileNet or small ResNet) on a labelled image subset, using temperature-scaled soft targets and a combination of cross-entropy and KL-loss.
This is a potential application pathway, not a delivered product. The supplied starter does not implement this service or validate it with real users.
Networkers Home runs this topic inside its AI Engineer Course, with placement support and hands-on labs.