The error is expected in this case, since nn.CrossEntropyLoss expects targets in the range [0, nb_classes-1] in order to use it as indices to calculate the loss.
If you want to train the model with different subsets, your model should most likely still output the logits for all 12 classes, shouldn’t it?
I guess your current approach wants to map the new labels to the 5 outputs of your model, which would mix different targets for the same class output of the model so I’m unsure if that’s really what you want.