This error still points to an invalid target index.
It’s a bit strange that your code is running fine on the CPU.
However, try to add an assert statement and check each target batch so only contain values in [0, nb_classes-1].