Did you update the NVIDIA drivers recently?
Sometimes this error is thrown, when the CUDA / NVIDIA drivers are in a bad state.
A restart usually solves the problem.
Alternatively, could you try to set another GPU as the visible device?
The GPU ids sometimes don’t match with what nvidia-smi shows.
Could you run export CUDA_DEVICE_ORDER=PCI_BUS_ID before the script?