Launch an AWS EC2 instance with GPU for Deep Learning in 5 minutes.

Di Chen
4 min readMar 1, 2018

--

First setup Deep Learning AMI with p2.xlarge.

I assume you have some experience playing with AWS EC2 before, which means you should know how to set AWS security group and connect your EC2 instances via SSH, which requires to set up key pairs in EC2. Please refer to Amazon EC2 Key Pairs if you haven’t generated your EC2 key pairs yet.

  1. Log into your AWS account and click “EC2

2. First click on the “Instance” on the left bar, and then click “Launch Instance

3. Choose the right AMI for deep learning, i.e “Deep Learning AMI (Ubuntu) Version 4.0” and click “Select”. It has preconfigured most of the common frames/packages for deep learning tasks with anaconda.

4. Choose the right instance type, i.e. p2.xlarge, the cheapest one with a GPU. You can check the detailed charge for the AMI and the EC2 spot instance. For a p2.xlarge instance in 2018, the lowest AMI charge is $0.9/hour.

5. Edit the security group under “Security Groups” for your instance, so that you can access your instance via ssh in your local terminal.

6. You can either create a new security group or select an existing security group. Make sure you configure the “Protocol”, “Port Range” and “Source” correctly, so that you could access your instance via SSH from locally. Here I make my instance be accessible from everywhere. (Unsafe and NOT recommend. Please take your own risk to do so.)

7. Finally, we can launch the instance. Note that I have previously configured my key pairs for SSH access to my instance. Please refer to Amazon EC2 Key Pairs if you haven’t done so.

Connect to your instance via SSH

  1. Get your public DNS ID and SSH into your instance using:
ssh -i YOUR-PATH/YOUR-AWS-PRIVATE-KEY.pem ubuntu@ec2-YOUR-PUBLIC-IP-ADDRESS.compute-1.amazonaws.com -L 8888:localhost:8888

2. Input “Yes” when prompt “Are you sure you want to continue connecting (yes/no)?”.

3. Check NVIDIA Driver Version(v384): $ nvidia-smi

4. Check CUDA toolkit version (version 9): $ nvcc --version

5. Check CuDNN version (version 5.1): $ cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2

7. Test a small TensorFlow application.

git clone https://github.com/tensorflow/tensorflow.gitsource activate tensorflow_p36python3 tensorflow/tensorflow/examples/tutorials/mnist/fully_connected_feed.py

Test Jupyter Notebook

You can run Jupyter Notebook by: $ jupyter notebook

Open your local browser and input the given url to access your Jupyter Notebook. You should now see all the files in your instances like the screenshot below.

If you find this post helpful, please make some noise by clicking the clap icon 👏on the top left. Thanks for reading!😃

--

--

Di Chen

Software Engineer, Data Scientist. Living in the dream.