Here is a recreation of the problem
The below code works fine
>>> loss = nn.CrossEntropyLoss()
>>> input = torch.randn(3, 5, requires_grad=True)
>>> target = torch.empty(3, dtype=torch.long).random_(5)
>>> output = loss(input, target)

But this wont work
>>> loss = nn.CrossEntropyLoss()
>>> input = torch.randn(3, 5, requires_grad=True)
>>> target = torch.empty(3, dtype=torch.long).random_(100)
>>> output = loss(input, target)

This is because target can be [0,5,99].
The target is screaming at you, that your 3rd sample is the 100th class.
But if you look at your input there is only 5 classes. Meaning target value should in range [0-4].
cheers