It seems to work:
criterion = nn.CrossEntropyLoss(ignore_index=-1)

output = torch.randn(2, 10, requires_grad=True)
target = torch.tensor([-1, 1])

loss = criterion(output, target)
loss.backward()
print(loss, output.grad)
> tensor(1.4096, grad_fn=<NllLossBackward>) 
tensor([[ 0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000,
          0.0000,  0.0000,  0.0000],
        [ 0.1207, -0.7557,  0.0068,  0.0153,  0.0806,  0.0683,  0.0791,  0.1964,
          0.0741,  0.0229,  0.0915]])

I would assume that only positive indices would work, so based on this assumption I would create an additional dummy class:
criterion = nn.CrossEntropyLoss(ignore_index=10)

output = torch.randn(2, 11, requires_grad=True)
target = torch.tensor([10, 1])

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

but apparently -1 just works fine.