Yes, you could write your custom loss function, which could accept one-hot encoded targets.
The scatter_ method can be used to create the targets or alternatively use F.one_hot:
nb_classes = 3
target = torch.randint(0, nb_classes, (10,))
one_hot_scatter = torch.zeros(10, nb_classes).scatter_(
    dim=1, index=target.unsqueeze(1), src=torch.ones(10, nb_classes))

one_hot = F.one_hot(target, num_classes=nb_classes)