Is there a way to force pytorch to use the CPU?

Running the notebooks on a Windows 10 machine with an unsupported GPU and getting this error:

Found GPU0 GeForce GTX 960M which is of cuda capability 5.0.
    PyTorch no longer supports this GPU because it is too old.

Tried activating the fastai-cpu environment but it still tried to use the GPU (and thus gives me the error).

Is there a way to simply disable the GPU from being used by pytorch?

SOLVED: You need to uninstall the referenced version of pytorch in the fastai-cpu environment and install the correct version from peterjc123 repo.

conda uninstall pytorch
conda install -c peterjc123 pytorch-cpu

A quick addendum. You could use CUDA_VISIBLE_DEVICES="" jupyter notebook or CUDA_VISIBLE_DEVICES="" python to have the same effect. You could replace “” with any other index like 0, 1 to refer to which all gpus the function will have access to as well.


Updated answer for fastai v1

you can force the library to use the CPU by simply setting defaults.device = 'cpu'.

WIthout wildcard imports: fastai.torch_core.defaults.device = 'gpu'

Relevant documentation: torch_core - docs


This is way easier