wikillm

Paper · 2022-03-16 · cs.CV, cs.AI

Decoupled Knowledge Distillation

Splits the classic KD loss into a target-class term (TCKD) and a non-target-class term (NCKD), drops the teacher-confidence factor from NCKD and weights both terms separately (alpha, beta). Logit-only, so no extra cost over KD. Author-reported: ResNet32x4 to ResNet8x4 on CIFAR-100 reaches 76.32% top-1 vs 73.33% for KD.

Knowledge distillationknowledge-distillationlogit-distillationimage-classificationobject-detection

arXivPDFCodeMarkdown14 min read

AI-compiled by claude-haiku-5-5 on 2026-10-19, not yet reviewed by a human. Every claim cites its source; check it when a detail matters.

In plain words

Teaching a small model by copying a big model's answers works, and the answers that matter are the big model's scores for every possible class. The usual recipe mixes two kinds of information into one term: how sure the teacher is about the correct class, and how it ranks the wrong classes. This paper pulls them apart. Its main finding is that the wrong-class part carries most of the useful hints, and that the usual mix quietly shrinks that part whenever the teacher is confident. The fix is a new loss with a separate knob for each part.

The new loss costs about the same to compute as the classic one and adds no network pieces, unlike methods that copy the teacher's internal features. The authors report that it matches or beats those feature methods on image classification. On object detection it does not do so alone, and it works best combined with a feature method. It is a practical option for anyone who wants to distill a model cheaply and has the teacher's output scores.

TL;DR

The classic KD loss can be rewritten as a target-class term plus a non-target-class term multiplied by (1 - p_t), where p_t is the teacher's probability for the correct class §3.1 eq. 6. DKD removes that multiplier and gives each term its own weight, alpha and beta §3.3 eq. 7. It adds no parameters and costs about the same as KD §4.2. On CIFAR-100 and ImageNet it beats KD and is comparable to or better than several feature-based methods §4.1; on MS-COCO, DKD alone trails feature methods §4.1. All numbers are author-reported.

Problem

Logit distillation (matching the student's output scores to the teacher's) is cheap, but the authors note that it was generally weaker than feature distillation, which needs extra modules and memory during training §1. They argue the classic KD loss is a coupled formulation with two defects §1 §3.1:

  • Suppression: the non-target term is weighted by (1 - p_t), so a teacher that is confident on the correct class shrinks the term that carries the most useful information §3.2 §3.3.
  • No balance: the target-class and non-target-class terms share one weight, so their relative importance cannot be tuned §3.3.

The derivation omits the softmax temperature T, which the method then uses §3.1 footnote.

Method

Notation. Class probabilities come from a softmax over logits z eq. 1. Two views are used: a two-way "binary" distribution b = [p_t, p_\t] (target class vs. all others) §3.1, and the distribution over the C-1 non-target classes, renormalised without the target eq. 2.

Reformulation. Splitting the classic KL loss gives eq. 5:

\mathrm{KD} = \mathrm{KL}(\mathbf{b}^{\mathcal{T}} \| \mathbf{b}^{\mathcal{S}}) + (1 - p_t^{\mathcal{T}})\,\mathrm{KL}(\hat{\mathbf{p}}^{\mathcal{T}} \| \hat{\mathbf{p}}^{\mathcal{S}})

Writing the first term as TCKD and the second as NCKD gives eq. 6:

\mathrm{KD} = \mathrm{TCKD} + (1 - p_t^{\mathcal{T}})\,\mathrm{NCKD}

The full derivation is in app. A.1.

Findings that motivate the method §3.2:

  1. Each term on its own: TCKD alone can hurt the student, while NCKD alone is comparable to or better than full KD tab. 1.
  2. TCKD helps more on harder training data: with strong augmentation tab. 2, with label noise tab. 3, and on ImageNet tab. 4. The paper reads TCKD as carrying knowledge about how hard each sample is §3.2.
  3. Using NCKD only on the more confidently predicted half of the training set gives a higher student accuracy than using it on the other half tab. 5. The paper reads this as the suppression described above §3.2.

DKD §3.3 eq. 7. The coupled factor (1 - p_t) is replaced by a constant beta, and TCKD and NCKD get separate weights:

\mathrm{DKD} = \alpha\,\mathrm{TCKD} + \beta\,\mathrm{NCKD}

The per-sample KL terms are computed in the same way as in KD. Algorithm 1 is a PyTorch-style sketch of the same loss alg. 1. The pseudocode below follows it and the official code (see the Paper vs code section).

Pseudocode
# DKD loss for one batch  [§3.3] [eq. 7] [alg. 1]
# Input:  student_logits, teacher_logits: (B, C); target: (B,) class ids
# Output: scalar loss
# kl(p, q) = KL(p || q): p is the teacher, q is the student

def dkd_loss(student_logits, teacher_logits, target, alpha, beta, T):
    # Temperature-softened class probabilities  [alg. 1]
    p_student = softmax(student_logits / T)              # (B, C)
    p_teacher = softmax(teacher_logits / T)              # (B, C)
    # Two-way view: target class vs. all others  [§3.1] [eq. 5]
    pt_student = pick(p_student, target)                 # (B,)
    pt_teacher = pick(p_teacher, target)                 # (B,)
    binary_student = stack(pt_student, 1 - pt_student)   # (B, 2)
    binary_teacher = stack(pt_teacher, 1 - pt_teacher)   # (B, 2)
    # TCKD: per-sample KL on the two-way view  [eq. 5] [alg. 1]
    tckd = kl(binary_teacher, binary_student)            # (B,)
    # Non-target classes only, renormalised  [§3.1] [eq. 2]
    student_others = drop_target(student_logits, target) / T   # (B, C-1)
    teacher_others = drop_target(teacher_logits, target) / T   # (B, C-1)
    # NCKD: per-sample KL on non-target classes; no (1 - p_t) factor  [§3.3]
    nckd = kl(softmax(teacher_others), softmax(student_others))  # (B,)
    # Weight the two parts separately, average over the batch, then
    # scale by T^2  [alg. 1]
    loss = alpha * tckd + beta * nckd
    return mean(loss) * T ** 2

Training objective. The paper trains with cross-entropy on the labels plus the DKD term, and ramps the DKD term up linearly at the start of training app. A.2:

Pseudocode
# Training objective for CIFAR-100 runs  [app. A.2]
# Input: image, target, epoch (the trainer counts epochs from 1)

def training_loss(student, teacher, image, target, epoch):
    # Teacher is frozen; no gradients flow into it
    # [code: mdistiller/distillers/DKD.py#L66-L68]
    student_logits = student(image)
    teacher_logits = teacher(image)
    # Cross-entropy on the labels, weight 1.0  [app. A.2]
    loss_ce = cross_entropy(student_logits, target)
    # Linear ramp of the DKD term over the first 20 epochs  [app. A.2]
    # [code: mdistiller/distillers/DKD.py#L72]
    ramp = min(epoch / 20, 1.0)
    loss_dkd = ramp * dkd_loss(
        student_logits, teacher_logits, target, alpha, beta, T
    )
    return loss_ce + loss_dkd

Key values: alpha = 1.0 and T = 4 on CIFAR-100; beta depends on the teacher (see Hyperparameters). The derivation omits T §3.1 footnote, and the experiments use T = 4 on CIFAR-100 and T = 1 on ImageNet and detection app. A.2.

Hyperparameters

Values are from the paper's supplement unless marked "code". Where the paper is silent, the table says "not stated".

NameValueWhereNotes
CIFAR-100
epochs240app. A.2 res32x4_res8x4.yamlall teacher and student runs
batch size64app. A.2 res32x4_res8x4.yaml
optimiserSGD, momentum 0.9app. A.2 res32x4_res8x4.yaml
weight decay5e-4app. A.2 res32x4_res8x4.yaml
learning rate0.05 (ResNet, WRN, VGG students); 0.01 (ShuffleNet and MobileNet-V2 students)app. A.2 res32x4_res8x4.yaml res32x4_shuv1.yamlthe paper names the series, not whether the teacher or student; the code keys it on the student
LR scheduledivided by 10 at epochs 150, 180, 210app. A.2 res32x4_res8x4.yaml
CE weight1.0app. A.2 cfg.py
temperature T4app. A.2 cfg.py
alpha1.0app. A.2 cfg.py
beta2.0 (ResNet56, ResNet110); 6.0 (WRN-40-2, VGG13); 8.0 (ResNet50, ResNet32x4)app. A.3, tab. A.2 res56_res20.yaml vgg13_mv2.yaml cfg.pychosen per teacher; see Pitfalls
DKD warmuplinear ramp over 20 epochs (of the DKD term)app. A.2 cfg.pythe paper calls it a warmup; the code ramps the loss weight, not the learning rate
trials5 (average)tab. 6 tab. 7
ImageNet
epochs100app. A.2 dkd.yaml
batch size512app. A.2 dkd.yaml
learning rate0.2app. A.2 dkd.yaml
LR scheduledivided by 10 every 30 epochs (30, 60, 90)app. A.2 dkd.yaml
momentumnot statedapp. A.2 dkd.yamlthe code uses 0.9
weight decay1e-4app. A.2 dkd.yaml
CE weight1.0app. A.2 dkd.yaml
temperature T1app. A.2 dkd.yaml
alpha0.5app. A.2the code does not set it; see Paper vs code
beta0.5 (ResNet34 to ResNet18); 2.0 (ResNet50 to MobileNet-V1)app. A.2 dkd.yaml dkd.yaml
warmupnot statedapp. A.2 dkd.yamlthe code uses 1 epoch
trials3 (average)tab. 8 tab. 9
MS-COCO (Faster R-CNN with FPN)
detectorFaster R-CNN, FPN; DKD on the R-CNN head onlyapp. A.2 app. A.6 rcnn.pyteacher features are not used by DKD itself
alpha / beta / T1.0 / 0.25 / 1app. A.2 config.py
schedule"1x scheduler" (Detectron2 settings)app. A.2 DKD-R50-R101.yamlcode: batch 8, base LR 0.01, 180000 iterations, steps 120000 and 160000
teacher / student pairsResNet-101 to ResNet-18; ResNet-101 to ResNet-50; ResNet-50 to MobileNet-V2tab. 10
trials3 (average)tab. 10
Linear probing (transferability)
feature extractorWRN-16-2 distilled from WRN-40-2app. A.7
probeSGD, momentum 0.9, weight decay 0; 40 epochs; LR 0.1 at batch 128, divided by 10 every 10 epochsapp. A.7downstream: STL-10 and Tiny-ImageNet §4.2

Results

All results are author-reported. Accuracy is top-1 (%) on the validation split unless stated. Differences are as printed in the paper, or computed from the table values where marked.

CIFAR-100, same teacher and student architecture (average of 5 runs) tab. 6

Teacher (acc.)StudentStudent baselineKDDKDΔ vs KD
ResNet56 (72.34)ResNet2069.0670.6671.97+1.31
ResNet110 (74.31)ResNet3271.1473.0874.11+1.03
ResNet32x4 (79.42)ResNet8x472.5073.3376.32+2.99
WRN-40-2 (75.61)WRN-16-273.2674.9276.24+1.32
WRN-40-2 (75.61)WRN-40-171.9873.5474.81+1.27
VGG13 (74.64)VGG870.3672.9874.68+1.70

The text reports 1 to 2 points over KD for same-series pairs §4.1.

CIFAR-100, different architectures (average of 5 runs) tab. 7

Teacher (acc.)Student (baseline)KDDKDΔ vs KD
ResNet32x4 (79.42)ShuffleNet-V1 (70.50)74.0776.45+2.38
WRN-40-2 (75.61)ShuffleNet-V1 (70.50)74.8376.70+1.87
VGG13 (74.64)MobileNet-V2 (64.60)67.3769.71+2.34
ResNet50 (79.34)MobileNet-V2 (64.60)67.3570.35+3.00
ResNet32x4 (79.42)ShuffleNet-V2 (71.82)74.4577.07+2.62

The text reports 2 to 3 points over KD for different-series pairs §4.1.

Ablation of alpha and beta (ResNet32x4 teacher, ResNet8x4 student, CIFAR-100) §4.1

This table has no caption in the paper, so it is cited by section.

beta (alpha = 1.0)1.02.04.08.010.0
top-174.7975.4475.9476.3276.18

The coupled form (beta replaced by 1 - p_t, i.e. KD) gives 73.63 §4.1.

alpha (beta = 8.0)0.00.20.51.02.04.0
top-175.3075.6476.1276.3276.1175.42

The paper says TCKD's contribution is stable for alpha around 1.0 §4.1.

Reformulation ablation (CIFAR-100, weights all 1.0, see Pitfalls) tab. 1

TeacherStudentStudent baselineTCKD + NCKDTCKD onlyNCKD only
ResNet32x4ResNet8x472.5073.63 (+1.13)68.63 (-3.87)74.26 (+1.76)
ResNet32x4ShuffleNet-V170.5074.29 (+3.79)70.52 (+0.02)74.91 (+4.41)
WRN-40-2WRN-16-273.2674.96 (+1.70)70.96 (-2.30)74.76 (+1.50)
WRN-40-2ShuffleNet-V170.5074.92 (+4.42)70.62 (+0.12)75.12 (+4.62)

Deltas are over the student baseline. "TCKD + NCKD" is the classic KD form.

Harder training data (NCKD is used in all rows; the TCKD column is ticked where it is added) §3.2:

  • AutoAugment, teacher ResNet32x4 at 81.29% tab. 2: ResNet8x4 73.82 to 75.33 (+1.51) with TCKD; ShuffleNet-V1 77.13 to 77.98 (+0.85) with TCKD.
  • Symmetric label noise on the training set, teacher ResNet32x4 and student ResNet8x4 tab. 3: noise 0.1, 70.99 to 70.96 (-0.03); noise 0.2, 67.55 to 68.03 (+0.48); noise 0.3, 64.62 to 65.26 (+0.64).
  • ImageNet, teacher ResNet-34 and student ResNet-18 tab. 4: 70.71 to 71.03 (+0.32).
  • NCKD only, split by teacher confidence p_t tab. 5: all samples 74.26; the "0-50%" subset 74.23; the "50-100%" subset 73.96. The text reads "0-50%" as the top half by p_t §3.2.

CIFAR-100, teacher larger than the student (average of 5 runs) tab. 11 tab. 12

TeacherTeacher acc.KDDKD
WRN-28-275.4575.3775.92
WRN-40-275.6174.9276.24
WRN-16-477.5175.7976.00
WRN-28-478.6075.0476.45
VGG1374.6474.9375.45
WRN-16-477.5175.7976.00
ResNet5079.3475.3676.60

Students are WRN-16-2 in both tables tab. 11 tab. 12. The table caption for the second says "different series", but it includes WRN-16-4, which is a WRN.

ImageNet, ResNet-34 to ResNet-18 (average of 3 runs) tab. 8

MethodTop-1Top-5
Teacher (ResNet-34)73.3191.42
Student baseline (ResNet-18)69.7589.07
AT70.6990.01
OFD70.8189.98
CRD71.1790.13
ReviewKD71.6190.51
KD70.6689.88
KD (authors' run)71.0390.05
DKD71.7090.41

ImageNet, ResNet-50 to MobileNet-V1 (average of 3 runs) tab. 9

MethodTop-1Top-5
Teacher (ResNet-50)76.1692.86
Student baseline (MobileNet-V1)68.8788.76
AT69.5689.33
OFD71.2590.34
CRD71.3790.41
ReviewKD72.5691.00
KD68.5888.98
KD (authors' run)70.5089.80
DKD72.0591.05

Against KD: +1.04 top-1 (ResNet-34 pair) and +3.47 (ResNet-50 pair), computed from the table values.

MS-COCO, Faster R-CNN with FPN (AP on val2017, average of 3 runs) tab. 10

MethodR-101 to R-18 AP / AP50 / AP75R-101 to R-50 AP / AP50 / AP75R-50 to MV2 AP / AP50 / AP75
Teacher42.04 / 62.48 / 45.8842.04 / 62.48 / 45.8840.22 / 61.02 / 43.81
Student baseline33.26 / 53.61 / 35.2637.93 / 58.84 / 41.0529.47 / 48.87 / 30.90
KD33.97 / 54.66 / 36.6238.35 / 59.41 / 41.7130.13 / 50.28 / 31.35
FitNet34.13 / 54.16 / 36.7138.76 / 59.62 / 41.8030.20 / 49.80 / 31.69
FGFI35.44 / 55.51 / 38.1739.44 / 60.27 / 43.0431.16 / 50.68 / 32.92
ReviewKD36.75 / 56.72 / 34.0040.36 / 60.97 / 44.0833.71 / 53.15 / 36.13
DKD35.05 / 56.60 / 37.5439.25 / 60.90 / 42.7332.34 / 53.77 / 34.01
DKD + ReviewKD37.01 / 57.53 / 39.8540.65 / 61.51 / 44.4434.35 / 54.89 / 36.61

DKD alone beats KD on every pair. The paper says the best detection results come from combining DKD with a feature method §4.1.

Other reported results

  • Transferability, linear probe on features from WRN-16-2 tab. 13: STL-10 accuracy, baseline 69.7, KD 70.9, FitNet 70.3, CRD 71.6, ReviewKD 72.4, DKD 72.9. Tiny-ImageNet, baseline 33.7, KD 33.9, FitNet 33.5, CRD 35.6, ReviewKD 36.6, DKD 37.1.
  • Training cost: the paper reports DKD as having about the same complexity as KD, with no extra parameters, and a better speed/accuracy trade-off than the feature methods §4.2 fig. 2. The exact timings are only in the figure, and this card does not extract them.
  • Visualisations: t-SNE features are more separable for DKD than for KD fig. 3; the difference between student and teacher logit correlation matrices is smaller for DKD fig. 4 §4.2.

Paper vs code

Official repository: megvii-research/mdistiller (MEGVII Research), linked in the abstract and in the paper. Cloned at commit a08d46f10d6102bd6e3f258ca5ac880b020ea259, MIT licence.

Discrepancies found:

  • ImageNet alpha. The paper sets alpha = 0.5 for all ImageNet experiments app. A.2. The ImageNet DKD configs do not set alpha, so they take the library default of 1.0 dkd.yaml dkd.yaml cfg.py. Unless a run overrides it, the code does not match the paper here.
  • Warmup scope. The paper's CIFAR-100 section says a 20-epoch linear warmup is used "for all experiments" app. A.2. The code applies a 20-epoch ramp to the DKD term on CIFAR-100 cfg.py DKD.py. On ImageNet the config uses a 1-epoch ramp dkd.yaml. The detection code adds no ramp rcnn.py.

Checked and matching:

  • CIFAR-100 values match the paper: batch 64, 240 epochs, LR 0.05 or 0.01 by student, decay at 150/180/210, momentum 0.9, weight decay 5e-4, T = 4, alpha = 1.0 res32x4_res8x4.yaml res32x4_shuv1.yaml.
  • Per-teacher beta on CIFAR-100 matches app. A.3: 2.0 for ResNet56 and ResNet110 res56_res20.yaml; 6.0 for WRN-40-2 and VGG13 vgg13_mv2.yaml; 8.0 for ResNet32x4 and ResNet50 (the library default, cfg.py).
  • ImageNet beta (0.5 and 2.0), T = 1, batch 512, LR 0.2, 100 epochs and the 30/60/90 decay match app. A.2 dkd.yaml dkd.yaml.
  • Detection alpha = 1.0, beta = 0.25, T = 1 match app. A.2 [code: detection/model/config.py#L18-L20]. DKD is applied to the R-CNN head on the same sampled proposals, with teacher features from the teacher's backbone, as described in app. A.6 rcnn.py.
  • The loss matches Algorithm 1: alpha TCKD + beta NCKD, times T^2 alg. 1 DKD.py.

Implementation details the paper does not show:

  • The code computes NCKD by subtracting 1000 from the target logit (after dividing by T) before the softmax DKD.py. This is a numerical stand-in for removing the target class. It is exact only when the target logit is far below the others on the T-scaled scale, which holds in practice but is not guaranteed.
  • The code's KL uses size_average=False and divides by the batch size DKD.py. This is the batch mean of the per-sample KL, which the paper's pseudocode does not spell out.

Pitfalls

  • Warmup is a loss ramp, not an LR warmup, in code. The epoch counter starts at 1 trainer.py, so epoch 1 gives a DKD weight of 1/20 on CIFAR-100. Whether an implementer should ramp the learning rate instead is not stated.
  • Beta is per teacher and has no general rule. The paper's suggested guide is the gap z_t - z_max between the target logit and the largest non-target logit, averaged over training samples app. A.3. The fit uses a few teachers and is called a conjecture app. A.3 §5. The paper says the relation between performance and beta is "not fully investigated" §5. Beta ranges from 0.5 (ImageNet same-series) to 8.0 across the configs above.
  • TCKD alone is unreliable at T = 4. The paper finds TCKD alone can hurt, for example -3.87 on ResNet8x4 tab. 1. It attributes this to a large gradient on non-target logits at high T. With TCKD alone, T = 1 gives 73.24 on WRN-40-2 to WRN-16-2 (vs 73.26 baseline) app. A.5 tab. A.3. The TCKD-only rows are ablations, not a recommended setting.
  • Loss weights in the analysis are non-standard. The §3 experiments set all loss weights to 1.0 (CE, KD, TCKD, NCKD). The CRD default that the paper cites uses 0.1 CE and 0.9 KD app. A.4. Results in tab. 1 are not directly comparable to CRD-default KD numbers.
  • Baseline KD numbers come from elsewhere. Compared-method results are "reported in their original papers or reproduced by previous works" app. A.2. Only the ImageNet "KD (authors' run)" row is an authors' run tab. 8 tab. 9. Expect a fresh KD run to differ from the quoted KD rows.
  • Mask-based NCKD. The -1000 offset in the code is a numerical trick DKD.py. The TCKD term uses log of a softmax, not log_softmax DKD.py. A very small target probability can underflow to zero there, and the code has no epsilon guard.
  • Detection needs features. The paper finds DKD alone is clearly below ReviewKD on detection, because logits carry no localisation signal §4.1 §5. It suggests combining DKD with feature distillation §4.1.
  • Efficiency claims rely on a figure. The cost comparison fig. 2 is a plot, and the text gives no numbers. Its caption says training time is per batch fig. 2.
  • Several numbers are in the supplement. The transfer probe, the detection setup and the beta table are in the appendix, not the main text. Read app. A.2 to app. A.7 before reproducing.

Lineage

  • Builds on: classic knowledge distillation (Hinton et al.), cited as [kd] in the paper §1 §3.1. DKD keeps the same teacher-student setup and changes only the logit loss. The classic formula is not compiled in this wiki.
  • Compared against: logit methods KD (and a re-run KD on ImageNet) tab. 8 tab. 9; feature methods FitNet, RKD, CRD, OFD, ReviewKD, AT and FGFI, as listed in the result tables tab. 6 tab. 7 tab. 8 tab. 9 tab. 10 tab. 13. Related work also covers teacher-assistant and early-stopped teachers §2 §4.2.
  • Superseded by: none recorded in this wiki.

Source and license

Adapted from “Decoupled Knowledge Distillation” by Borui Zhao, Quan Cui, Renjie Song, Yiyu Qiu, Jiajun Liang (arXiv:2203.08679), used under CC BY 4.0. Changes: condensed and restructured for implementation, with tables, equations and algorithms taken from the paper and its code, each cited to its source. Not affiliated with or endorsed by the authors. Code citations refer to https://github.com/megvii-research/mdistiller at commit a08d46f10d61 (MIT). Any quoted code is shown under that license.