Updating PyTorch

Premise

I just wanted to pin this topic, so that it can be used for future reference.

Recommendations

If you are a PyTorch user, I would recommend to add soumith as source server to your Anaconda (or Miniconda)

conda config --add channels soumith

Then, to get the latest PyTorch and vision package via conda, you can simply

conda update pytorch torchvision

PyTorch will be installed in

$HOME/anaconda3/lib/python3.5/site-packages/torch

this is because you want to use Python 3 (since Python 2 is going to die soon).

Questions

If you want the latest PyTorch update, I believe you should install from source. (Am I correct? Will it be installed in the same directory, like when we were luarocks make the old Torch?)

The location of torchvision is… unknown. I couldn’t find where Anaconda put it. torchvision.__file__ says

$HOME/anaconda3/lib/python3.5/site-packages/torchvision-0.1.6-py3.5.egg/torchvision/__init__.py

but such location does not exist. Nevertheless, my IDE can find those files in that location, when exploring the source code.

Another thing I’m puzzled about is the following location a RuntimeError spits out

/data/users/soumith/miniconda2/conda-bld/pytorch-0.1.7_1485445763020/work/torch/lib/THNN/generic/SpatialConvolutionMM.c
10 Likes
  1. Yes, installing it from source will install it in the same place as anaconda does.
  2. torchvision should be exactly there where __file__ shows you.
  3. 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 this issue.
1 Like

About 2, that’s kind of not what I see here.

>>> 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 "<ipython-input-95-16f43d841fa3>", line 1, in <module>
    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'
>>> f2 = open(torch.__file__)
# succeed

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

Oh, maybe I’ve figured it out…

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

There is no directory. Just a pth and an egg.

Oh yeah, I think it’s zipped in an egg.

1 Like

this is no longer working.

PackageNotFoundError: Package not found: ‘pytorch’

1 Like

Hi,

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 conda update pytorch torchvision

FYI. In order to install the latest torch and torchvision, now, you do

conda install pytorch torchvision -c pytorch

You can also read this post ( Pytorch 0.3 version is released).

7 Likes

For me this did not work. It always tried to downgrade my pytorch and torchvision to some rather ancient version.

I installed it again in a separate environment using pip then which worked.

What about uninstall original torch and torchvision and install again?

Tried that aswell. So far only Pip seems to work for me.

This worked for me!

conda update pytorch torchvision -c pytorch

The following NEW packages will be INSTALLED:

cudatoolkit: 8.0-3

The following packages will be UPDATED:

pytorch:     0.2.0-py36h53baedd_4cu80 soumith [cuda80] --> 0.3.0-py36_cuda8.0.61_cudnn7.0.3h37a80b5_4 pytorch
torchvision: 0.1.9-py36h7584368_1     soumith --> 0.2.0-py36h17b6947_1                       pytorch
5 Likes

If the dependencies are not met, conda will not update to recent pytorch. What I did was the following.

  1. conda install pytorch=0.3.0 -c pytorch ( This gave the missing dependencies)
  2. Install the missing dependencies from Anaconda Cloud ( in my case they where numba, blaze )
  3. conda update pytorch torchvision -c pytorch
4 Likes

I can no longer edit the original post. Now you need to use this command instead (basically, you need to replace soumith with pytorch).

conda config --add channels pytorch

Yeah, the soumith channel is now called pytorch. See post above.

1 Like

Just a general note, it’s probably better to do the torch.__file__ checks with via isfile and abspath:

>>> import torch
>>> import os
>>> os.path.isfile(torch.__file__)
True
>>> os.path.abspath(torch.__file__)
'/Users/sebastian/miniconda3/lib/python3.6/site-packages/torch/__init__.py'
1 Like

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:

# All requested packages already installed.

Any suggestions?

I would recommend to create a new conda environment and install there your 1.0 preview.
In that way you can just delete it once the 1.0 stable version will be released and your other code is still executable.
Have a look here to learn how to manage environments.

1 Like

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