What torch.cuda.set_device() does?

Does torch.cuda.set_device(args.gpu) set a GPU for execution or it sets the number of GPUs should be used for execution?

If it sets the GPU for execution, how can I set multiple GPUs to run my experiment? For example, I want to tell to pytorch that you should use two GPUs (if available) to run my experiment. How can I achieve that?

torch.cuda.set_device sets the default GPU and in order to use multi-GPU, you may use nn.DataParallel

Can you give an example in order to use multi-GPU?

you may see the following example OpenNMT

1 Like