This code snippet seems to work:
criterion = nn.CrossEntropyLoss(
    ignore_index=255, weight=torch.tensor([1., 2.]), reduction='none')

x = torch.randn(3, 2)
y = torch.tensor([0, 1, 255])

loss = criterion(x, y)
print(loss)
> tensor([0.8519, 1.1084, 0.0000])