Could you point me to the line of code where this error is thrown?
If you are running the code on your GPU, make sure to call the script using:
CUDA_LAUNCH_BLOCKING=1 python script.py args

because otherwise stack trace might point to a wrong line of code, since CUDA calls are asynchronous.