I have the same problem with you. I want to use
torch::autograd::backward() 

to instead. But I got the error log with

one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [1, 64, 4, 4]] is at version 2; expected version 1 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).

I dont’t konw how to solve the problem. Do you Solve it? Thanks!