How to set up AWS P2 Server for Deep Learning

Jude Ben
Africa AI
Published in
8 min readJan 16, 2017

It’s 2017 and part of my learning goal is to get practical knowledge on deep learning, having read enough theories last quarter of 2016, so i started this course Practical Deep Learning For Coders, Part 1, first week of January to reach my goal, taught by Jeremy Howard (Kaggle’s #1 competitor 2 years running, and founder of Enlitic) . I’m passionate about the idea that deep learning can help to solve a lot of society’s most important problems, so i am super excited to start this new journey, I remembered attending artificial Intelligence course(CSC525) in my final year in computer Science , university of Uyo, Nigeria, The lecturer read out the course outline and i was smiling because i always wanted to know what this Artificial intelligence is all about. There was an argument in the class about the proponent of week and Strong AI , to me and my friends that was the only interesting part of the course, there was no practical knowledge and the lecturer kept reading it out everyday to us from a textbook, everyone in the class just wanted to pass the course. At the end of the course, i didn’t really learn much about Artificial Intelligence and that was it. I still did not understand what Artificial intelligence was after passing with a “B” grade.

Last month, Our small team thought of building a deep learning recommendation engine to power our new Startup App -NamMi- An Artisan’s Recommendation App for Nigeria. NamMi is solving the question “Who should do this for me ?” and seek to use deep learning, crowd source experience and social graph to answer that question better than objective and subjective listing.

After a little comparison between Google’s tensorflow and Amazon’s Dsstne, We decided to go with Amazon’s Dsstne, because it best suits our use case - to build a deep learning recommendation engine for NamMi. Amazon’s Dsstne is a library for training and deploying recommendation models with sparse inputs, fully connected hidden layers, and sparse outputs, according to its github repository.

With my limited and no practical Knowledge of deep learning, i watched the Amazon’s dsstne getting started video, read a lot of blog post on it and tried to run the sample data set for 3 good days, i still couldn't figure out how to make it work. I knew it was my lack of knowledge on deep learning so when i heard about this course Practical Deep Learning For Coders, Part 1 . i just jumped into it and started learning.

This is my first post on deep learning series, as i am learning, i will be sharing my experience, just like everything first in software development, we need to setup the environment for deep learning, so let’s begin.

Begin……

To get started in deep learning you’ll need a deep learning capable machine -a computer with an Nvidia graphics processing unit (GPU) in it that you can use . Since my laptop does not have Nvidia GPU and the course also recommended using Amazon Web Services (AWS). I had to create an amazon aws account and set this up and I am happy to share.

I used a recently released AWS product called “P2”, which has a powerful GPU with a lot of memory just as it was recommended from the course. Amazon EC2 P2 Instances are powerful, scalable instances that provide GPU-based parallel compute capabilities. P2 are ideally suited for machine learning, high performance databases, computational fluid dynamics, computational finance, seismic analysis, molecular modeling, genomics, rendering, and other server-side workloads requiring massive parallel floating point processing power. pre-installed with popular deep learning frameworks such as Caffe and Mxnet, Unfortunately ,P2 is not Free ,It costs $0.90 per hour to run.

By Default, service limit for P2 server is zero (0) . AWS does not allow you to create a GPU service without requesting for service increase , You must request for service limit increase to one(1) before you can use it for deep learning

Request p2 limit increase
Request form

It is important that you don’t try to create your P2 server until your request has been actioned; to check whether it has, visit this link and find the row for “p2.xlarge”.

They will get back to you within 24hrs. Once you have access to Aws, you can get your instance up and running. Everything you do will be done through the console and specifically you will be using AWS command-line interface, which is a python based interface called Anaconda.

Installing Anaconda is Simple

I recommend you use Anaconda regardless of the operating system you’re using window, mac or linux. Just follow the instruction on the download website: https://www.continuum.io/downloads . I will only type Linux code here because I am using Ubuntu in my development laptop. This is the code to install Anoconda in Ubuntu with python 2.7 installed.

bash Anaconda2-4.2.0-Linux-x86_64.sh

NOTE: Include the “bash” command even if you are not using the bash shell.

if you are using window, i suggest you install a bash script- cygwin because some of the script you will write are written in bash rather than power shell which is the default in window OS. after installing Anoconda, next is to install aws cli.

Installing AWS command-line interface..

run the following code in your terminal if your using mac or linux or on cygwin for window users.

pip install awscli

The AWS command-line interface create a program called “aws”, in order to use it, you need to configure it with your security keys.

Setting up security keys…

go to aws console, you can type:

https://console.aws.amazon.com

You need to create a user for yourself, you can do this in the security ,identity and compliance section , click IAM

aws console image

Then you can click add user ,create a new user-name and click next permission. Enable programmatic access for the user. copy both Access key ID and secret access key because you will need them later.

add user

Now you can attached the administrative access policy to the to new username

Copy and keep your security credentials, because you will need them to configure aws in your local terminal.

Next: Configure AWS in local terminal..

type the following in your terminal

aws configure

It will ask for access key id and secret access key, the one you copied from the aws console. just copy and paste , press enter.

The default region name, type “us-west-2” and the default output type “text”

configure aws

Next Step: setup your deep learning server

There is a prepared bash script from the course , to help speed up the set up process, you can download clone copy i used from my github repository for the P2 server.

type:

wget https://github.com/judeebene/courses/blob/master/setup/setup_p2.sh

original copy can be found in fast.ai github repository https://github.com/fastai/courses in setup subfolder.

After downloading run the script:

bash setup_p2.sh

run bash setup_p2.sh

When the script is done running, you will find all you need to connect to aws p2 instance from your terminal from the output text file “fast-ai-comments.txt’

Connecting to AWS…

check for your instance Url from the “fast-ai-comments.txt” file

it will looks like this:

xxx–xx–xxx–xxx–xx.us-west-2.compute.amazonaws.com

Then ssh connect from your terminal by typing:

ssh xxx–xx–xxx–xxx–xx.us-west-2.compute.amazonaws.com

then type yes and pressed enter.

Now that you’ve login, before you check if your GPU is working well reboot your aws instance

you can type: sudo reboot

or reboot from the aws console.

from the action, select instance state, then reboot. Now you’re ready to check if your GPU is working well.

type: nvidia-smi

checking GPU

This is showing information about your GPU ,how much you’re using and number of processes running.

Yes, You’re almost done ,one more step, remove the bash history

type: sudo rm .bash-history

Now you can test your jupyter notebook, If you haven’t used it before,Jupyter Notebook is a web application that allows you to create and share documents that contain live code, equations, visualizations and explanatory text. Uses include: data cleaning and transformation, numerical simulation, statistical modeling, machine learning and much more. I will write more on how i used jupyter notebook to run deep learning analysis on future post.

running jupyter notebook

Now you will see that the notebook is running at your instance url with port 8888, copy your instance url, remember you can find it inside your output file.”fast-ai-comments.txt” and add the port number 8888 in your browser

It’ss passworded from the setup_p2.sh script, use “dl_course” to access it

jupyter notebook

Now you can go into the notebook folder, “nbs” lets test some few python libraries to be sure that the server is ready for deep learning.I will write more on the various python libraries i used in deep learning.

testing few python libraries with jupyter

Congratulation.

That’s it, you just finished setting up Amazon P2 server for deep learning

When you’re done, don’t forget to shutdown your aws instance, so you don’t get charge for it.

--

--

Jude Ben
Africa AI

Former Software Developer@PillarProject, Intel Machine learning Innovator ,Deep learning Enthusiast , Lead Research Engineer and founder@Volibra