Skip to content

Commit

Permalink
Error handling and minor bug fixes in CSKD (#100)
Browse files Browse the repository at this point in the history
* pairwise sampler added and csdk updated

* links added in init

* Finalised and logs added

* CSKD added with tests

* Docs added

* Testing internal kdloss

* Adding docstrings and paper summary in tutorial

* Minor correction in docs

* Error handling for non-none teacher added

* cskd reformatted
  • Loading branch information
ashwinvaswani authored Jun 9, 2021
1 parent d30d065 commit 934d1d3
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions KD_Lib/KD/vision/CSKD/cskd.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

class CSKD(BaseClass):
"""
Implementation of assisted Knowledge distillation from the paper "Improved Knowledge
Distillation via Teacher Assistant" https://arxiv.org/pdf/1902.03393.pdf
Implementation of "Regularizing Class-wise Predictions via Self-knowledge Distillation"
https://arxiv.org/pdf/2003.13964.pdf
:param teacher_model (torch.nn.Module): Teacher model
:param teacher_model (torch.nn.Module): Teacher model -> Should be None
:param student_model (torch.nn.Module): Student model
:param train_loader (torch.utils.data.DataLoader): Dataloader for training
:param val_loader (torch.utils.data.DataLoader): Dataloader for validation/testing
:param optimizer_teacher (torch.optim.*): Optimizer used for training teacher
:param optimizer_teacher (torch.optim.*): Optimizer used for training teacher -> Should be None
:param optimizer_student (torch.optim.*): Optimizer used for training student
:param loss_fn (torch.nn.Module): Calculates loss during distillation
:param temp (float): Temperature parameter for distillation
Expand Down Expand Up @@ -60,6 +60,11 @@ def __init__(
logdir,
)
self.lamda = lamda
if teacher_model is not None or optimizer_teacher is not None:
print(
"Error!!! Teacher model and Teacher optimizer should be None for self-distillation, please refer to the documentation."
)
assert teacher_model == None

def calculate_kd_loss(self, y_pred_pair_1, y_pred_pair_2):
"""
Expand Down

0 comments on commit 934d1d3

Please sign in to comment.