That is the intention for CrossEntropyLoss – Apply softmax in training but not in inference (assuming you don’t need probabilistic representation).
And you can use training property to handle network for training and inference.
if self.training:
    # code for training
else:
    # code for inference