Skip to content

Installation PyTorch from the source

Jinserk Baik edited this page Feb 8, 2019 · 1 revision

Install pyenv

Doing this with your normal user account. Do not use root.

Install dependencies

refer to here

$ sudo apt install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev libffi-dev liblzma-dev python-openssl

Install pyenv

install the pyenv using installation script

$ curl https://pyenv.run | bash

add env setting to your ~/.bashrc

export PATH="/home/jinserk/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

refresh the env

$ source ~/.bashrc

Install Python

install your preferred python binary. The installation path will be `$HOME/.pyenv/

$ pyenv install 3.7.2

update pip and install basic python env

$ pyenv local 3.7.2
$ pip install --upgrade pip
$ pip install --upgrade numpy scipy sklearn matplotlib pyyaml wheel

CUDA/CUDNN Installation

CUDA Install

download deb(network) file from here

install deb file

$ sudo dpkg -i cuda-repo-ubuntu18sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
04_10.0.130-1_amd64.deb

add GPG key for the repository

$ sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub

update repository info

$ sudo apt update

install cuda

$ sudo apt install cuda

CUDNN Installation

Download deb files from here. You will need to register the NVIDIA developer membership.

Install deb files

$ sudo dpkg -i libcudnn7_7.4.2.24-1+cuda10.0_amd64.deb
$ sudo dpkg -i libcudnn7-dev_7.4.2.24-1+cuda10.0_amd64.deb
$ sudo dpkg -i libcudnn7-doc_7.4.2.24-1+cuda10.0_amd64.deb

NCCL Installation (optional)

If you have two or more GPUs on your machine, or you will use multi-GPUs cluster, you will need to install NCCL.

download Network Installers (x86) from here

Install deb file

$ sudo dpkg -i nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb

update repository info

$ sudo apt update

install libnccl2 package

$ sudo apt install libnccl2

PyTorch Installaion

install latest pytorch

$ git clone https://github.com/pytorch/pytorch.git --recursive
$ cd pytorch
$ pyenv local 3.7.2 
$ python setup.py bdist_wheel
$ pip install --upgrade dist/<built-whl>

install torchaudio

$ cd ..
$ git clone https://github.com/pytorch/audio.git
$ cd audio
$ python setup.py bdist_wheel
$ pip install --upgrade dist/<built-whl>

install torchnet

$ cd ..
$ git clone https://github.com/pytorch/tnt.git
$ cd tnt
$ python setup.py bdist_wheel
$ pip install --upgrade dist/<built-whl>