Getting free access to AWS GPU instances for Deep Learning

Authors: Sneha Bhakare, Videsh Suman

Videsh Suman
9 min readMay 10, 2018

Disclaimer:
Free for Students only. Free access in the sense that you’ll receive free 150$ AWS credits which can be used on any of the Amazon Web Services, supposedly to be renewed every 12 months until you graduate.

As a part of the course project for EE 769 — Introduction to Machine Learning, we (along with my other group-mate) needed to train our DQN model on a GPU, which encouraged me to wander around, in search of free GPU access, all over the Internet. Gathering information from various sources, I was able to help ourselves train the model on a considerably powerful GPU for free.

Without wasting time on needless Introduction i.e. expressing the need for powerful computation in today’s Deep Learning era, let me cut the crap and get to the point.

So, what is AWS? (Check the hyperlink, if interested)
AWS Educate is a grant program for educators, academic researchers and students. The program augments Amazon’s efforts to increase awareness of its public cloud services in the educational community.

First things first!

Register for Github Education: Student Developer Pack which, among many other perks, also gives you a total of $150 AWS credits, although requiring you to join the AWS Educate Program too.

The importance of this pack cannot be overstated (if you’re a developer)

Getting your Developer Pack activated is pretty easy and straight forward. Follow the steps mentioned here, if you don’t have the Developer Pack account already. Remember, the perks of this pack can be accessed only until the next 2 years, which can further be extended if you still hold academic status then. This might take an hour upto even a week for activation.

Registering for AWS

In the meantime, register for AWS Account according to the following instructions. This will also require you to setup a payment method and verify your phone number. Sign in to your AWS account, and take note of your 12-digit Account ID on the My Account page.

For me the page looks like this. Take note of your Account Id.

If you already have the Github Student Pack, or you’re done activating it, just open the above hyperlink, login and proceed over to the AWS Educate section, accessing it using your unique link provided there.

Access the unique link and register for AWS Educate

AWS Educate: Registration and Redemption

After being directed to the AWS Educate page, you’ll notice the Promo Code to be pre-filled in this case. Register using the institute-provided email address and enter the other concerned registration details.
When you’re filling out your AWS Educate application, you can either select an AWS account that you’ve already successfully created and activated, or select an AWS Educate Starter Account (Starter Accounts can only use some AWS services excluding the EC2 GPU instances). Hence, just select the already created AWS account. You might need the 12 digit Account ID to be entered on selecting this option, but I’m not really sure.
You might want to check this issue (skip it if not interested) for more insight.

After completing the necessary procedure, you should ideally receive a Welcome Email from AWS Educate Support, which will include an AWS Educate Promotional Credit. Redeem the credit code on the Credits page of your AWS account. They might take upto 48 hours to review your application, be patient till then.

You might also receive this dismissive email instead, rejecting your application within a few minutes of completing your application. This has happened with another student of my Institution, so I think it’s an issue with the institute-provided email address in my case.

My Welcome Email was not so welcoming, after all.

In such a case, create a Support Case at here, mentioning your rejected application and attaching your University/School ID for further review.

This is how my Support Case looked like

They replied back to my case in over about two days time.

Their reply to my Support Case

Almost immediately after this reply, I received another email from AWS Educate Support, actually welcoming me this time.

Yay!!

Do as directed on this email: redeem the credit code on the Credits page of your AWS account. You’ll find your credits page looking something like this, with the Credit Code applied.

My Credits after the code redemption

So, now you’re done with creating your account and getting everything onboard before you really start sailing.

Launching a GPU Instance

What is Amazon EC2? What are Instances and AMIs?

Just go to the AWS homepage and login with your email address and password. Sign in to the AWS Console.

You’ll see this page after logging into your Console

On the top left, you’ll see a Region drop down list. You need to select one before you proceed to Launch a Virtual Machine.

Now, there are quite a few parameters for choosing your AWS Region:

  • Geographical proximity
  • Instances available and their prices (the GPU instances from the list)
  • Latencies

You can also take a look at these links too (not in context of GPU instances though) :

Personally, I had used Mumbai as my region for my first instance, planning to change for the next time. I wasn’t too sure about Region selection when I had created my own first instance.

Read about Instances and AMIs here.

After you click to Launch a virtual machine with EC2, they ask you to choose an AMI first.

In the interest of Deep Learning, go to AWS Marketplace tab and search for Deep Learning Ubuntu

For details, check it’s product page — Deep Learning AMI (Ubuntu). It also gives you the region-wise, instance-wise pricing.

Select the first AMI and proceed
This list can vary depending on the Region you select.

Select one of the GPU compute instances based on the specifications mentioned on this page (check the Accelerated Computing tab), and the corresponding pricing in the AMI product page (make sure you select the correct region while checking the prices).

Once you’re sure about the the instance, click on Review and Launch. Click on Launch after that.

Create a new key pair

Now they’ll ask you to create a new key pair for your instance. Type the key pair name (tip: should only contain alphabet, numbers or underscore) and download the .pem file in a safe and accessible location in your system. You’ll need this file every time you have to access the virtual machine. Don’t ever delete this file as it can be downloaded only once, on creation, or you won’t be able to access this instance again.

Assuming this is your first time, you’ll receive this Error message after launching the instance. So, for every time you want to launch a new instance of a different type and from a different region, you have to request for a service limit (default limit is zero for every case) increase from the AWS Support.

Visit the link mentioned to request a service limit increase
Select the region, the preferred instance and set the new limit value to 1

Almost instantly (at least I did), you’ll receive the message regarding the approval of your request.

Prompt Indeed!

You can relaunch the instance now with the already created key pair.

I hope it’s successful this time.

You should change the permissions of the key to user-only RW. Fire up the terminal in the directory containing the .pem file.

# for Linus/OSX
$ chmod 600 PEM_FILENAME

Here PEM_FILENAME is the full file name of the .pem file you just downloaded.

Scroll down and go to the View Instances page.

The instance can be seen running. Note the Public DNS on the right column of the Description tab.

Your instance is up and running. Now, it’s time to test your virtual machine. To ssh into the instance(from home directory in your system):

ssh -i path/PEM_FILENAME ubuntu@PUBLIC_DNS

PUBLIC_DNS is the Public DNS which can be found on the right column of the Description tab in the Instances page.

ssh -i ~/dlvm_sumanvid97.pem ubuntu@ec2-13-126-144-105.ap-south-1.compute.amazonaws.com

You’ll be asked whether to add the following to the list of known hosts; just type yes and you’ll be into the remote server.

Select one of the following virtual environments depending upon your requirement

Use any of the commands to choose the concerned virtual environment. You might have to install some of the dependencies required for your project. However, it’s as easy as in any other Ubuntu system.

Since you’re in the remote server instance now, editing or writing any code would require you to fire up Vim. You can download any other Ubuntu software you would want only using the terminal.

A good practice is to write/edit files on your system and copying the entire directory (via scp) into the remote instance. Use the following command from your system’s terminal:

$ scp -i path/PEM_FILENAME path/DIRECTORY_OR_FILE_TO_BE_COPIED ubuntu@PUBLIC_DNS:TARGET_PATH

For me, this command looks like this:

$ scp -i ~/dlvm_sumanvid97.pem ~/LearningTensorFlow  ubuntu@ec2-13-126-144-105.ap-south-1.compute.amazonaws.com:~/

After training if you want to send the model (or the entire directory) back to your own system, use this command on your system’s terminal:

$ scp -i path/PEM_FILENAME ubuntu@PUBLIC_DNS:path/DIRECTORY_OR_FILE_TO_BE_COPIED TARGET_PATH

For me, it would be something like this:

$ scp -i ~/dlvm_sumanvid97.pem ubuntu@ec2-13-126-144-105.ap-south-1.compute.amazonaws.com:~/LearningTensorFlow/model.h5 ~/LearningTensorFlow

To stop an instance, just open the Instances tab in your Console and right click on the desired instance.

Right click > Instance State > Stop

Importantant Pointers

  • Check this link to know the difference between Stopping and Terminating an Instance. Important.
  • You can explore the tabs in the Billing Dashboard and keep a check on your limits.
  • As stated somewhere (not sure where), this 150$ credit code is supposed to be regenerated and mailed to you every 12 months, until you graduate.
  • Stop your instances when are training, to avoid incurring charges. GPU instances are expensive. Use your funds wisely.
  • Terminate them when you are sure you are done with your instance (disk storage also costs something, and can be significant if you have a large disk footprint).
  • Look into creating custom alarms to automatically stop your instances when they are not doing anything. Hoping to try this next time.
  • If you need access to a large dataset and don’t want to download it every time you spin up an instance, the best way to go would be to create an AMI for that and attach that AMI to your machine when configuring your instance (before launching but after you have selected the AMI). I never had the need to try this though.

PS:

I, myself, discovered this enormous platform of AWS only in the last few weeks. Hoping to exploit it more in the coming days.
If you find something fishy on this blog, experience a case not covered here, or have any questions or something new to contribute, do post in the comments section below.

References:

Cheers! :)

--

--

Videsh Suman

ML/CV @ Fyusion, Formerly studying @ UMass Amherst, IIT Bombay