The class logits should be in dim1 in your use case, so you could permute your output as:
p = p.permute(0, 2, 1)

or alternatively make sure your model outputs the right shapes, but this of course depends on the architecture.