Quick start — pyt🔥rch on an AWS EC2 GPU enabled compute instance

Michael Dietz
2 min readApr 17, 2017

--

No, a neckbeard isn’t required to install tensorflow/pytorch and their dependencies properly. In this tutorial we’ll install pytorch on an AWS EC2 GPU enabled compute instance.

This post serves as a general quick start to get up and running with your favorite deep learning library/framework on an AWS EC2 GPU enabled compute instance as pretty much everything is the same.

  1. Launching an EC2 instance
  2. [Recommended] Requesting a spot instance and increasing the storage space on our EC2 instance to accommodate larger data sets
  3. Downloading and installing the CUDA Toolkit and cuDNN library
  4. Installing pytorch with pip

Launching an EC2 instance

Launch an instance from the AWS EC2 console and select Ubuntu Server 16.04 LTS (HVM), SSD Volume Type — ami-80861296.

Choosing an AMI

I recommend choosing a p2 instance as there is a ~2–3x speed-up when compared to the previous generation of g2 instances (see a detailed comparison here).

Choosing an instance type

[Recommended] Requesting a spot instance and increasing the storage space on our EC2 instance to accommodate larger data sets

Requesting a spot instance
Increasing the storage space on our EC2 instance

Downloading and installing the CUDA Toolkit and cuDNN library

CUDA and cuDNN ship with pytorch. No need to download/install these. Simply run the script attached below to install the required NVIDA driver and reboot:

$ chmod +x install-tesla-driver-ubuntu.sh | sudo ./install-tesla-driver-ubuntu.sh

If you are using a different deep learning library/framework then run the script attached below to install CUDA and cuDNN:

this is not required for pytorch users (unless installing from source)

Installing pytorch with pip

Now all we need to do is install pytorch with pip: $ sudo pip3 install -U http://download.pytorch.org/whl/cu80/torch-0.1.11.post5-cp35-cp35m-linux_x86_64.whl .

To verify everything is working open the Python interpreter $ python3 and > import torch > torch.randn(5, 5).cuda().

--

--