This error is raised, if you pass invalid target indices to nn.CrossEntropyLoss or nn.NLLLoss, which both expect the target tensor to contain values in the range [0, nb_classes-1].
I don’t think the Python version changes this error, so you would have to check the target values instead.