How to call MSE_loss

This looks like it should be right to me:

torch::Tensor loss = torch::mse_loss(prediction, desired_prediction.detach(), torch::nn::functional::MSELossFuncOptions(torch::kNone));
    loss.backward();

But I’m getting

error: cannot convert ‘torch::nn::functional::MSELossFuncOptions {aka torch::nn::MSELossOptions}’ to ‘int64_t {aka long int}’ for argument ‘3’ to ‘at::Tensor at::mse_loss(const at::Tensor&, const at::Tensor&, int64_t)

I’m sure it’s a simple thing - any idea what’s wrong?

Changing torch::mse_loss to torch::nn::functional::mse_loss should make it work.

mse_loss is defined under torch::nn::functional namespace.

https://pytorch.org/cppdocs/api/function_namespacetorch_1_1nn_1_1functional_1aba6a5341298f43163c046b3dd50dc6ce.html#function-torch-nn-functional-mse-loss

1 Like

It gives me an error saying :

error: ‘functional’ is not a namespace-name

And if I go to its definition it gets me to the thrust API. What could be wrong?