Solved by ptrblck in post #2 
              
              
                You are detaching the prediction tensor here: 
y_pred1 = y_pred.data.numpy().astype("int")

Don’t use the .data attribute, as it may have unwanted side effects. 
Also, once you leave PyTorch and use other libraries such as numpy, Autograd won’t be able to automatically create the backward pass for y…