Solved by nilansh_rajput1 in post #8 
              
              
                Hey sorry I got it, in my code there was torch.set_grad_enabled(False); this line, I was struggling with my custom loss function for a day for this error:( . I tried this example to see if same error comes up.