Hi,
I am looking to do the following in C++:
auto x = torch::zeros({5}, torch::requires_grad());
auto out_1 = torch::relu( W_1.matmul(x) + b_1);
auto out_2 = torch::relu( W_1.matmul(out_2) + b_2); 
auto logits = torch::log_softmax(out_2, 1);
auto loss = logits[0] - logits[1];

I want to find the values of d(loss)/d(out_1) and  d(loss)/d(out_2).
How do I do this? Attempts to do
loss.backward();

and then accessing
out_2.grad()

have seemingly failed: there is a runtime error which says libc++abi.dylib: terminating with uncaught exception of type c10::Error: tensor with backend UNKNOWN_BACKEND does not have a device
I can provide a minimal breaking example if need be.