Ultimate guide to setting up a Google Cloud machine for fast.ai version 2

1. Sign up on Google Cloud Platform Free Tier.

12 months worth of US$300 credit (3 Jan 2018).

2. Upgrade to a paid account (credit card required).


Note 1: Please note that some people have reported that Google Cloud does not accept debit cards.

Note 2: If you are unable to find an Upgrade button at this point, just continue with the next steps. The Upgrade button should appear at Step 5 below when you request for an increase in quota.

3. Create a new project for the fast.ai course

Click on “Create Project”.
Give your project an identifiable name and click “Create”.

4. Set a default Compute Engine region

Compute Engine → Settings

Set default region and zone (choose one from list).
Zones with NVIDIA K80 GPU and Intel Broadwell CPU (3 Jan 2018).

5. Request for increase in quota for GPU

IAM & Admin → Quotas

Select your project’s region.
Select NVIDIA K80 GPUs (without “preemptible”) → Edit Quotas → Change to “1” → Submit Request.

6. Receive email approval of quota increase

Approval email from Google Cloud Platform Support.

7. Configure firewall for Jupyter notebook

VPC Network → Firewall rules

The default firewall rules.

Create a firewall rule if your project does not already have one for tcp:8888.

Name: “default-allow-jupyter” and Target tags: “jupyter”
Source IP ranges:“” and Specified protocols and ports: “tcp:8888-8889”

You may choose some other unused port number but the typical number is 8888. It is permissible to specify a range of ports such as in the above case.

8. Create your virtual machine instance for fast.ai

Compute Engine → VM instances → Create

CPU platform: “Intel Broadwell or later” and Number of GPUs: “1”

It is up to you to decide the number of cores and the amount of memory to allocate for your VM instance but if you have the budget for it, it is a good idea to go with 4 cores and 26 GB memory (ideally > 12 GB, as the Tesla K80 GPU comes with 12 GB memory).

Boot disk: “Ubuntu 16.04 LTS” and “50 GB SSD”, Firewall: Check both, Network tags: “jupyter”

Again, it is up to you to decide the type of persistent disk to use as the boot disk but SSD is recommended for its higher speed if you have the budget for it. (For the fast.ai version 2 course, you minimally need 20 GB.)

Newly created VM instance is running.

9. (Optional) Convert the IP address to static

VPC network → External IP addresses

Convert IP address to “Static” and give it a name.

**Following this step results in ongoing charges for the static IP address. Skip this step if you wish to save on the cost of a static IP address (US$0.01/hour at time of writing).

10. Connecting to the VM instance

There are a few methods of connecting to your Ubuntu VM according to Google Cloud Platform’s official documentation (which can be found here). Two of those methods will be mentioned briefly.

Method 1: SSH from the browser:

Requires enabling popups on your browser (usually disabled by default).

While this method is the most convenient, it comes with a list of known issues that are officially documented here, which is why I recommend using the Google Cloud SDK command line method below.

Method 2: Command line using Google Cloud SDK (recommended)

Step a. Download and install Cloud Tools for your OS to use the Cloud SDK. (Windows users: check the option to install Python during installation).

Step b. Run “gcloud init” to link your account, and select project and region.

Step c. Run “gcloud compute ssh <your instance name>

Successful connection to VM running on Ubuntu 16.04.3 LTS.

Note: You should always stick to the same method of connecting to your VM because your login usernames for SSH from browser and for Cloud SDK may be different. This may result in confusion as you will end up in completely different home directories after connecting to your VM. If you intend to alternate between the two methods, first configure your SSH from browser and Cloud SDK login usernames to be identical.

*To switch users when connecting via Cloud SDK, use the command: “gcloud compute ssh <your user name>@<your instance name>”

Step 11: Run the bash setup script

curl https://raw.githubusercontent.com/howkhang/fastai-v2-setup/master/setup.sh | bash

You will be automatically disconnected after the script has finished running in order for the VM to do a reboot.

Step 12: Reconnect to the VM instance

Run “jupyter notebook”

Step 13: Connect to Jupyter notebook

Method 1: Connecting using your VM’s static IP address

Use this method only if you went through step 9 to obtain a static IP address.

Launch your browser and connect using your VM’s static IP address followed by the port number (in this case, “:8888”). For the token, copy the long string of characters shown after the “token=” .

Method 2: Connecting using ssh and port forwarding

Use this method if you skipped obtaining a static IP address in step 9 or if you encounter difficulties connecting to your Jupyter notebook using method 1.

Step a. Open another terminal (or Google Cloud SDK Shell) on your local machine and run the following command for port forwarding:

gcloud compute ssh <your instance name> --ssh-flag=“-L” --ssh-flag=“8888:localhost:8888”

You should see a new VM terminal pop up. You should now have a total of two local terminals (both showing your gcloud compute ssh commands) and two VM terminals (one showing the jupyter notebook server running and the other just showing the command line prompt).

Step b. Connect to Jupyter notebook using localhost:8888

Launch your browser and connect using “localhost” followed by the port number (in this case, “:8888”). For the token, copy the long string of characters shown after the “token=”.

Step 14: Get ready to do some serious learning!

And we are good to go! Let me know if you face any issues or have any feedback on this guide.

**Stopping your VM instance

Important: Remember to stop your VM instance when you are done with your notebooks or you will continue to incur charges.

Method 1: Online console

Compute Engine → VM instances

Stopping your instance via the online console.

Method 2: Command line on Cloud SDK

Enter the command: gcloud compute instances stop <insert instance name>

Method 3: Use the Cloud Console mobile app

Allows you to check on your instances anytime on your smartphone.