Could you check the target values, since they are supposed to be in the range [0, nb_classes-1].
Maybe they are outside of this range, which will throw an error.
Also, you might want to run the code on CPU to get a (hopefully better) error message.