Thanks for the answer. Actually I am trying to perform an adversarial attack where I don’t have to perform any training. The strange thing happening is when I calculate my gradients over an original  input I get  tensor([0., 0., 0.,  …, nan, nan, nan])  as result but if I made very small changes to my input the gradients turn out to perfect in the range of  tensor(0.0580) and tensor(-0.0501)..
Please help me to figure out this issue?