Where can I find source code of mse_loss() in libtorch?

From pytorch’s project in github, I can find MSELossImpl::forward() in torch/csrc/api/src/nn/modules/loss.cpp.

This function calls F::detail::mse_loss(input, target, options.reduction());, it’s in torch/csrc/api/include/torch/nn/functional/loss.h.

Again F::detail::mse_loss magically calls:

return torch::mse_loss(

However I can’t find defination of torch::mse_loss().

torch/csrc/api/include/torch/nn/functional/loss.h includes 3 files:

#include <ATen/ExpandUtils.h>
#include <torch/nn/functional/activation.h>
#include <torch/nn/options/loss.h>


Both the c++ and python binding are generated based on this file.
Here since there are no specific function name for the backend, there is a function in Aten/native with that name. For mse, you can find it here. Hope this helps.

Thank you, it’s very useful.