Solved by ptrblck in post #2 
              
              
                Try to swap the labels and y_pred tensors when passing them to your criterion. 
If that doesn’t help, could you post the complete stack trace? 
Also, Variables are deprecated since PyTorch 0.4, so you should use tensors now.