Reputation: 165
A Pytorch project is supposed to run on GPU. I want to run it on my laptop only with CPU. There are a lot of places calling .cuda()
on models, tensors, etc., which fail to execute when cuda is not available. Is it possible to do it without changing the code everywhere?
Upvotes: 5
Views: 9291
Reputation: 40909
Here's the simplest fix I can think of:
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
.cuda()
to .to(device)
, where device
is the variable set in step 1.Upvotes: 5
Reputation: 46
That depends wholly on the structure and design of the code within the project in question. Usually there would be an argument to specify on which device to run on. You should check your code. It is also not advisable to run it on your laptop CPU especially if the project consists of a moderately large model. Good luck!
Upvotes: 0