Using autograd::grad function in C++

I am trying to make a custom C++ extension using this tutorial, but I am getting an error when I am trying to compile the code. I am basically trying to call the grad function in here. I am getting the following error…

error: ‘grad’ is not a member of ‘torch::autograd’
return torch::autograd::grad(outputs, inputs, grad_outputs, retain_graph, create_graph, allow_unused);

Any help will be appreciate! Thank you.

Hi,

Which version of pytorch/libtorch are you using?

Currently I have pytorch 1.2.0 installed in my machine. I installed it using pip

I’m not sure this function was already added back then. You should try to upgrade to the latest version.

1 Like

Thank you. Updating pytorch worked.