CUDA operations are executed asynchronously, so errors (in this case the assert triggered by the loss function) can be reported at a later line of code.
To isolate the offending operation you could rerun the script via CUDA_LAUNCH_BLOCKING=1 python script.py args or run it on the CPU.
The latest PyTorch release also gives you this information in the error message.