Issue with pip installation of PyTorch

Lav: <p>A few months ago, I installed <a href="https://github.com/chemprop/chemprop#installation" rel="noopener nofollow ugc">chemprop</a> via Visual Studio Code, Windows 10 64 bit).<br>
The installation instructions say:<br>
“on machines with GPUs, you may need to manually install a GPU-enabled version of PyTorch by following the instructions here”, where here links to the PyTorch Start Locally page.<br>
I have a Nvidia GeForce RTX 3050 Ti laptop GPU.<br>
At the time, the PyTorch pip installation code was:</p>
<pre><code>pip3 install torch==1.11.0+cu113 torchvision==0.12.0+cu113 torchaudio===0.11.0+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html
</code></pre>
<p>which I used, and it worked. The basic tests in python said that cuda was available, and:</p>
<pre><code>torch.__version__
'1.11.0+cu113'

torch.cuda.get_arch_list()
['sm_37', 'sm_50', 'sm_60', 'sm_61', 'sm_70', 'sm_75', 'sm_80', 'sm_86', 'compute_37']
</code></pre>
<p>Chemprop also correctly called the GPU/cuda when necessary.</p>
<p>It is actually weird that this worked, because <a href="https://discuss.pytorch.org/t/nvidia-geforce-rtx-3050-ti-laptop-gpu-with-cuda-capability-sm-86-is-not-compatible-with-the-current-pytorch-installation/143837/2">this post</a> seems to say that my python output points to a 10.2 ‘runtime’, whatever that means (no idea, sorry, not an IT expert).<br>
Plus, my current GPU driver is a bit old, and nvidia-smi says the max supported cuda is 11.2.<br>
But OK, I only know that it works, somehow.</p>
<p>Now, a new version of chemprop came out, so I installed it (in a new conda environment), went back to PyTorch Start Locally find the installation code, and now it looks like this:</p>
<pre><code>pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113
</code></pre>
<p>Thinking that it was better to use the up-to-date pip installation code, I went ahead and ran it.<br>
And the GPU was never again seen or used by torch or by chemprop (in the new environment; in the old one it still worked, luckily).</p>
<pre><code>torch.__version__
'1.11.0+cu113'
</code></pre>
<p>but:</p>
<pre><code>torch.cuda.is_available()
False
</code></pre>
<p>I looked at a lot of posts, some arguing that one should update the GPU driver, some describing incredibly complicated developer installations of separate packages, etc.:</p>
<p>[sorry, I am manually breaking the links otherwise your system says I cannot post as a new user]</p>
<p>ttps://stackoverflow.com/questions/69204737/torch-cuda-is-available-returns-false-why</p>
<p>ttps://stackoverflow.com/questions/60987997/why-torch-cuda-is-available-returns-false-even-after-installing-pytorch-with/61034368#61034368</p>
<p>ttps://stackoverflow.com/questions/70831932/cant-connect-to-gpu-when-building-pytorch-projects</p>
<p>Having no expertise whatsoever and not wanting to risk breaking my system, I simply tried removing the new conda environment, repeating the installation of chemprop, and then running the above <em>old</em> pip installation code for PyTorch.<br>
This seemed to work. Now the tests are giving again the expected answers.</p>
<p>Does anybody know what may be going on?<br>
Why is the new pip installation code not working, whereas the old one does, despite the apparent runtime conflict?</p>
<p>I have sort of resolved my issue, but I thought it may be useful to post this, in case my solution is not good/stable, and/or there is a better way to handle this.</p>
<p>E.g. in the above PyTorch discussion I linked, the user ends up saying “You were right. The env I was using had an incorrect version. Thanks go it working.”.<br>
That’s very nice, but from my point of view as a non-expert, I have absolutely no idea how I can decide what ‘version’ my ‘env’ is using: I just run the code that is provided on the website and sort of hope it does the job… so maybe if someone could please explain what needs to be done, it would be great.</p>
<p>Thanks!</p>

ptrblck: <aside class="quote no-group" data-username="Lav" data-post="1" data-topic="155973">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/l/8797f3/48.png" class="avatar"> Lav:</div>
<blockquote>
<p>It is actually weird that this worked, because <a href="https://discuss.pytorch.org/t/nvidia-geforce-rtx-3050-ti-laptop-gpu-with-cuda-capability-sm-86-is-not-compatible-with-the-current-pytorch-installation/143837/2">this post</a> seems to say that my python output points to a 10.2 ‘runtime’, whatever that means (no idea, sorry, not an IT expert).</p>
</blockquote>
</aside>
<p>No, your output does not point to a CUDA10.2 runtime, as the <code>sm_80</code> and <code>sm_86</code> architectures are available and no errors are raised about the lack of Ampere support in the build.</p>
<aside class="quote no-group" data-username="Lav" data-post="1" data-topic="155973">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/l/8797f3/48.png" class="avatar"> Lav:</div>
<blockquote>
<p>Plus, my current GPU driver is a bit old, and nvidia-smi says the max supported cuda is 11.2.<br>
But OK, I only know that it works, somehow.</p>
</blockquote>
</aside>
<p><code>nvidia-smi</code> points to the CUDA Toolkit version which was released with the driver, which is not the max. version as CUDA11.x is compatible between minor releases (or at least it should be as long as the libraries are sticking to the support).</p>
<aside class="quote no-group" data-username="Lav" data-post="1" data-topic="155973">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/l/8797f3/48.png" class="avatar"> Lav:</div>
<blockquote>
<p>Does anybody know what may be going on?</p>
</blockquote>
</aside>
<p>No idea and I haven’t seen the issue before. Could you check the links where the binaries are downloaded from as I would expect these are the same (just accessed via different install commands)?</p>

Lav: <p>Thank you <a class="mention" href="/u/ptrblck">@ptrblck</a> , I had clearly not understood this ‘runtime’ thing, as I suspected.<br>
Note however that the torch.cuda.get_arch_list() output I reported is the one where I used the <em>old</em> installation command, i.e. the one where the system works. When I had used the <em>new</em> command, the output was different. And I had also tried running a python torch command (can’t remember what) that was supposed to produce a more informative output, and indeed it said something along the lines that the GPU was not being used due to a wrong configuration.<br>
I could make a new env and repeat the process with the new command, to get the exact output and share it, if that can help disentangle this story.</p>
<p>For the rest, the sentence “check the links where the binaries are” unfortunately does not mean much to me - as I mentioned, I really am no expert in anything related to IT.<br>
I only know two things: 1) I needed to install PyTorch because the statistical modelling software chemprop requires it to use the machine’s Nvidia GPU; 2) the most recent PyTorch installation command, as provided by the PyTorch website, failed to make my GPU work correctly, whereas the old command succeeded.</p>
<p>This might be specific to my own GPU though, because I also installed chemprop + PyTorch in a different machine with a more powerful and up-to-date GPU, and I did not seem to have any problems there, with the new PyTorch command.</p>
<p>Thanks</p>

ptrblck: <aside class="quote no-group" data-username="Lav" data-post="3" data-topic="155973">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/l/8797f3/48.png" class="avatar"> Lav:</div>
<blockquote>
<p>I could make a new env and repeat the process with the new command, to get the exact output and share it, if that can help disentangle this story.</p>
</blockquote>
</aside>
<p>Yes, this would be great. Don’t worry about not understanding the details and sorry for not being clear enough.<br>
In the end, the install command should work on your setup, so could you create a new environment, use the new (broken) command, and post the full install logs here, so that I could take a look at it, please?</p>

Lav: <p>OK, done.<br>
I installed chemprop again using Option 1 <a href="https://github.com/chemprop/chemprop" rel="noopener nofollow ugc">here</a>, into conda environment ‘chemprop151_test’.<br>
I cloned this environment by:</p>
<pre><code>conda create --name chemprop151_test_copy --clone chemprop151_test
</code></pre>
<p>Then I installed PyTorch with cuda 11.3 in chemprop151_test, i.e. activated the environtment in conda and did:</p>
<pre><code>pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113
</code></pre>
<p>Output:</p>
<pre><code>Looking in indexes: https://pypi.org/simple, https://download.pytorch.org/whl/cu113
Requirement already satisfied: torch in c:\users\username\miniconda3\envs\chemprop151_test\lib\site-packages (1.12.0)
Collecting torchvision
  Using cached https://download.pytorch.org/whl/cu113/torchvision-0.13.0%2Bcu113-cp38-cp38-win_amd64.whl (4.7 MB)
Collecting torchaudio
  Using cached https://download.pytorch.org/whl/cu113/torchaudio-0.12.0%2Bcu113-cp38-cp38-win_amd64.whl (1.2 MB)
Requirement already satisfied: typing-extensions in c:\users\username\miniconda3\envs\chemprop151_test\lib\site-packages (from torch) (4.3.0)
Requirement already satisfied: requests in c:\users\username\miniconda3\envs\chemprop151_test\lib\site-packages (from torchvision) (2.28.1)
a3\envs\chemprop151_test\lib\site-packages (from torchvision) (9.2.0)
Requirement already satisfied: idna&lt;4,&gt;=2.5 in c:\users\username\miniconda3\envs\chemprop151_test\lib\site-packages (from requests-&gt;torchvision) (3.3)
Requirement already satisfied: urllib3&lt;1.27,&gt;=1.21.1 in c:\users\username\miniconda3\envs\chemprop151_test\lib\site-packages (from requests-&gt;torchvision) (1.26.10)
Requirement already satisfied: certifi&gt;=2017.4.17 in c:\users\username\miniconda3\envs\chemprop151_test\lib\site-packages (from requests-&gt;torchvision) (2022.6.15)
Requirement already satisfied: charset-normalizer&lt;3,&gt;=2 in c:\users\username\miniconda3\envs\chemprop151_test\lib\site-packages (from requests-&gt;torchvision) (2.1.0)
Installing collected packages: torchvision, torchaudio
Successfully installed torchaudio-0.12.0+cu113 torchvision-0.13.0+cu113

python
Python 3.8.13 (default, Mar 28 2022, 06:59:08) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import torch
&gt;&gt;&gt; torch.cuda.is_available()
False
&gt;&gt;&gt; torch.__version__
'1.12.0+cpu'
&gt;&gt;&gt; torch.cuda.get_arch_list()
[]
</code></pre>
<p>Then I installed PyTorch with cuda 11.6 in chemprop151_test_copy, i.e. activated the environtment in conda and did:</p>
<pre><code>pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu116
</code></pre>
<p>Output:</p>
<pre><code>Looking in indexes: https://pypi.org/simple, https://download.pytorch.org/whl/cu116
Requirement already satisfied: torch in c:\users\username\miniconda3\envs\chemprop151_test_copy\lib\site-packages (1.12.0)
Collecting torchvision
  Downloading https://download.pytorch.org/whl/cu116/torchvision-0.13.0%2Bcu116-cp38-cp38-win_amd64.whl (2.6 MB)
     |████████████████████████████████| 2.6 MB 1.6 MB/s
Collecting torchaudio
  Downloading https://download.pytorch.org/whl/cu116/torchaudio-0.12.0%2Bcu116-cp38-cp38-win_amd64.whl (1.2 MB)
     |████████████████████████████████| 1.2 MB 6.4 MB/s
Requirement already satisfied: typing-extensions in c:\users\username\miniconda3\envs\chemprop151_test_copy\lib\site-packages (from torch) (4.3.0)
Requirement already satisfied: numpy in c:\users\username\miniconda3\envs\chemprop151_test_copy\lib\site-packages (from torchvision) (1.23.0)
Requirement already satisfied: requests in c:\users\username\miniconda3\envs\chemprop151_test_copy\lib\site-packages (from torchvision) (2.28.1)
Requirement already satisfied: pillow!=8.3.*,&gt;=5.3.0 in c:\users\username\miniconda3\envs\chemprop151_test_copy\lib\site-packages (from torchvision) (9.2.0)
Requirement already satisfied: charset-normalizer&lt;3,&gt;=2 in c:\users\username\miniconda3\envs\chemprop151_test_copy\lib\site-packages (from requests-&gt;torchvision) (2.1.0)
Requirement already satisfied: idna&lt;4,&gt;=2.5 in c:\users\username\miniconda3\envs\chemprop151_test_copy\lib\site-packages (from requests-&gt;torchvision) (3.3)
Requirement already satisfied: urllib3&lt;1.27,&gt;=1.21.1 in c:\users\username\miniconda3\envs\chemprop151_test_copy\lib\site-packages (from requests-&gt;torchvision) (1.26.10)
Requirement already satisfied: certifi&gt;=2017.4.17 in c:\users\username\miniconda3\envs\chemprop151_test_copy\lib\site-packages (from requests-&gt;torchvision) (2022.6.15)
Installing collected packages: torchvision, torchaudio
Successfully installed torchaudio-0.12.0+cu116 torchvision-0.13.0+cu116

python
Python 3.8.13 (default, Mar 28 2022, 06:59:08) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import torch
&gt;&gt;&gt; torch.cuda.is_available()
False
&gt;&gt;&gt; torch.__version__
'1.12.0+cpu'
&gt;&gt;&gt; torch.cuda.get_arch_list()
[]
</code></pre>
<p>When I installed PyTorch via the old code:</p>
<pre><code>pip3 install torch==1.11.0+cu113 torchvision==0.12.0+cu113 torchaudio===0.11.0+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html
</code></pre>
<p>Output:</p>
<pre><code>Looking in links: https://download.pytorch.org/whl/cu113/torch_stable.html
Collecting torch==1.11.0+cu113
  Using cached https://download.pytorch.org/whl/cu113/torch-1.11.0%2Bcu113-cp38-cp38-win_amd64.whl (2186.1 MB)
Collecting torchvision==0.12.0+cu113
  Using cached https://download.pytorch.org/whl/cu113/torchvision-0.12.0%2Bcu113-cp38-cp38-win_amd64.whl (5.4 MB)
Collecting torchaudio===0.11.0+cu113
  Using cached https://download.pytorch.org/whl/cu113/torchaudio-0.11.0%2Bcu113-cp38-cp38-win_amd64.whl (573 kB)
Requirement already satisfied: typing-extensions in c:\users\username\miniconda3\envs\chemprop151_oldpytorch\lib\site-packages (from torch==1.11.0+cu113) (4.3.0)
Requirement already satisfied: numpy in c:\users\username\miniconda3\envs\chemprop151_oldpytorch\lib\site-packages (from torchvision==0.12.0+cu113) (1.23.0)
Requirement already satisfied: requests in c:\users\username\miniconda3\envs\chemprop151_oldpytorch\lib\site-packages (from torchvision==0.12.0+cu113) (2.28.1)
Requirement already satisfied: pillow!=8.3.*,&gt;=5.3.0 in c:\users\username\miniconda3\envs\chemprop151_oldpytorch\lib\site-packages (from torchvision==0.12.0+cu113) (9.2.0)
Requirement already satisfied: urllib3&lt;1.27,&gt;=1.21.1 in c:\users\username\miniconda3\envs\chemprop151_oldpytorch\lib\site-packages (from requests-&gt;torchvision==0.12.0+cu113) (1.26.10)
Requirement already satisfied: charset-normalizer&lt;3,&gt;=2 in c:\users\username\miniconda3\envs\chemprop151_oldpytorch\lib\site-packages (from requests-&gt;torchvision==0.12.0+cu113) (2.1.0)
Requirement already satisfied: idna&lt;4,&gt;=2.5 in c:\users\username\miniconda3\envs\chemprop151_oldpytorch\lib\site-packages (from requests-&gt;torchvision==0.12.0+cu113) (3.3)
Requirement already satisfied: certifi&gt;=2017.4.17 in c:\users\username\miniconda3\envs\chemprop151_oldpytorch\lib\site-packages (from requests-&gt;torchvision==0.12.0+cu113) (2022.6.15)
Installing collected packages: torch, torchvision, torchaudio
  Attempting uninstall: torch
    Found existing installation: torch 1.12.0
    Uninstalling torch-1.12.0:
      Successfully uninstalled torch-1.12.0
Successfully installed torch-1.11.0+cu113 torchaudio-0.11.0+cu113 torchvision-0.12.0+cu113

python
Python 3.8.13 (default, Mar 28 2022, 06:59:08) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import torch
&gt;&gt;&gt; torch.cuda.is_available()
True
&gt;&gt;&gt; torch.__version__
'1.11.0+cu113'
&gt;&gt;&gt; torch.cuda.get_arch_list()
['sm_37', 'sm_50', 'sm_60', 'sm_61', 'sm_70', 'sm_75', 'sm_80', 'sm_86', 'compute_37']
</code></pre>
<p>I hope there is something in this that explains why the old installation works and the new one doesn’t.</p>
<p>Thanks again for your time!</p>

ptrblck: <p>Thanks for the logs.</p>
<p>Let’s go through some points to isolate the issue.</p>
<p>The main difference between the “breaking” and “working” install commands is the version specification for each package:</p>
<pre><code class="lang-auto"># broken 
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu116

# working
pip3 install torch==1.11.0+cu113 torchvision==0.12.0+cu113 torchaudio===0.11.0+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html
</code></pre>
<p>as well as the CUDA runtime for <code>cu116</code>.</p>
<p>Now let’s check what the “broken” commands are doing:</p>
<pre><code class="lang-auto">Looking in indexes: https://pypi.org/simple, https://download.pytorch.org/whl/cu113
Requirement already satisfied: torch in c:\users\username\miniconda3\envs\chemprop151_test\lib\site-packages (1.12.0)
...
Looking in indexes: https://pypi.org/simple, https://download.pytorch.org/whl/cu116
Requirement already satisfied: torch in c:\users\username\miniconda3\envs\chemprop151_test_copy\lib\site-packages (1.12.0)
</code></pre>
<p>So it looks as if the <code>torch</code> requirement is already satisfied and PyTorch was already installed.<br>
Checking the <a href="https://github.com/chemprop/chemprop/blob/b831fdad2a9546710c35e195ce23df76dbcf52dd/environment.yml"><code>environment.yml</code></a> also shows this requirement:</p>
<pre><code class="lang-auto">pytorch&gt;=1.4.0
</code></pre>
<p>Your quick <code>torch.__version__</code> check also shows that PyTorch is indeed installed from the latest stable release, but the CPU-only version:</p>
<pre><code class="lang-auto">&gt;&gt;&gt; torch.__version__
'1.12.0+cpu'
</code></pre>
<p><code>pip install</code> might not be smart enough to figure out that you want to install the PyTorch wheels with the CUDA runtime, checks for an already installed <code>torch</code> package, finds it, and skips the install command for <code>torch</code>.</p>
<p>However, if you specify the version directly via:</p>
<pre><code class="lang-auto">pip3 install torch==1.11.0+cu113 ...
</code></pre>
<p>the install command will see a version mismatch (note that the requirements from <code>chemprop</code> installed <code>torch==1.12.0+cpu</code>) and will download it:</p>
<pre><code class="lang-auto">Looking in links: https://download.pytorch.org/whl/cu113/torch_stable.html
Collecting torch==1.11.0+cu113
  Using cached https://download.pytorch.org/whl/cu113/torch-1.11.0%2Bcu113-cp38-cp38-win_amd64.whl (2186.1 MB)
</code></pre>
<p>Note also that the previously CPU-only version will be uninstalled in this process:</p>
<pre><code class="lang-auto">Installing collected packages: torch, torchvision, torchaudio
  Attempting uninstall: torch
    Found existing installation: torch 1.12.0
    Uninstalling torch-1.12.0:
      Successfully uninstalled torch-1.12.0
Successfully installed torch-1.11.0+cu113 ...
</code></pre>
<p>which explains why the version tag works for you.</p>
<p>In summary: the previous command should also work, if you would uninstall the CPU-only version manually before running the install command.<br>
I hope it helps.</p>

Lav: <p>Thanks, yes, it makes perfect sense. So the problem is that chemprop’s installation puts there a CPU version of Torch, which is not replaced by the new PyTorch installation command.<br>
I would argue that the issue comes a bit from both sides then, because chemprop is correct in installing Torch-CPU, so the software can work even for users who don’t have GPU’s: but the previous PyTorch installation command made sure to install the correct version of Torch, regardless of what was there before. Perhaps this should always be the case, or am I wrong? Won’t a user who installs PyTorch by this command generally want the correct/best/up to date version of Torch to be installed?<br>
Anyway, I wonder why the new command instead worked perfectly OK in the other machine, because the procedure I followed was 100% the same.</p>
<p>We can call it problem solved, assuming that I find the command to uninstall Torch-CPU from chemprop. I will have a look at the manual.</p>
<p>Thanks!</p>

ptrblck: <aside class="quote no-group" data-username="Lav" data-post="7" data-topic="155973">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/l/8797f3/48.png" class="avatar"> Lav:</div>
<blockquote>
<p>Won’t a user who installs PyTorch by this command generally want the correct/best/up to date version of Torch to be installed?</p>
</blockquote>
</aside>
<p>Yes, I think you are right and <code>pip</code> already thinks you are on the latest and greatest PyTorch version (<code>1.12.0</code> was already found). However, I also think that the version is only checked and <code>pip</code> is not aware of the CUDA runtimes unfortunately and thus doesn’t detect that you want to use <code>1.12.0+cu113</code> instead.</p>
<aside class="quote no-group" data-username="Lav" data-post="7" data-topic="155973">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/l/8797f3/48.png" class="avatar"> Lav:</div>
<blockquote>
<p>Anyway, I wonder why the new command instead worked perfectly OK in the other machine, because the procedure I followed was 100% the same.</p>
</blockquote>
</aside>
<p>If the same exact workflow produced different result on another machine, I would guess that <code>pip</code> might have been able to detect the version conflict, but you should check the install logs again (and post them here) so that I could take a look at it.</p>

Lav: <p>Yeah actually I was wrong: the procedure I used in the linux machine was not 100% the same.<br>
I stopped after installing chemprop, because the torch.cuda.is_available() already said True, and:</p>
<pre><code class="lang-auto">torch.__version__
'1.12.0+cu102'
torch.cuda.get_arch_list()
['sm_37', 'sm_50', 'sm_60', 'sm_60']
</code></pre>
<p>Maybe this means I am not using the latest or best version, but as long as chemprop works…</p>