Solved by JCouture in post #2 
              
              
                I figured out the issue which was that y_pred actually had a shape of [4,1,1] whilst y_true had only [4,1]. I got rid of the third dimension by using torch.squeeze(y_pred, 2) and this has fixed the issue.