The raised error points towards an invalid index in the target:
IndexError: Target 2 is out of bounds.

In a multi-class classification using nn.CrossEntropyLoss the model output is expected to have the shape [batch_size, nb_classes] while the target should have the shape [batch_size] and contain class indices in the range [0, nb_classes-1].
Since your target contains a class index of 2 this would mean that you are working with at least 3 different classes (class indices would be [0, 1, 2]) and your model output should thus have the shape [batch_size, >=3], which doesn’t seem to be the case.