Good to hear you narrowed down the indexing issue.
For the sake of completeness: due to the asynchronous execution of CUDA kernels, you might see errors from different libs or code places. To get a better stack trace, which should point to the failing operation, you could run the script via: CUDA_LAUNCH_BLOCKING=1 python script.py args.