If I'm not specifying to use CPU/GPU, which one is my script using?
PyTorch defaults to the CPU, unless you use the .cuda()
methods on your models and the torch.cuda.XTensor
variants of PyTorch's tensors.
My way is like this (below pytorch 0.4):
dtype = torch.cuda.float if torch.cuda.is_available() else torch.float
torch.zeros(2, 2, dtype=dtype)
UPDATE pytorch 0.4:
device = torch.device("cuda" if use_cuda else "cpu")
model = MyRNN().to(device)
from PyTorch 0.4.0 Migration Guide.
You should write you code so that it will use GPU processing if torch.cuda.is_available == True.
So:
if torch.cuda.is_available():
model.cuda()
else:
# Do Nothing. Run as CPU.