Hi,
Due to how cuda works, some errors are reported on a different operation than the one that is responsible for the error.
You can force it to raise the error right away by launching your script with the CUDA_LAUNCH_BLOCKING environment variable as:
CUDA_LAUNCH_BLOCKING=1 python your_script.py

It is possible that it will run slightly slower than usual, it is normal.