That’s strange, as the script works even if I run it on a machine with a masked GPU:
CUDA_VISIBLE_DEVICES="" python your_script.py
> device(type='cpu')

EDIT: Wait a moment. I’ve run the script on the wrong machine.
What is torch.cuda.is_available() returning on your machine?