Considering two classes, do the label span between 0 and 1 ?
I have a minimal code which works, make sure this code and yours are similar.
logits = torch.from_numpy(np.random.randn(16,2)).float()
target = torch.from_numpy(np.random.randint(0,2, size = 16)).long()

loss = nn.CrossEntropyLoss()
z = loss(logits, target)