This error might be thrown if you are running out of memory and cublas isn’t able to create its handle.
Could you check the memory usage via nvidia-smi and check if you are close to the device limit?
If that’s the case, try to lower the batch size and rerun the code.