I assume you are using nn.CrossEntropyLoss as the criterion.
In that case, the model output should contain logits and have the shape [batch_size, nb_classes], while the target would have the shape [batch_size] and contain the class indices in the range [0, nb_classes-1].
The error is raised, if your target uses out-of-bounds class indices.
E.g. for 10 classes, the valid target values would be [0, 9], while you are trying to pass a 10 to the criterion.
Also, don’t call the forward method, as it will not call potentially registered hooks. Call the model directly instead: output = model(inputs).