Using CUDA Pytorch RuntimeError: Expected object of backend CUDA but got backend CPU running on Jupyter Notebook
I just started to review Lesson 4 from PyTorch Scholarship Challenge of Udacity Scholarship .
After running my exercise I saw that my model is Running on CPU, as you can see in the picture below my PC’s CPU-s are on 100% running:
So I started to search on internet ,also searching Slack PyTorch Challenge then asking my colleagues from Slack PyTorch Challenge Thanks to: Mariam El-Shakafi, manu_correa, I found the solution on this post :
Solution:
add
device = torch.device(“cuda:0” if torch.cuda.is_available() else “cpu”)
# Assume that we are on a CUDA machine, then this should print a CUDA device:
print(device)
you will get :
add:
model = model.to(device)
you will get :
add:
images = images.to(device)
labels = labels.to(device)
you will get :
CUDA will do a faster results and as you can see below low CPU usage: