Could you set the env variable in your terminal via:
CUDA_VISIBLE_DEVICES=1,3 python script.py args

If you are using the os.environ method inside your script, you would have to make sure it’s called before any torch imports.