You could easily transform the one-hot encoded tensors to class index tensors using target = torch.argmax(one_hot, 1) and just remove the softmax at the end of your model.
Generally I wouldn’t recommend to rewrite PyTorch function, if you don’t have a valid use case for it, as e.g. internally the log-sum-exp trick is used to stabilize the calculations numerically.
Anyway, I think the mean in your formula would calculate the mean over all classes, which should most likely yield a lower loss than the corresponding one using nn.CrossEntropyLoss.