Pytorch uses cuda despite disabling it. How to force it to use CPU-only
I tried disabling cuda for pytorch following this stackoverflow question and a few others.
At OS level, before initializing python -&gt; set CUDA_VISIBLE_DEVICES ''
But when I enter the python prompt, I still see Cuda is available
&gt;&gt;&gt; import torch
&gt;&gt;&gt; torch.cuda.is_available()
True

A subsequent operation confirms it.
&gt;&gt;&gt; a = torch.ones(5)
&gt;&gt;&gt; b = a
&gt;&gt;&gt; a.add_(1)
tensor([2., 2., 2., 2., 2.])
&gt;&gt;&gt; print(b)
tensor([2., 2., 2., 2., 2.])

I can see that b also got updated. How do I force pytorch not to use GPU ?

You could use a.to(&quot;cpu&quot;) to move a tensor to a particular device, in this case CPU. Then a.is_cuda() should return False, confirming that it is not on GPU.
The same can be done with entire models, etc., e.g. model.to(&quot;cpu&quot;)
