How to run a pytorch project with CPU?
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?

Here's the simplest fix I can think of:

Put the following line near the top of your code:

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')


Do a global replace. Change .cuda() to .to(device), where device is the variable set in step 1.

