The error message points to a target values, which is out of bounds:
Assertion `cur_target >= 0 && cur_target < n_classes` failed

Make sure the target contains values in the range [0, nb_classes-1] for nn.CrossEntropyLoss or nn.NLLLoss.