Skip to content Skip to sidebar Skip to footer

How To Swap From Gpu To A Cpu Only?

Hi I was wondering how can run a machine learning code onto my CPU instead of a GPU? I have tried making the GPU false on the setting file but it hasn't been able to fix it. ###

Solution 1:

If I am not wrong, you are getting the above error at code model = loadmodel(). I don't have an idea what you are doing inside loadmodel(), but you can try below points:

  • Set defaults.device to cpu. To be completely sure, add a torch.cuda.set_device('cpu')
  • Change torch.load(model_weights) to torch.load(model_weights, map_location=torch.device('cpu'))

Solution 2:

If you're using a model extended from nn.Module you can move your entire model to CPU or GPU doing this:

device = torch.device("cuda")
model.to(device)
# or
device = torch.device("cpu")
model.to(device)

If you'd like to move just a Tensor:

x = torch.Tensor(10).cuda()
# orx = torch.Tensor(10).cpu()

Post a Comment for "How To Swap From Gpu To A Cpu Only?"