Are you sure you are using the right criterion?
This dummy code snippet seems to work:
criterion = nn.CrossEntropyLoss(ignore_index=-1)
output = torch.randn(10, 10, requires_grad=True)
target = torch.randint(0, 10, (10,))
target[0] = -1
loss = criterion(output, target)
loss.backward()
print(output.grad)

The gradients at output.grad[0] are all zeros as expected.
If that doesn’t work, could you please post a code snippet so that we could have a look?