You could rerun the code via CUDA_LAUNCH_BLOCKING=1 python script.pt args and make sure that the right line of code is shown, which raises the issue.
If you are still seeing that the criterion is raising it, add assert statements before calculating the loss and check for the values of the model output and the targets.