Could you post a minimal code snippet to reproduce this issue, as this dummy code works fine:
output = torch.randn(10, 10, requires_grad=True)
target = torch.randint(0, 10, (10,))
target[0] = -100

output = output.to('cuda')
target = target.to('cuda')

criterion = nn.CrossEntropyLoss()

loss = criterion(output, target)
loss.backward()