So basically, you want to ignore the loss for the class-2, right ?
In that case, you can make use of the argument class_weights in nn.CrossEntropyLoss() by setting it to torch.Tensor([1,1,0]).
https://pytorch.org/docs/master/generated/torch.nn.CrossEntropyLoss.html 2