Hi,
I got the same unexpected behaviour with PyTorch 1.5.0 using a GPU
loss = torch.nn.CrossEntropyLoss()
weights = torch.randn(10, 5)                                                                                                                         
labels = torch.arange(10)
loss(weights.cuda(), labels.cuda())
Out[13]: tensor(1.7329, device='cuda:0')

The error is triggered if I use the CPU though.