Based on the error message dim1 has a different shape for your model output and target.
Note that nn.CrossEntropyLoss assumes the output is passed as [batch_size, nb_classes, *], while the target should have the shape [batch_size, *] (missing nb_class dimension).
Other loss functions, such as nn.MSELoss expect the same shapes or are broadcasting internally, if possible.