Great summary of how to use AWS

(Jeremy Howard) #1

Thanks to @reshama, here’s a summary of how to use AWS. (I’ve copied it from @reshama’s Github - hope that’s OK!):

AWS fastami GPU Image Setup Part 1 v2
Notes from Lesson 2 live on 06-Nov-2017

Part I - Setting up AMI

AMI (Amazon Machine Image): a template for how your computer is created

Step 0: Getting Started

Log into AWS Console:
Select Service: EC2
Launch Instance

Step 1: Choose an Amazon Machine Image (AMI)

  • Search Community AMIs [left menu]
  • Search: fastai
  • Select this image (for region N. Virginia): fastai-part1v2-p2 - ami-c6ac1cbc

NOTE: this AMI is available in a number of regions. Check your local region first. If it’s not available, check next closest region.

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

Step 2: Choose an Instance Type

(Note: it is the kind of computer we want to use.)

  • Filter by: GPU Compute
  • Select: p2.xlarge (this is the cheapeast, reasonably effective for deep learning type of instance available)
  • Select: Review and Launch at bottom

Step 2b: Select keypair

Note: you have already created a keypair in the past. Use one of those. For more specific instructions, see Create a Keypair.

And, voila! We have just created a new computer on AWS that we can log into :boom:

Part II - Logging into our AWS Computer

Syntax for logging in and setting up tunnel for Jupyter Notebook

Note 1: Ensure you are in your .ssh directory on your local computer.
Note 2: You will put your Public IP address where mine is.
Note 3: This part -L8888:localhost:8888 connects Jupyter Notebook from AWS to your computer.

my current path


my syntax for logging in

ssh -i aws_fastai_gpu.pem ubuntu@ -L8888:localhost:8888  

my example

▶ ssh -i aws_fastai_gpu.pem ubuntu@ -L8888:localhost:8888       
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-1039-aws x86_64)

 * Documentation:
 * Management:
 * Support:

  Get cloud support with Ubuntu Advantage Cloud Guest:

2 packages can be updated.
0 updates are security updates.

*** System restart required ***
(fastai) ubuntu@ip-172-31-10-243:~$ 

Working on our AWS Computer

List what files are loaded on the AWS computer:

my example

(fastai) ubuntu@ip-172-31-10-243:~$ ls
data  fastai  src
(fastai) ubuntu@ip-172-31-10-243:~$

cd into the fastai repo
cd fastai

my example

(fastai) ubuntu@ip-172-31-10-243:~$ cd fastai
(fastai) ubuntu@ip-172-31-10-243:~/fastai$ ls -alt
total 76
drwxr-xr-x 18 ubuntu ubuntu  4096 Nov  7 16:25 ..
drwxrwxr-x  8 ubuntu ubuntu  4096 Nov  5 00:35 .git
drwxrwxr-x  6 ubuntu ubuntu  4096 Nov  5 00:35 fastai
drwxrwxr-x  6 ubuntu ubuntu  4096 Nov  5 00:29 .
-rw-rw-r--  1 ubuntu ubuntu  1273 Nov  5 00:29 environment.yml
drwxrwxr-x  3 ubuntu ubuntu  4096 Nov  1 21:30 tutorials
-rw-rw-r--  1 ubuntu ubuntu   905 Nov  1 21:30 requirements.txt
drwxrwxr-x  4 ubuntu ubuntu  4096 Nov  1 21:30 courses
-rw-rw-r--  1 ubuntu ubuntu  1173 Nov  1 21:30 .gitignore
-rw-rw-r--  1 ubuntu ubuntu 35141 Nov  1 21:30 LICENSE
-rw-rw-r--  1 ubuntu ubuntu   280 Nov  1 21:30
(fastai) ubuntu@ip-172-31-10-243:~/fastai$ 

:heavy_exclamation_mark: Update the fastai repo
git pull

my example

(fastai) ubuntu@ip-172-31-10-243:~/fastai$ git pull
remote: Counting objects: 21, done.
remote: Total 21 (delta 12), reused 12 (delta 12), pack-reused 9
Unpacking objects: 100% (21/21), done.
   9ae40be..d64a103  master     -> origin/master
Updating 9ae40be..d64a103
 courses/dl1/excel/collab_filter.xlsx   | Bin 0 -> 90259 bytes
 courses/dl1/excel/conv-example.xlsx    | Bin 0 -> 101835 bytes
 courses/dl1/excel/entropy_example.xlsx | Bin 0 -> 10228 bytes
 courses/dl1/excel/graddesc.xlsm        | Bin 0 -> 124265 bytes
 courses/dl1/excel/layers_example.xlsx  | Bin 0 -> 17931 bytes
 courses/dl1/lesson1-rxt50.ipynb        |   4 +++-
 fastai/                 |   5 +++--
 fastai/                      |   2 ++
 fastai/                      |   1 +
 fastai/                        |   4 +++-
 fastai/                        |  26 ++++++++++++++++++++++++++
 fastai/                   |   4 ++--
 fastai/                |   4 ++++
 13 files changed, 44 insertions(+), 6 deletions(-)
 create mode 100755 courses/dl1/excel/collab_filter.xlsx
 create mode 100644 courses/dl1/excel/conv-example.xlsx
 create mode 100644 courses/dl1/excel/entropy_example.xlsx
 create mode 100644 courses/dl1/excel/graddesc.xlsm
 create mode 100644 courses/dl1/excel/layers_example.xlsx
(fastai) ubuntu@ip-172-31-10-243:~/fastai$ 

Update the conda libraries (do this once a month.)
conda env update


  • check which version of python is running
    • python --version
  • check which python path is being used
    • which python
  • see what packages are installed
    • pip list --format=legacy

my example

(fastai) ubuntu@ip-172-31-10-243:~/fastai$ python --version
Python 3.6.3 :: Anaconda, Inc.
(fastai) ubuntu@ip-172-31-10-243:~/fastai$ which python
(fastai) ubuntu@ip-172-31-10-243:~/fastai$ 

Part III - Jupyter Notebook

Launch Jupyter Notebook
jupyter notebook

my example

(fastai) ubuntu@ip-172-31-10-243:~/fastai$ jupyter notebook
[I 17:00:22.985 NotebookApp] Writing notebook server cookie secret to /run/user/1000/jupyter/notebook_cookie_secret
[I 17:00:30.584 NotebookApp] [jupyter_nbextensions_configurator] enabled 0.2.8
[I 17:00:30.950 NotebookApp] Serving notebooks from local directory: /home/ubuntu/fastai
[I 17:00:30.950 NotebookApp] 0 active kernels
[I 17:00:30.950 NotebookApp] The Jupyter Notebook is running at:
[I 17:00:30.950 NotebookApp] http://localhost:8888/?token=04089b6ccf89e723321097c9089ab52550f408c86f533608
[I 17:00:30.950 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 17:00:30.951 NotebookApp] No web browser found: could not locate runnable browser.
[C 17:00:30.951 NotebookApp] 
    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
[I 17:01:49.931 NotebookApp] 302 GET /?token=04089b6ccf89e723321097c9089ab52550f408c86f533608 ( 0.58ms

Going to “MY URL” for Jupyter Notebook


Note: you will want to edit the above url with YOUR TOKEN.

This notebook is running on AWS GPU machine.
This costs $0.90 per hour (and $3-4 per month for storage) :moneybag:
:boom: Remember to shut the notebook down! (Stop Instance.) :boom:


I opened the Lesson 1 notebook, made a copy with the name tmp-reshama-lesson1.ipynb and was able to run all the code! :boom:

(Reshama Shaikh) #2

(Thanks to @reshama, here’s a summary of how to use AWS. (I’ve copied it from @reshama’s Github - hope that’s OK!):slight_smile:

Of course, @jeremy :smiley:

(Vikrant Behal) #3

Can I launch more than 1 instance of aws instance?

While my 1st instance is running, my shell (Cywgin) is busy with 1st instance’s Jupyter notebook. Is it possible to spin 2nd instance?


(Sanyam Bhutani) #4

I think what you’d want to do is open another terminal and SSH from it.

(Vikrant Behal) #5

I couldn’t open another instance of Cygwin. When I click on icon, it navigates to existing instance.

(Jeremy Howard) #7

IIRC if you hold down shift when clicking in the start menu, it opens a new instance.

(Jeremy Howard) #8

@reshama you might find this helpful to know - you can put code and shell samples in your markdown like this:

ssh ubuntu@$IP -L8888:localhost:8888 

…which looks like this:

ssh ubuntu@$IP -L8888:localhost:8888 

<kbd> is best just used for keyboard shortcuts, I think.

PS: Noticed you’ve got even more cool posts in your github - really great! :smiley:

(Saurav Singh) #9

I m doing a fresh start at aws. It’s asking me to create a VPC and subnet.
@yinterian can you tell me what it is. And to configure that up :slight_smile:

(yinterian) #10

We don’t need to do this.

The steps are:
– select a region closets to you from this set
Oregon: ami-8c4288f4
Sydney: ami-39ec055b
Mumbai: ami-c53975aa
N. Virginia: ami-c6ac1cbc
Ireland: ami-b93c9ec0
– create key pairs for that region if you don’t have them
– launch an instance with the ami corresponding to your region for example for Oregon: ami-8c4288f4
– get a p2.xlarge
– You may need to ask to increase your limit to 1 if you have not done so already.
Could you try this and let me know if it works.

We discussed some of these steps in the introductory workshop.

(Saurav Singh) #11

yup I followed up these steps exactly how it is, and how its shown it the workshop video.
After selecting up the ami. It doesn’t give me an option to review and launch so when I click on configure I get this.

By the way, Im trying to launch it on oregon region.

(Saurav Singh) #12

Anyway I got it.
Though I will just write it down here for others.
To setup a VPC and subnet.

  1. Follow this exactly how it is.
  2. Go to your subnet. Right click and enable auto-public IP assign.
  3. Re-follow the steps of creating an EC2 instance.

(Praveen Krishnan) #13

@reshama How do I install Anaconda 3 on the AWS instance? I started the course end of 2017 with the AWS instance and that has Anaconda 2 with python 2.7. So, how do I migrate to Python 3 now (with Anaconda 3)?

(Aditya) #14

Everything is setup in the AMI…

(Praveen Krishnan) #15

Thanks. But the problem is I am using an AMI from 2017 which has Anaconda 2. So, how do I change that to Anaconda 3?

(Praveen Krishnan) #16

I just followed the instructions to install anaconda 3 from here

and modified the bashrc to reference Anaconda 3. Thanks for the response.

(Dan Goldner) #18

Hi all, I’m using the fastai AMI on AWS. I followed reshama’s directions, and when I run jupyter notebook, it doesn’t show anything in the tree, and if I try to create a new notebook, no kernels are present.

I am using LocalForward in my .ssh/config file, which works fine from paperspace and from cpu aws machines.

Grateful for any hints about where to look next.

(Dan Goldner) #19

Got it sorted – used the script,

# from
jupyter notebook --generate-config
key=$(python -c "from notebook.auth import passwd; print(passwd())")
cd ~
mkdir certs
cd certs
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.key -out mycert.pem
cd ~
sed -i "1 a\
c = get_config()\\
c.NotebookApp.certfile = u'$certdir/mycert.pem'\\
c.NotebookApp.keyfile = u'$certdir/mycert.key'\\
c.NotebookApp.ip = '*'\\
c.NotebookApp.open_browser = False\\
c.NotebookApp.password = u'$key'\\
c.NotebookApp.port = 8888" .jupyter/

and all was well.