Search code examples
pythonpytorchconda

How to get conda to install pytorch-gpu rather than pytorch-cpu Ubuntu cuda 11.4


I've combed through all of the similar questions but to no avail. I have an older GPU that I'm trying to get to work with CUDA and pytorch. For some reason, I can't get conda to install pytorch gpu. No matter what I do, it tries to install the cpu version of pytorch.

I build my conda like this - miniconda

conda create --name tortoise python=3.9 numba inflect

I need to force a specific version of CUDA 11.4.

conda install pytorch=1.11.0 torchvision=0.12 torchaudio=0.11 cudatoolkit=11.4 -c pytorch -c nvidia

Someone said that torchvision and torchaudio could cause the cpu version to be installed.

conda install pytorch=1.11.0 cudatoolkit=11.4 -c pytorch -c nvidia

Regardless of what I do, it tries to install the cpu version of pytorch.

Showing conda will install cpu version of pytorch

So what it is that is determining that the cpu version should be installed. I have a GPU in this box.

nvidia-smi output

conda info

conda info


Solution

  • Since the virtual package __cuda==11.4 is present, conda should be able to install the gpu accelerated versions of pytorch. The next thing to check is available cuda versions. You can use conda search for that like so:

    conda search -c pytorch pytorch==1.11
    # Name                       Version           Build  Channel
    pytorch                       1.11.0    py3.10_cpu_0  pytorch
    pytorch                       1.11.0 py3.10_cuda10.2_cudnn7.6.5_0  pytorch
    pytorch                       1.11.0 py3.10_cuda11.1_cudnn8.0.5_0  pytorch
    pytorch                       1.11.0 py3.10_cuda11.3_cudnn8.2.0_0  pytorch
    pytorch                       1.11.0 py3.10_cuda11.5_cudnn8.3.2_0  pytorch
    pytorch                       1.11.0     py3.7_cpu_0  pytorch
    pytorch                       1.11.0 py3.7_cuda10.2_cudnn7.6.5_0  pytorch
    pytorch                       1.11.0 py3.7_cuda11.1_cudnn8.0.5_0  pytorch
    pytorch                       1.11.0 py3.7_cuda11.3_cudnn8.2.0_0  pytorch
    pytorch                       1.11.0 py3.7_cuda11.5_cudnn8.3.2_0  pytorch
    pytorch                       1.11.0     py3.8_cpu_0  pytorch
    pytorch                       1.11.0 py3.8_cuda10.2_cudnn7.6.5_0  pytorch
    pytorch                       1.11.0 py3.8_cuda11.1_cudnn8.0.5_0  pytorch
    pytorch                       1.11.0 py3.8_cuda11.3_cudnn8.2.0_0  pytorch
    pytorch                       1.11.0 py3.8_cuda11.5_cudnn8.3.2_0  pytorch
    pytorch                       1.11.0     py3.9_cpu_0  pytorch
    pytorch                       1.11.0 py3.9_cuda10.2_cudnn7.6.5_0  pytorch
    pytorch                       1.11.0 py3.9_cuda11.1_cudnn8.0.5_0  pytorch
    pytorch                       1.11.0 py3.9_cuda11.3_cudnn8.2.0_0  pytorch
    pytorch                       1.11.0 py3.9_cuda11.5_cudnn8.3.2_0  pytorch
    

    Note that for python 3.9, which you have, there are only cuda10.2, cuda11.1, cuda11.3 and cuda11.5 available. So by forcing cudatoolkit=11.4, conda cannot find a suitable pytorch gpu version and installs a cpu only variant. Since you driver/graphics card are only capable up to cuda 11.4, your best option is probably to use 11.3:

    conda install pytorch=1.11.0 cudatoolkit=11.3 -c pytorch -c nvidia