Most likely your targets contain invalid values outside of the expected range [0, nb_classes-1].
I’m not sure, if you are using an older PyTorch version, as the stacktrace with blocking launches should show the indexing errors.
In case you are already using the latest release, you could use TORCH_SHOW_CPP_STACKTRACES=1 to hopefully get a more detailed stacktrace or run the code on the CPU to get a better error.