Setup and Run fast.ai in Amazon AWS

The philosophy of fast.ai is to get up and running with Deep Learning as soon as possible, and figure out the details on the way. And they provide some wonderful resources to do just that. Fast.ai has a promo code for Paperspace, that would allow you to get started fairly easily. But soon you would realize that the $15 promo in Paperspace barely lasts two lectures. So, at some point you would want to move to a more powerful GPU provider, such as Amazon AWS. But setting up an AWS machine could be a little troublesome for beginners. In this blog I am going to give a comprehensive guideline on how to set up an AWS machine to fire up your deep learning code. Amazon AWS has a $150 bonus for signing up with a student email address. I will briefly discuss how to get it at the end.

In this tutorial I am assuming that you already have an AWS account, and you have set up the billing information and other necessary requirements. If you face any problem regarding those, you can contact the customer service, they are very helpful on this regard.

Login to console:

Select location Oregon, Ohio or N. Virginia for an AWS free tier account. Otherwise you would get an error while creating an instance. If you are not a free tier user, you can choose any location and you are good to go.

Go to All services> Select EC2

Request Limit Increase:

Click “Limits” on the left panel of EC2 Dashboard

Inside “Instance Limits” click on “Request Limit Increase”

Select Region (The same region you have selected earlier), for example, I have chosen Oregon.
Primary Instance Type : p2.xlarge
Limit: <do nothing here>
New Limit Value: 1

In Use Case Description, type “fast.ai MOOC”

Select “Support Language” and “Contact Method” and hit “Submit”.
The customer care will reach out to you in 24/48 hours. Once this part is done, you can move on to the next sections.

Creating the Key Pair:

Extra step for Windows:
To run this on Windows (works on Windows 10 only), you need to install Ubuntu Bash for windows. Here you can find a comprehensive guide to how to install it. Once it is done, move on to the next part of the tutorial. Here on, when I mention bash, you should understand the Ubuntu Bash for Windows.

Open your Linux Bash or Mac Terminal. Type “ssh-keygen” into the bash, hit Enter 3 times.

This will generate an SSH key file named “id_rsa.pub” in your local computer inside folder named ‘.ssh’. Now you need to copy this file to another directory that is easy for you to locate.

# Linux or Mac
cp .ssh/id_rsa.pub /<A location in your computer>/
# For Bash for Winwows
cp .ssh/id_rsa.pub /mnt/<A location in your computer>/

For example, following command in Windows 10 will copy the file to your Desktop and E drive respectively.

cp.ssh/id_rsa.pub /mnt/c/Users/<yourUserName>/Desktop/
cp.ssh/id_rsa.pub /mnt/e/

Selecting this Key Pair from AWS:
Select “Key Pairs” from the left panel.

Click “Import Key Pair

Choose the key pair file “id_rsa.pub” from your local storage (where you have just copied from .ssh folder), change the name for your Key Pair if you wish.

Launch Instance:

From the left panel, click “Community AMIs”

Search for “fastai”, select fastai-part1v2-p2 — ami-xxxxxxxx

Depending on your selected location, the “ami” would be one of the following:

  • Oregon: ami-8c4288f4
  • Sydney: ami-39ec055b
  • Mumbai: ami-c53975aa
  • N. Virginia: ami-c6ac1cbc
  • Ireland: ami-b93c9ec0

Filter by GPU Compute

Select p2.xlarge

Click “Review and Launch”

Click “Launch”

Select a key pair, click “Launch Instances”. You can set up a different name for this particular Key Pair if you want.

And, done. You should see a message like this confirming that your instance is launched.

A little bit caution though, the instance you have created will start running instantly. And to my concern, AWS bills you on hour basis. So, even if you run the machine for a few minutes, probably you would be charged for an hour (Please let me know if I am wrong). So, I would recommend you to run the instance for an hour before you shut it down. Maybe just test out some of the fast.ai lessons if they are working right now.

Running the Instance:

You will see an Instance like this.

For the first time, it will probably be running. If not, to run it, right click> Instance State> Start. Also use the same process to stop the instance when you are done. Do not click “Terminate” unless you know what you are doing.

To log in to this computer, you need to know its Public IP address. The IP is located in the description, as shown here. Copy this IP address.

To get to this computer you need to SSH to it. SSH means connecting to the cloud computer so that it is like that you are typing in that computer. To do this, you need to open your Linux Bash, Ubuntu Bash for Windows, or Mac Terminal, and execute the following command. It will also connect Jupyter Notebook in the cloud instance to Jupyter Notebook in your PC. XXX.XXX.XXX.XXX indicates the Public IP address of the cloud instance.

ssh ubuntu@XXX.XXX.XXX.XXX -L8888:localhost:8888

It will ask for permission to connect to the cloud computer. Type “yes”. After this step, you should see something like this:

Now go to fast.ai directory

cd fastai

First thing you should do when you get here is make sure it is updated

git pull

For the first run, and maybe even once a month, be sure to update the libraries as well

conda env update

This might take a few minutes, don’t freak out!
The last step, is to run Jupyter Notebook

jupyter notebook

This will fire up Jupyter Notebook in the cloud computer, as if it is running on your local computer. You should see something like this:

Copy the URL and paste it in your browser, and you will see a Jupyter Notebook window with fast.ai files.

VIOLA!! You have successfully created and run a cloud instance in Amazon AWS. Now you can do anything in this Jupyter Notebook that you could do in your local computer. Enjoy the power of cloud, until you burn out of your credits ;). Last time I checked a p2.xlarge instance cost $0.90/Hour. After you are done working, be sure to shut down the instance.

AWS student pack:

Go to https://education.github.com/pack/offers

Scroll down to “aws educate” click on “Get access using your unique link”. You’ll be asked to log in to github if you are not logged in.

Provide your student information and school email address to get the promo code and insert the promo code in your AWS account to get credit. If you have trouble getting this credit, ask me in the comments, I will make a separate blog describing the process.

References:

Image Credit:
Some of the images are screen grab from the referenced video.

Researcher in NLP and Machine Learning | masumhasan.net

Researcher in NLP and Machine Learning | masumhasan.net