Solved by ptrblck in post #2 
              
              
                .argmax is not a differentiable function, so you are detaching the model output in: 
 y_train_pred = model(X_train_batch).argmax(dim=1).float()

which will raise the error. 
I don’t know what kind of use case you are working on, but in case it’s a multi-class classification, pass the raw logits to n…