Quick Guide for setting up PyTorch with Window in 2 mins

Nok Chan
codeburst
Published in
4 min readMar 31, 2018

--

Edited: Since PyTorch 0.4.0 (The latest is 1.0 now), there are official Window Support, please install Pytorch with either pip or conda, details are written in their homepage instead if you want to use the new version. Pytorch has done a great job, unlike Tensorflow, you can install PyTorch with a single command. It handles CUDA and CuDNN out of the box for you in most case. In other word, you don’t have to go to Nvidia and download CUDA & CuDNN yourself.

# If you use conda
conda install pytorch torchvision -c pytorch
# Or you can use pip as well, depends on your python version you need to install the corresponding one, the example here is Python 3.6
pip3 install https://download.pytorch.org/whl/cu90/torch-1.0.0-cp36-cp36m-win_amd64.whl
pip3 install torchvision

Updated: If you have to install PyTorch with version <0.4.0, please continue the reading, otherwise, you are all set!

PyTorch does not have window support officially, but there is a very nice repo from peterjc123 which have Window support and works fine so far.

I personally have a Geforce 930M and Window10 laptop, it works fine before. Until recently, that’s what happened to me.

RuntimeError: cuda runtime error (8) : invalid device function at /data/users/soumith/miniconda2/conda-bld/pytorch-cuda80-0.1.8_1486040640754/work/torch/lib/THC/generated/../generic/THCTensorMathPointwise.cu:246

I google it and I find it is because PyTorch no longer support my GPU since 0.3.1. This mean, for any GPU have compatibility ≤ 5.0, they are not support with current version.

For those who have Geforce 1000 Series, you are probably still fine. To install PyTorch on Window, you simply do this. Please refer to peterjc123 repo

# If your main Python version is not 3.5 or 3.6
conda create -n test python=3.6 numpy pyyaml mkl

# for CPU only packages
conda install -c peterjc123 pytorch-cpu

# for Windows 10 and Windows Server 2016, CUDA 8
conda install -c peterjc123 pytorch

# for Windows 10 and Windows Server 2016, CUDA 9
conda install -c peterjc123 pytorch cuda90

# for Windows 7/8/8.1 and Windows Server 2008/2012, CUDA 8
conda install -c peterjc123 pytorch_legacy

If you have a older GPU like me. I find this thread on PyTorch forums.

There are two choices.

  1. Compile from source as suggested.

2. Install a .whl file, which is easier.

To build from source was too complicated for me, I will go through the steps that you needed to install an older PyTorch version on window. It is actually on peterjc123’s repo already, but I find the instruction is not obvious and I have missed it at first sight.

  1. Find your GPU compatibility, if you have a GPU similar to me, you are probably fine with 0.3.0 PyTorch

2. Click the icon on below screenshot. If you want to install GPU 0.3.0 version, click on it. (The master branch for GPU seems broken at the moment, but I believe if you do conda install pytorch peterjc123, it will install 0.3.1 at the moement so it should be fine)

A GIF showing the whole process
Pick 0.3.1 (Latest successfully built package)

3. Find your package, it depends on your OS system(Window 7/8/10), Python version (3.5/3.6) and architecture (Pascal, Maxwell and Kepler)

4. Once you click on the icon, you will see a page lie this. For those who are not familiar with this, you probably think you are in the wrong place.

5. Click on one of the JOB NAME that fits your need. For me, it is Visual Studio 2017, Python = 3.6 and CUDA_ARCH = Maxwell.

6. You will see something similar to above screenshot, click “Artifacts”

7. Click on the .whl file and download it, then simply go to that directory and use

 pip install xxxx.whl

8. Done

This is actually a very convenient way to install PyTorch on Window. Hope it helps, especially for those who do not have a new GPU. :)

Edited: Added a little GIF.

✉️ Subscribe to CodeBurst’s once-weekly Email Blast, 🐦 Follow CodeBurst on Twitter, view 🗺️ The 2018 Web Developer Roadmap, and 🕸️ Learn Full Stack Web Development.

--

--