Updating PyTorch

Atcold: <h1>Premise</h1>
<p>I just wanted to pin this topic, so that it can be used for future reference.</p>
<h1>Recommendations</h1>
<p>If you are a <em>PyTorch</em> user, I would recommend to add <code>soumith</code> as source server to your <em>Anaconda</em> (or <em>Miniconda</em>)</p>
<pre><code class="lang-auto">conda config --add channels soumith
</code></pre>
<p>Then, to get the latest <em>PyTorch</em> and <em>vision</em> package via <code>conda</code>, you can simply</p>
<pre><code class="lang-auto">conda update pytorch torchvision
</code></pre>
<p><code>PyTorch</code> will be installed in</p>
<pre><code class="lang-auto">$HOME/anaconda3/lib/python3.5/site-packages/torch
</code></pre>
<p>this is because you <strong>want</strong> to use <em>Python</em> 3 (since <em>Python</em> 2 is going to die soon).</p>
<h1>Questions</h1>
<p>If you want the latest <em>PyTorch</em> update, I believe you should install from source. (Am I correct? Will it be installed in the same directory, like when we were <code>luarocks make</code> the old <em>Torch</em>?)</p>
<p>The location of <code>torchvision</code> is… unknown. I couldn’t find where <em>Anaconda</em> put it. <code>torchvision.__file__</code> says</p>
<pre><code class="lang-auto">$HOME/anaconda3/lib/python3.5/site-packages/torchvision-0.1.6-py3.5.egg/torchvision/__init__.py
</code></pre>
<p>but such location does not exist. Nevertheless, my IDE can find those files in that location, when exploring the source code.</p>
<p>Another thing I’m puzzled about is the following location a <code>RuntimeError</code> spits out</p>
<pre><code class="lang-auto">/data/users/soumith/miniconda2/conda-bld/pytorch-0.1.7_1485445763020/work/torch/lib/THNN/generic/SpatialConvolutionMM.c
</code></pre>

apaszke: <ol>
<li>Yes, installing it from source will install it in the same place as anaconda does.</li>
<li>
<code>torchvision</code> should be exactly there where <code>__file__</code> shows you.</li>
<li>When you compile the libs, the compiler will put the compile time path of the .c files in the error messages. Since it’s Soumith who’s responsible for building the binaries, his name shows up there. See <a href="https://github.com/pytorch/pytorch/issues/465">this issue</a>.</li>
</ol>

Atcold: <p>About 2, that’s kind of not what I see here.</p>
<pre><code class="lang-auto">&gt;&gt;&gt; f = open(torchvision.__file__)
Traceback (most recent call last):
  File "/home/atcold/anaconda3/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2881, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "&lt;ipython-input-95-16f43d841fa3&gt;", line 1, in &lt;module&gt;
    f = open(torchvision.__file__)
NotADirectoryError: [Errno 20] Not a directory: '/home/atcold/anaconda3/lib/python3.5/site-packages/torchvision-0.1.6-py3.5.egg/torchvision/__init__.py'
&gt;&gt;&gt; f2 = open(torch.__file__)
# succeed
</code></pre>

apaszke: <p>How about <code>/home/atcold/anaconda3/lib/python3.5/site-packages/torchvision/__init__.py</code>? If that doesn’t exist you can use <code>find</code> (terminal command) to look for a <code>torchvision</code> directory under <code>/home/atcold/anaconda3/lib/python3.5/site-packages</code>. It has be somewhere there.</p>

Atcold: <p>Oh, maybe I’ve figured it out…</p>
<pre><code class="lang-auto">atcold@GPU0 ~/anaconda3/lib/python3.5/site-packages $ ls -daF torch*
torch/  torch-0.1-py3.5.egg-info/  torchvision-0.1.6-py3.5.egg  torchvision.pth
</code></pre>
<p>There is no directory. Just a <code>pth</code> and an <code>egg</code>.</p>

apaszke: <p>Oh yeah, I think it’s zipped in an egg.</p>

Hubert: <p>this is no longer working.</p>
<p>PackageNotFoundError: Package not found: ‘pytorch’</p>

antspy: <p>Hi,</p>
<p>is this still relevant? I added soumith to my conda channels but pytorch 0.3 (released a few days ago) still does not show up when I run <code>conda update pytorch torchvision</code></p>

jdhao: <p>FYI. In order to install the latest <code>torch</code> and <code>torchvision</code>, now, you do</p>
<pre><code class="lang-auto">conda install pytorch torchvision -c pytorch
</code></pre>
<p>You can also read this post ( <a href="https://discuss.pytorch.org/t/pytorch-0-3-version-is-released/10782/13?u=jdhao">Pytorch 0.3 version is released</a>).</p>

omair-kg: <p>For me this did not work. It always tried to downgrade my pytorch and torchvision to some rather ancient version.</p>
<p>I installed it again in a separate environment using pip then which worked.</p>

jdhao: <p>What about uninstall original <code>torch</code> and <code>torchvision</code> and install again?</p>

omair-kg: <p>Tried that aswell. So far only Pip seems to work for me.</p>

manozzm: <p>This worked for me!</p>
<blockquote>
<p>conda update pytorch torchvision -c pytorch</p>
</blockquote>
<p>The following NEW packages will be INSTALLED:</p>
<pre><code>cudatoolkit: 8.0-3
</code></pre>
<p>The following packages will be UPDATED:</p>
<pre><code>pytorch:     0.2.0-py36h53baedd_4cu80 soumith [cuda80] --&gt; 0.3.0-py36_cuda8.0.61_cudnn7.0.3h37a80b5_4 pytorch
torchvision: 0.1.9-py36h7584368_1     soumith --&gt; 0.2.0-py36h17b6947_1                       pytorch
</code></pre>

shehabk: <p>If the dependencies are not met, conda will not update to recent pytorch. What I did was the following.</p>
<ol>
<li>conda install pytorch=0.3.0 -c pytorch ( This gave the missing dependencies)</li>
<li>Install the missing dependencies from Anaconda Cloud ( in my case they where numba, blaze )</li>
<li>conda update pytorch torchvision -c pytorch</li>
</ol>

Atcold: <aside class="quote no-group" data-username="Hubert" data-post="7" data-topic="309" data-full="true">
<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/h/9d8465/48.png" class="avatar"> Hubert:</div>
<blockquote>
<p>this is no longer working.</p>
<p>PackageNotFoundError: Package not found: ‘pytorch’</p>
</blockquote>
</aside>
<p>I can no longer edit the original post. Now you need to use this command instead (basically, you need to replace <code>soumith</code> with <code>pytorch</code>).</p>
<pre><code class="lang-auto">conda config --add channels pytorch
</code></pre>

Atcold: <aside class="quote no-group" data-username="antspy" data-post="8" data-topic="309" 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/antspy/48/3475_2.png" class="avatar"> antspy:</div>
<blockquote>
<p>Hi,</p>
<p>is this still relevant? I added soumith to my conda channels but pytorch 0.3 (released a few days ago) still does not show up when I run <code>conda update pytorch torchvision</code></p>
</blockquote>
</aside>
<p>Yeah, the <code>soumith</code> channel is now called <code>pytorch</code>. See post above.</p>

rasbt: <p>Just a general note, it’s probably better to do the <code>torch.__file__</code> checks with via <code>isfile</code> and <code>abspath</code>:</p>
<pre><code class="lang-auto">&gt;&gt;&gt; import torch
&gt;&gt;&gt; import os
&gt;&gt;&gt; os.path.isfile(torch.__file__)
True
&gt;&gt;&gt; os.path.abspath(torch.__file__)
'/Users/sebastian/miniconda3/lib/python3.6/site-packages/torch/__init__.py'
</code></pre>

stoddur: <p>Hey guys. What is the recommended way of upgrading to PyTorch V1.0 using conda? After adding the pytorch channel and trying to update this message appears:</p>
<p><code># All requested packages already installed.</code></p>
<p>Any suggestions?</p>

ptrblck: <p>I would recommend to create a new conda environment and install there your 1.0 preview.<br>
In that way you can just delete it once the 1.0 stable version will be released and your other code is still executable.<br>
Have a look <a href="https://conda.io/docs/user-guide/tasks/manage-environments.html">here</a> to learn how to manage environments.</p>

stoddur: <p>Thanks for your reply. How does one go about installing the 1.0 preview? After installing the nightly version from source I end up with version 0.4.1</p>