Distillation code loss functions
# ❓ Questions & Help
Why compute cross entropy loss from the hard labels in distillation code?

if self.alpha_clm > 0.0:
            shift_logits = s_logits[..., :-1, :].contiguous()
            shift_labels = lm_labels[..., 1:].contiguous()
            loss_clm = self.lm_loss_fct(shift_logits.view(-1, shift_logits.size(-1)), shift_labels.view(-1))
            loss += self.alpha_clm * loss_clm

The model outputs loss when passed with the labels.


<!-- The GitHub issue tracker is primarly intended for bugs, feature requests,
     new models and benchmarks, and migration questions. For all other questions,
     we direct you to Stack Overflow (SO) where a whole community of PyTorch and
     Tensorflow enthusiast can help you out. Make sure to tag your question with the
     right deep learning framework as well as the huggingface-transformers tag: 
     https://stackoverflow.com/questions/tagged/huggingface-transformers 
     
     If your question wasn't answered after a period of time on Stack Overflow, you
     can always open a question on GitHub. You should then link to the SO question 
     that you posted.
     -->

## Details
<!-- Description of your issue -->

<!-- You should first ask your question on SO, and only if
     you didn't get an answer ask it here on GitHub. -->
**A link to original question on Stack Overflow**: 
Hello @snaik2016,
The part of code you're referring to is not a distillation loss. It's the "classic" causal language modeling loss.
Victor<|||||>Not referring to the "distillation loss" just the part of the code where loss is computed in distillation code. The exact same quantity is return by model output when labels are passed.<|||||>Oh yes, you are right, this could be factorized in.
Just note that you have to be careful with the `ignore_index` and make sure it's coherent with your processing (if I remember correctly, at one point, not all the models were using the same `ignore_index` in the loss computation).<|||||>This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
