Where can I find cross_entropy_loss implementation

Hi, I would like to see the implementation of cross entropy loss. So far, I learned that, torch.nn.funcional.py calls torch._C.nn.cross_entropy_loss but I am having trouble finding the C implementation.

From the releated issue(Where does `torch._C` come from?), I realize that some functions are implemented in C and torch._C is the implementation. The Issue contains links to the original implementations, but it from the outdated pytorch code.

  • Can someone point to the exact location of cross entropy loss implementation (both CPU and GPU)?
  • If possible, can someone kindly explain how one can track down to such point from python package(e.g. from torch.nn.functional.py to the C implementation, where the C code is binded with python, etc…)

Many thanks!

Cross-entropy loss is implemented with a combination of existing operations, such as logsoftmax and nll_loss:

These individual kernels will have CPU and GPU implementations in ATen, e.g.,
CPU:

GPU:

1 Like