def loss_fn_kd(outputs, labels, teacher_outputs, params):
    '\n    Compute the knowledge-distillation (KD) loss given outputs, labels.\n    "Hyperparameters": temperature and alpha\n\n    NOTE: the KL Divergence for PyTorch comparing the softmaxs of teacher\n    and student expects the input tensor to be log probabilities! See Issue #2\n    '
    alpha = params.alpha
    T = params.temperature
    KD_loss = ((nn.KLDivLoss()(F.log_softmax((outputs / T), dim=1), F.softmax((teacher_outputs / T), dim=1)) * ((alpha * T) * T)) + (F.cross_entropy(outputs, labels) * (1.0 - alpha)))
    return KD_loss
Compute the knowledge-distillation (KD) loss given outputs, labels.
"Hyperparameters": temperature and alpha

NOTE: the KL Divergence for PyTorch comparing the softmaxs of teacher
and student expects the input tensor to be log probabilities! See Issue #2
def loss_fn_kd(outputs, labels, teacher_outputs, params):
    '\n    Compute the knowledge-distillation (KD) loss given outputs, labels.\n    "Hyperparameters": temperature and alpha\n\n    NOTE: the KL Divergence for PyTorch comparing the softmaxs of teacher\n    and student expects the input tensor to be log probabilities! See Issue #2\n    '
    alpha = params.alpha
    T = params.temperature
    KD_loss = ((nn.KLDivLoss()(F.log_softmax((outputs / T), dim=1), F.softmax((teacher_outputs / T), dim=1)) * ((alpha * T) * T)) + (F.cross_entropy(outputs, labels) * (1.0 - alpha)))
    return KD_loss