Could you print the shape of the output of your model as well as the targets?
Based on the error description I guess that your output might only have a single channel and thus nn.CrossEntropyLoss would only accept a single class (which is not very useful in a multi-class use case  ).