I’m not sure which script you are using, but check the target shape before calculating the loss:
print(target.min(), target.max())
loss = criterion(output, target)

The expected range is posted in the previous answer as [0, nb_classes-1], i.e. if you are dealing with 5 classes, the target tensor should contain the values [0, 1, 2, 3, 4].