PyTorch: Difference between revisions
m (Latest available wheel in its section, split the installation into two sections) |
(Marked this version for translation) |
||
Line 12: | Line 12: | ||
= Installation = <!--T:1--> | = Installation = <!--T:1--> | ||
==Latest available wheels== | ==Latest available wheels== <!--T:20--> | ||
To see the latest version of pytorch that we have built: | To see the latest version of pytorch that we have built: | ||
{{Command|avail_wheels --name torch}} | {{Command|avail_wheels --name torch}} | ||
For more information on listing wheels, see [[Python#Listing_available_wheels | listing available wheels]]. | For more information on listing wheels, see [[Python#Listing_available_wheels | listing available wheels]]. | ||
<!--T:15--> | ==Pre-build== <!--T:15--> | ||
<!--T:18--> | <!--T:18--> | ||
Line 29: | Line 28: | ||
:{{Command|prompt=(venv) [name@server ~]|pip install numpy torch_cpu}} | :{{Command|prompt=(venv) [name@server ~]|pip install numpy torch_cpu}} | ||
<!--T:16--> | ==Anaconda== <!--T:16--> | ||
You can install PyTorch using Anaconda. First [[Anaconda/en|install Anaconda]], and then install PyTorch in a conda environment as follows. '''Note that Anaconda has a tendency to update its versions often, which may result in the instructions below not working in the future.''' | You can install PyTorch using Anaconda. First [[Anaconda/en|install Anaconda]], and then install PyTorch in a conda environment as follows. '''Note that Anaconda has a tendency to update its versions often, which may result in the instructions below not working in the future.''' | ||
Revision as of 18:34, 26 July 2018
PyTorch is a Python package that provides two high-level features:
- Tensor computation (like NumPy) with strong GPU acceleration
- Deep neural networks built on a tape-based autograd system
PyTorch has a distant connection with Torch, but for all practical purposes you can treat them as separate packages.
Installation
Latest available wheels
To see the latest version of pytorch that we have built:
[name@server ~]$ avail_wheels --name torch
For more information on listing wheels, see listing available wheels.
Pre-build
The preferred option is to install it using the python wheel that we compile, as follows:
- 1. Load a python module, either python/2.7, python/3.5, or python/3.6
- 2. Create and start a virtual environment.
- 3. Install PyTorch in the virtual environment with
pip install
. For both GPU and CPU support: -
(venv) [name@server ~] pip install numpy torch_gpu
- If you only need CPU support:
-
(venv) [name@server ~] pip install numpy torch_cpu
Anaconda
You can install PyTorch using Anaconda. First install Anaconda, and then install PyTorch in a conda environment as follows. Note that Anaconda has a tendency to update its versions often, which may result in the instructions below not working in the future.
- 1. Load the Miniconda 2 or Miniconda 3 module.
-
[name@server ~]$ module load miniconda3
- 2. Create a new conda virtual environment.
-
[name@server ~]$ conda create --name pytorch
- 3. When conda asks you to proceed, type
y
. - 4. Activate the newly created conda virtual environment.
-
[name@server ~]$ source activate pytorch
- 5. Install PyTorch in the conda virtual environment.
-
[name@server ~]$ conda install pytorch torchvision cuda80 -c soumith
- Here, we instruct conda to use the soumith channel to retrieve the packages from the release channel belonging to the main PyTorch developer, Soumith Chintala. This guarantees you will have the latest version.
Job submission
Once the setup is completed, you can submit a PyTorch job with
[name@server ~]$ sbatch pytorch-test.sh
Here is an example of a job submission script using the python wheel, with a virtual environment in $HOME/pytorch:
#!/bin/bash
#SBATCH --gres=gpu:1 # Request GPU "generic resources"
#SBATCH --cpus-per-task=6 # Cores proportional to GPUs: 6 on Cedar, 16 on Graham.
#SBATCH --mem=32000M # Memory proportional to GPUs: 32000 Cedar, 64000 Graham.
#SBATCH --time=0-03:00
#SBATCH --output=%N-%j.out
module load python/3.6
source $HOME/pytorch/bin/activate
python ./pytorch-test.py
and here is an example of a job submission script using Anaconda:
#!/bin/bash
#SBATCH --gres=gpu:1 # Request GPU "generic resources"
#SBATCH --cpus-per-task=6 # Cores proportional to GPUs: 6 on Cedar, 16 on Graham.
#SBATCH --mem=32000M # Memory proportional to GPUs: 32000 Cedar, 64000 Graham.
#SBATCH --time=0-03:00
#SBATCH --output=%N-%j.out
module load miniconda3
source activate pytorch
python ./pytorch-test.py
The Python script pytorch-test.py
has the form
import torch
x = torch.Tensor(5, 3)
print(x)
y = torch.rand(5, 3)
print(y)
# let us run the following only if CUDA is available
if torch.cuda.is_available():
x = x.cuda()
y = y.cuda()
print(x + y)