Using a specific device for Run and Debug in PyTorch

Viewed 17

I want to use a specific GPU. I followed the instructions of some posts including (1, 2) but they don't work for me. More specifically, I when I run the code for debugging with vscode, even when I select the GPU using: dev = torch.device('cuda:1' if torch.cuda.is_available() else 'cpu') the program is run on the device 0 and device 2. How can I fix that?

This is the code I use:

    dev = torch.device('cuda:1' if torch.cuda.is_available() else 'cpu')
    model = model.to(dev)
0 Answers
Related