There are multiple ways to install PyTorch on your Genesis Cloud Instance. The easiest way to get started is to use the preconfigured image with PyTorch already installed. This guide is for when you want to use pip nevertheless, for example when installing a specific version of PyTorch. For more info check out the PyTorch installation guide here.
To use PyTorch with GPU support make sure to install the GPU driver when creating your instance. Make sure that the GPU drivers as well as the NVIDIA CUDA Toolkit is installed. Helpful resources:
Prerequisite: Installing pip
sudo apt install python3-pip
Check here to get the command for a specific torch version. You can use nvcc --version to check what nvidia toolkit version you are using. For pytorch 1.5 and nvidia toolkit 10.1 you need the following command.
pip3 install torch==1.5.0+cu101 torchvision==0.6.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html
After the installation finished you can check that PyTorch is working by starting the Python3 interpreter:
And then execute the following python commands to load PyTorch, check that CUDA (GPU support) is available and list the number of CUDA devices (=GPUs)
import torch torch.cuda.is_available() torch.cuda.device_count()
(Note: You can leave the Python interpreter mode using "ctrl + D")
You are all set! In your Python script make sure to specify that you want to use your GPU, when you start training your models. When they are running on one GPU you can just specify
in your python code. Here is a tutorial, that shows how to use multiple GPUs.