Home

Awesome

[CVPR 2024 Highlight] Logit Standardization in Knowledge Distillation

Closed Issues Open Issues

[Project Page] [arXiv] [Supplementary Materials] [Zhihu (in Chinese)]

<img src=.github/1_1-1.png width=50% /><img src=.github/2_2-1.png width=50% />
Vanilla KDKD w/ our logit standardization

Abstract

Knowledge distillation involves transferring soft labels from a teacher to a student using a shared temperature-based softmax function. However, the assumption of a shared temperature between teacher and student implies a mandatory exact match between their logits in terms of logit range and variance. This side-effect limits the performance of student, considering the capacity discrepancy between them and the finding that the innate logit relations of teacher are sufficient for student to learn. To address this issue, we propose setting the temperature as the weighted standard deviation of logit and performing a plug-and-play Z-score pre-process of logit standardization before applying softmax and Kullback-Leibler divergence. Our pre-process enables student to focus on essential logit relations from teacher rather than requiring a magnitude match, and can improve the performance of existing logit-based distillation methods. We also show a typical case where the conventional setting of sharing temperature between teacher and student cannot reliably yield the authentic distillation evaluation; nonetheless, this challenge is successfully alleviated by our Z-score. We extensively evaluate our method for various student and teacher models on CIFAR-100 and ImageNet, showing its significant superiority. The vanilla knowledge distillation powered by our pre-process can achieve favorable performance against state-of-the-art methods, and other distillation variants can obtain considerable gain with the assistance of our pre-process.

:tada: News

2024.4: Selected as Highlight in CVPR 2024

2024.3: Release the code and arXiv

2024.2: Accepted by CVPR 2024

2023.7: Rejected by ICCV 2023

Usage

The code is built on mdistiller, Multi-Level-Logit-Distillation, CTKD and tiny-transformers.

Installation

Environments:

Install the package:

sudo pip3 install -r requirements.txt
sudo python setup.py develop

Distilling CNNs

CIFAR-100

  1. For KD
# KD
python tools/train.py --cfg configs/cifar100/kd/resnet32x4_resnet8x4.yaml
# KD+Ours
python tools/train.py --cfg configs/cifar100/kd/resnet32x4_resnet8x4.yaml --logit-stand --base-temp 2 --kd-weight 9 
  1. For DKD
# DKD
python tools/train.py --cfg configs/cifar100/dkd/resnet32x4_resnet8x4.yaml 
# DKD+Ours
python tools/train.py --cfg configs/cifar100/dkd/resnet32x4_resnet8x4.yaml --logit-stand --base-temp 2 --kd-weight 9 
  1. For MLKD
# MLKD
python tools/train.py --cfg configs/cifar100/mlkd/resnet32x4_resnet8x4.yaml
# MLKD+Ours
python tools/train.py --cfg configs/cifar100/mlkd/resnet32x4_resnet8x4.yaml --logit-stand --base-temp 2 --kd-weight 9 
  1. For CTKD

Please refer to CTKD.

Results and Logs

We put the training logs in ./logs and hyper-linked below. The name of each log file is formated with KD_TYPE,TEACHER,STUDENT,BASE_TEMPERATURE,KD_WEIGHT.txt. The possible third value for DKD is the value of BETA. Due to average operation and randomness, there may be slight differences between the reported results and the logged results.

  1. Teacher and student have identical structures:
Teacher <br> StudentResNet32x4 <br> ResNet8x4VGG13 <br> VGG8Wrn_40_2 <br> Wrn_40_1Wrn_40_2 <br> Wrn_16_2ResNet56 <br> ResNet20ResNet110 <br> ResNet32ResNet110 <br> ResNet20
KD73.3372.9873.5474.9270.6673.0870.67
KD+Ours76.6274.3674.3776.1171.4374.1771.48
CTKD73.3973.5273.9375.4571.1973.5270.99
CTKD+Ours76.6774.4774.5876.0871.3474.0171.39
DKD76.3274.6874.8176.2471.9774.1171.06
DKD+Ours77.0174.8174.8976.3972.3274.2971.85
MLKD77.0875.1875.3576.6372.1974.1171.89
MLKD+Ours78.2875.2275.5676.9572.3374.3272.27
  1. Teacher and student have distinct structures:
Teacher <br> StudentResNet32x4 <br> SHN-V2ResNet32x4 <br> Wrn_16_2ResNet32x4 <br> Wrn_40_2Wrn_40_2 <br> ResNet8x4Wrn_40_2 <br> MN-V2VGG13 <br> MN-V2ResNet50 <br> MN-V2
KD74.4574.9077.7073.9768.3667.3767.35
KD+Ours75.5675.2677.9277.1169.2368.6169.02
CTKD75.3774.5777.6674.6168.3468.5068.67
CTKD+Ours76.1875.1677.9977.0369.5368.9869.36
DKD77.0775.7078.4675.5669.2869.7170.35
DKD+Ours77.3776.1978.9576.7570.0169.9870.45
MLKD78.4476.5279.2677.3370.7870.5771.04
MLKD+Ours78.7677.5379.6677.6871.6170.9471.19

Training on ImageNet

Distilling ViTs

Please refer to tiny-transformers.

Results

ModelTop-1 Acc. (Base)Top-1 Acc. (ECCV2022)Tpo-1 Acc. (KD+Ours)
DeiT-Tiny65.08 ( weights | log )78.15 ( weights | log )78.55( weights | log)
T2T-ViT-769.37 ( weights | log )78.35 ( weights | log )78.43( weights | log)
PiT-Tiny73.58 ( weights | log )78.48 ( weights | log )78.76( weights | log)
PVT-Tiny69.22 ( weights | log )77.07 ( weights | log )78.43( weights | log)

Reproduce Figure 3, 4, 5

Please refer to visualizations.

Acknowledgement

Sincere gratitude to the contributors of mdistiller, CTKD, Multi-Level-Logit-Distillation and tiny-transformers for their distinguished efforts.

:mailbox_with_mail: Contact

Shangquan Sun: shangquansun@gmail.com

:mega: Citation

If you find that this project helps your research, please consider citing some of the following paper:

@inproceedings{sun2024logit,
  title={Logit standardization in knowledge distillation},
  author={Sun, Shangquan and Ren, Wenqi and Li, Jingzhi and Wang, Rui and Cao, Xiaochun},
  booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  pages={15731--15740},
  year={2024}
}

@article{sun2024logit,
  title={Logit Standardization in Knowledge Distillation},
  author={Sun, Shangquan and Ren, Wenqi and Li, Jingzhi and Wang, Rui and Cao, Xiaochun},
  journal={arXiv preprint arXiv:2403.01427},
  year={2024}
}