Updating PyTorch -- Is there an "Official" Way?

navneethc: <p>Windows 10<br>
(mini)conda<br>
Pytorch 1.5.0 + CUDA</p>
<p>I’m trying to find an “offically” recommended way to update PyTorch and associated libraries to the latest stable version (from another stable version), but almost all the results I come across are at least a few years old and mostly workarounds to specific problems, or relates to pip, both here and at StackOverflow, so I started a new thread.</p>
<ol>
<li>
<p>What is the command to update only PyTorch and related libraries?</p>
</li>
<li>
<p>Would <code>conda update --all</code> take care of this, if I also wish to update Python and Jupyter, for example? (PyTorch has its own dedicated environment.)</p>
</li>
</ol>

ptrblck: <p>I generally don’t bother with updating PyTorch, but just uninstall the old version and install the latest one.<br>
I’m not even sure if an “update” would do something different.</p>

navneethc: <p>Thanks for the reply. In the interim, I’d tried comparing the differences between <code>conda update pytorch torchvision cudatoolkit -c pytorch</code> and <code>conda update --all</code>. It turned out that the former updates everything except Python and Matplotlib. So, I ran both commands in that order, but now when I try to import PyTorch I get an error about VS Runtime.</p>
<pre><code class="lang-auto">(pytorch) PS C:\Users\Navneeth&gt; python
Python 3.8.5 (default, Sep  3 2020, 21:29: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
Microsoft Visual C++ Redistributable is not installed, this may lead to the DLL load failure.
                 It can be downloaded at https://aka.ms/vs/16/release/vc_redist.x64.exe
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "C:\Users\Navneeth\Miniconda3\envs\pytorch\lib\site-packages\torch\__init__.py", line 127, in &lt;module&gt;
    raise err
OSError: [WinError 126] The specified module could not be found. Error loading "C:\Users\Navneeth\Miniconda3\envs\pytorch\lib\site-packages\torch\lib\asmjit.dll" or one of its dependencies.
</code></pre>
<p>This is weird since conda automatically installs the runtime whenever an environment is created.</p>
<p>This is the relevant bit from the output of <code>conda list</code>:</p>
<pre><code class="lang-auto">vc                        14.1                 h0510ff6_4
vs2015_runtime            14.16.27012          hf0eaf9b_3
</code></pre>

navneethc: <p>Solution/Workaround here: <a href="https://discuss.pytorch.org/t/problems-after-installing-pytorch-on-windows/91351/5" class="inline-onebox">Problems after installing pytorch on windows</a></p>

datacuber: <p>If I can bring back to life this thread. I understand from here that there is no official way to update Pytorch. But any suggestion instead? In my case I installed Pytorch 1.7.1 when, at that time, I had CUDA 10.1. Now my system automatically has been updating and now I have CUDA 11.2 with no problems. I have only seen installation instructions until CUDA 11.1. Am i suppose to have any compatibility problems with this?</p>
<p>I don’t want to create a new conda environment if not necessary, since as I remember Pytorch installation took a long while and if there is any way to properly carry out the process it would be good to know…</p>
<p>Thanks in advace,</p>
<p>Alfonso</p>

ptrblck: <aside class="quote no-group" data-username="datacuber" data-post="5" data-topic="97496">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/datacuber/48/40328_2.png" class="avatar"> datacuber:</div>
<blockquote>
<p>now I have CUDA 11.2 with no problems. I have only seen installation instructions until CUDA 11.1. Am i suppose to have any compatibility problems with this?</p>
</blockquote>
</aside>
<p>The PyTorch binaries ship with their own CUDA runtime (in the mentioned case with CUDA11.1) and your local CUDA toolkit will only be used if you build PyTorch from source or compile custom CUDA extensions. To run PyTorch on the GPU, you would need to have a compatible driver, which should be the case in your setup.</p>
<aside class="quote no-group" data-username="datacuber" data-post="5" data-topic="97496">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/datacuber/48/40328_2.png" class="avatar"> datacuber:</div>
<blockquote>
<p>I don’t want to create a new conda environment if not necessary, since as I remember Pytorch installation took a long while and if there is any way to properly carry out the process it would be good to know…</p>
</blockquote>
</aside>
<p>I’m not sure I understand this concern, since you would have to download the binaries in any case.</p>

navneethc: <p>To update PyTorch and CUDA alone, I’ve stuck to<br>
<code>conda update pytorch torchvision cudatoolkit -c pytorch</code><br>
since this thread. I update other libraries for Jupyter and visualisation, for example, thereafter.</p>

ptrblck: <p>Good to see <code>conda update</code> is also working! Did you see any advantage over reinstalling it, i.e. were some packages only partially pulled?</p>

navneethc: <p>An obvious advantage is fewer steps. <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"> Apart from that I think the whole process was uneventful (which is a good thing). It’s been a while since I bumped up a version; I’ll make sure to update this thread if something happens next time. <img src="https://discuss.pytorch.org/images/emoji/apple/smile.png?v=9" title=":smile:" class="emoji" alt=":smile:"></p>

Brando_Miranda: <p><a class="mention" href="/u/ptrblck">@ptrblck</a> mind sharing the commands you ran? <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=12" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<hr>
<p>I think this works:</p>
<pre><code class="lang-auto">pip install  torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113 --upgrade
</code></pre>

ptrblck: <p>As described before, I don’t try to update the binaries but just uninstall them and install a new release:</p>
<aside class="quote no-group" data-username="ptrblck" data-post="2" data-topic="97496" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/48/1823_2.png" class="avatar"> ptrblck:</div>
<blockquote>
<p>I generally don’t bother with updating PyTorch, but just uninstall the old version and install the latest one.<br>
I’m not even sure if an “update” would do something different.</p>
</blockquote>
</aside>
<p>I’m using the install commands from <a href="https://pytorch.org/get-started/locally/">here</a> or I explicitly install a release candidate I’m working on (e.g. for a CUDA update).</p>

JinroTorch: <p>Hello! I am using conda, and what has worked for me was letting conda update based on the install command. On the same pytorch environment,  run this:</p>
<pre><code class="lang-auto">conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia
</code></pre>

Super_Kai: <p>I couldn’t update pytorch with the commad below:</p>
<pre><code class="lang-auto">conda update pytorch
</code></pre>
<p>But, I could update pytorch by uninstalling and installing pytorch with the commands below. *I saw <a href="https://anaconda.org/pytorch/pytorch" rel="noopener nofollow ugc">anaconda.org</a> to install pytorch:</p>
<pre><code class="lang-auto">conda uninstall pytorch
</code></pre>
<pre><code class="lang-auto">conda install pytorch::pytorch
</code></pre>
<p>Be careful, the command below without <code>::pytorch</code> doesn’t install the latest pytorch:</p>
<pre><code class="lang-auto">conda install pytorch
</code></pre>