3

Some questions came up from https://superuser.com/questions/1572640/do-i-need-to-install-cuda-separately-after-installing-the-nvidia-display-driver. One of these questions:

Does conda pytorch need a different version than the official non-conda / non-pip cuda toolkit at https://developer.nvidia.com/cuda-toolkit?

In other words: Can I use the NVIDIA "cuda toolkit" for a pytorch installation?

Context:

If you go through the "command helper" at https://pytorch.org/get-started/locally/, you can choose between cuda versions 9.2, 10.1, 10.2 and None.

Taking 10.2 can result in:

conda install pytorch torchvision cudatoolkit=10.2 -c pytorch

Taking "None" builds the following command, but then you also cannot use cuda in pytorch:

conda install pytorch torchvision cpuonly -c pytorch

Could I then use NVIDIA "cuda toolkit" version 10.2 as the conda cudatoolkit in order to make this command the same as if it was executed with cudatoolkit=10.2 parameter?

The question arose since pytorch installs a different version (10.2 instead of the most recent NVIDIA 11.0), and the conda install takes additional 325 MB. If both versions were 11.0 and the installation size was smaller, you might not even notice the possible difference. But now it is clear that conda carries its own cuda version which is independent from the NVIDIA one.

questionto42
  • 7,175
  • 4
  • 57
  • 90
  • 1
    2. no. The conda install of pytorch is a binary install. If those binaries are compiled against cuda 10.2 binaries, you cannot use that version of pytorch with cuda 11.0, regardless of whether it is in the conda env or not. – Robert Crovella Jul 30 '20 at 00:59
  • Linked with https://stackoverflow.com/questions/52378427/i-have-cuda-installed-on-win10-but-anaconda-let-me-to-reinstall-it-in-the-envir and https://stackoverflow.com/questions/52298146/cuda-home-in-pytorch-installation – questionto42 Aug 16 '20 at 12:54

2 Answers2

2

I imagine it is probably possible to get a conda-installed pytorch to use a non-conda-installed CUDA toolkit. I don't know how to do it, and in my experience, when using conda packages that depend on CUDA, its much easier just to provide a conda-installed CUDA toolkit, and let it use that, rather than anything else. This often means I have one CUDA toolkit installed inside conda, and one installed in the usual location.

However, regardless of how you install pytorch, if you install a binary package (e.g. via conda), that version of pytorch will depend on a specific version of CUDA (that it was compiled against, e.g. 10.2) and you cannot use any other version of CUDA, regardless of how or where it is installed, to satisfy that dependency.

Robert Crovella
  • 143,785
  • 11
  • 213
  • 257
  • 1
    This is still the most relevant answer, even though I had to accept the other one for the simple reason that pip seems to make it possible what is being asked for (if it is not about getting a version ahead of conda, which I took out). YET, it is clearly not recommended to use pip to manage parts of the standard conda installation. With @RobertCrovela being an NVIDIA employee and expert in CUDA, it is hard to un-accept this answer. – questionto42 Dec 22 '20 at 20:42
2

You can try to install PyTorch via Pip:

pip install torch torchvision

It is also official way of installing, available in "command helper" at https://pytorch.org/get-started/locally/.

It uses preinstalled CUDA and doesn't download own CUDA Toolkit. Also you can choose the version of CUDA to install PyTorch for:

pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio===0.7.2 -f https://download.pytorch.org/whl/torch_stable.html
Mikhail Lobanov
  • 416
  • 4
  • 6
  • Thanks, but this is a misunderstanding. The question is about the version lag of Pytorch *cudatoolkit* vs. NVIDIA *cuda toolkit* (mind the space) for the times *when there is a version lag*. Your mentioned link is the base for the question. At that time, only cudatoolkit 10.2 was on offer, while NVIDIA had already offered cuda toolkit 11.0. Now without a time lag, the official command helper also offers the 11.0 version. The question must now be read as if NVIDIA cuda toolkit 12.0 was out while you could still just take Pytorch cudatoolkit 11.0. I will try to edit the question accordingly. – questionto42 Dec 22 '20 at 10:42
  • 1
    Well, if we imagine that NVIDIA released CUDA 12 but in PyTorch official command helper there is only version for CUDA 11, this could mean that pytorch doesn't support CUDA 12 yet. But we can check URL that I mentioned in the answer (https://download.pytorch.org/whl/torch_stable.html) or (https://download.pytorch.org/whl/torch_nightly.html) and look for appropriate version. For example nightly builds could already support CUDA 12. Then we can install this version with `pip install torch+cu120 -f https://download.pytorch.org/whl/torch_nightly.html` – Mikhail Lobanov Dec 22 '20 at 13:08
  • The download link that you mentioned in the answer is the download link that was the base for the question. The nightly build is still a concept inside conda / pip. What I was curious about is whether I could use an install of NVIDIA "cuda toolkit" itself directly in Pytorch. And that does not happen with conda nightly build, since that builds its own binaries for pytorch. There will always be a full "cudatoolkit" version inside pytorch, independent from the installed NVIDIA "cuda toolkit". That is why your answer is not the answer to the question, though I understand why you post it here! – questionto42 Dec 22 '20 at 13:18
  • Upvote just for the hint at the nightly install, even though it does not answer the question. I admit that the question is neither easy to put nor to understand. – questionto42 Dec 22 '20 at 13:26
  • 2
    Yes, when installing pytorch from conda, conda installs own cuda toolkit, but pip doesn't do it. Without firstly installed NVIDIA "cuda toolkit" pytorch installed from pip would not work. So, I think that pip version of pytorch doesn't have full cuda toolkit inside itself. – Mikhail Lobanov Dec 22 '20 at 18:32
  • I have changed the question back since this is not about a version being ahead or not. It is just about using the NVIDIA cuda toolkit *in place of* the PyTorch cuda toolkit. Your answer is good in any case. The other answer is still right as well: do not try to leave the conda standard. Using pip is not recommended just to save 325 MB of space, since the conda package has specific dependencies and structures. Using pip to go from 10.2 to 11.0 is thus not recommended either. Your answer is accepted now, but paradoxically, it is not recommended ;). – questionto42 Dec 22 '20 at 20:29