Since CUDA operations are asynchronous, the stack trace might indeed point to a wrong line of code.
This can usually be fixed by running the script via CUDA_LAUNCH_BLOCKING=1 python script.py args, which will synchronize all CUDA operations or on the CPU.