Hello, everyone. I need to use the neural network in an unconventional way, in which I have to compute the gradient of the model output with respect to the input, but I always get a None.
My code is like this:
model = torch.load('totalmodel.pth') model.eval() x = torch.tensor([1.,2.,3.,4.],device=device,requires_grad=True) y = model(x) y.backward() print(y) print(x.grad)
And the output is:
It shows that the grad_fn of output y is valid, and x requires_grad is True, why is the grad of x None?