Skip to content
Advertisement

CPU only pytorch is crashing with error AssertionError: Torch not compiled with CUDA enabled

I’m trying to run the code from this repository and I need to use Pytorch 1.4.0. I’ve installed the CPU only version of pytorch with pip install torch==1.4.0+cpu torchvision==0.5.0+cpu -f https://download.pytorch.org/whl/torch_stable.html.

I ran the program by doing py -m train_Kfold_CV --device 0 --fold_id 10 --np_data_dir "C:UsersusernameOneDriveDesktopemadeldeenAttnSleepprepare_datasetsedf_20_npz" but I’m getting this error:

JavaScript

I’ve changed the number of GPU in the config to 0 and tried adding device = torch.device('cpu') at the begining of the program, but it’s not doing anything. How can I fix this error? I’m using windows 10 with python 3.7.9 if it helps

Thanks

Advertisement

Answer

You are using CPU only pytorch, but your code has statement like cr = nn.CrossEntropyLoss(weight=torch.tensor(classes_weights).cuda()) which is trying to move the tensor to GPU.

To fix it, remove all the .cuda() operations.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement