The error points to the criterion, so you should check the model output and target for valid shapes and values.
I.e. for a vanilla multi-class classification, the target should have the shape [batch_size] and contain values in the range [0, nb_classes-1].