Depending what dim0 and dim1 are representing, this might be a valid approach.
I assume dim0 is the batch size, so what is dim1?
nn.CrossEntropyLoss takes an input of shape [N, C, additional dims] and a target of [N, additional dims].
Could you explain the dimensions so that we can reshape them if necessary?