main.py
def loss_fn_kd(outputs, labels, teacher_outputs, T, alpha):
    """
    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
    """
    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. - 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
    
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
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, T, alpha):
    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. - alpha)
    return KD_loss
def loss_fn_kd ( outputs , labels , teacher_outputs , T , alpha ) : 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. - alpha ) return KD_loss
Compute the knowledge-distillation (KD) loss given outputs, labels.
Compute the knowledge - distillation ( KD ) loss given outputs labels .
"""
    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
    """
outputs
labels
teacher_outputs
T
alpha