You should double check that the target that you give to your loss function verifies target – (N) where each value is 0≤targets[i]≤C−1 as stated in the doc 12.
If these are valid, you can enable the anomaly detection 28 mode to get more information about the error in the backward pass.