class_docstr: 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 -> 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 -> 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
  :param lambda (float): loss controlling parameter for distillation
  :param distil_weight (float): Weight paramter for distillation loss
  :param device (str): Device used for training; 'cpu' for cpu and 'cuda' for gpu
  :param log (bool): True if logging required
  :param logdir (str): Directory for storing logs
class_docstr_tok: ["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","-",">","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","-",">","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",":","param","lambda","(","float",")",":","loss","controlling","parameter","for","distillation",":","param","distil_weight","(","float",")",":","Weight","paramter","for","distillation","loss",":","param","device","(","str",")",":","Device","used","for","training",";","'cpu","'","for","cpu","and","'cuda","'","for","gpu",":","param","log","(","bool",")",":","True","if","logging","required",":","param","logdir","(","str",")",":","Directory","for","storing","logs"]
docstr: Function used for calculating the KD loss during distillation
  
  :param y_pred_pair_1 (torch.FloatTensor): Prediction made by the student model for first pair elements
  :param y_pred_pair_2 (torch.FloatTensor): Prediction made by the student models for second pair elements
docstr_tok: ["Function","used","for","calculating","the","KD","loss","during","distillation",":","param","y_pred_pair_1","(","torch.FloatTensor",")",":","Prediction","made","by","the","student","model","for","first","pair","elements",":","param","y_pred_pair_2","(","torch.FloatTensor",")",":","Prediction","made","by","the","student","models","for","second","pair","elements"]
code: def calculate_kd_loss(self, y_pred_pair_1, y_pred_pair_2):
      """
      Function used for calculating the KD loss during distillation
  
      :param y_pred_pair_1 (torch.FloatTensor): Prediction made by the student model for first pair elements
      :param y_pred_pair_2 (torch.FloatTensor): Prediction made by the student models for second pair elements
      """
      log_p = torch.log_softmax(y_pred_pair_1 / self.temp, dim=1)
      q = torch.softmax(y_pred_pair_2 / self.temp, dim=1)
      loss = (
          nn.KLDivLoss(reduction="sum")(log_p, q)
          * (self.temp**2)
          / y_pred_pair_1.size(0)
      )
  
      return loss
  
file_path: KD_Lib/KD_Lib/KD/vision/CSKD/cskd.py
imports: from copy import deepcopy
  import matplotlib.pyplot
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.optim
  from KD_Lib.KD.common import BaseClass
label_desc: Use image node_id 2 for calling the CSKD obj's underlying member method code with example usage: obj.calculate_kd_loss(y_pred_pair_1, y_pred_pair_2) and returns: loss