Set up Google Cloud GPU for fast.ai for v1 and v2

Nok Chan
Google Cloud - Community
6 min readNov 30, 2017
GCP

This blog post is for setting up Google Cloud GPU instance for this great course fast.ai, but some of the practice are still applicable for general purpose. I have been struggled for a few days to make it works, so I want to write a post to summarize these steps.

A lot of credits go to Sabastian from this thread and

‘s blog post Running Jupyter Notebook on Google Cloud Platform in 15 min. I just combine both of them for setting up this great course.

It will take you no more 30 minutes to finish all the set up and you can enjoy the course. :)

Note: This post originally target v1, but setup for v2 is much easier, simply just run the bash script after the you connect with the instance.

Create Google Cloud GPU Instance

  1. Increase Quota

In order to have GPU available, you need to apply for increasing the GPU quota, the default is 0. It takes me 5 mins to finish the process and get approved, much faster than AWS does.

Go to Quotas → you need to upgrade your account in order to have GPU available → increase the quota for the regions you want, please check that which region you would like to use here.

(Try not to be too aggressive by asking a lot of GPU quota, as from other experience, they may ask you to pay in advance. I think starting with 1 K80 is good enough)

2. Create an Google Cloud Platform(GCP) Instance

In the home page of GCP console, there are some info that you would like to copy down to a text file. Copy your Project ID, as you will need it later when you SSH to your instance. (For me, the project ID is endless-fire-xxxxxxx)

GCP Home Page

We can start creating instance now. Click “Compute Engine” which appears at the left side.

  1. Click Create an instance
  1. Name your instance, choose a zone that you want(make sure it has GPU available)
  2. Choose Tesla K80 as GPU

It is not easy to find where the GPU are, but they are actually hidden, click “Customise” and you will able to add GPU to your instance.

3. Change Boot Disk to Ubuntu 16.04

Make sure you have the correct image Ubuntu 16.04, and make it a SSD hard drive, the default is a HDD. The price actually doesn’t change much, so just choose a SSD! (Recommend to get at least 25GB, note that you can only increase SSD but not decrease SSD later)

Choose Ubuntu 16.04, make it an SSD if you want(recommended)

4. Almost done

You just need to tick HTTP traffic because later we will access the instance with Jupyter Notebook in a browser. You may also want to un-tick “Delete boot disk when instance is deleted” to keep your storage alive even if you kill you instance. And Now you are done, click create an instance!

It is that easy to setup the GCP, if you want to have a static IP, please go to the great blog post and check what’s more you can do.

Connect with your instance

Now we need to connect our remote instance on our local machine. Since I am a Window user and I have been following Jeremy’s tutorial, so I am using Cygwin to run my bash script. If you haven’t done that, please check out the tutorial or install Cygwin directly(Make sure you have the 64 bit version and “wget“ installed!).

STEP 1 Install Google Cloud SDK

It is something similar to “aws” package, it is a command line interface to interact with Google Cloud and we will need this to SSH our instance.

I will not spend time to explain how to install it. Please follow the instruction here, the documentation is straight forward.

STEP 2
SSH into the instance. Open Cygwin or you may just open the Google Cloud SDK Shell. The INSTANCE_NAME is what I asked you to copy down before, it is in your home page.

gcloud compute ssh INSTANCE_NAME (In my case, it is instance-1)

STEP 2.5

If you are doing v2. Please do this step and go to STEP 6 and you can ignore the rest.

Originally you can just run this script and you are done with Paperspace, but if you are using GCP VM, you need to change the script a little bit, I have changed the script in my Github so you can just mimic the same step:

git clone https://github.com/noklam/learning_fastai.git
bash learning_fastai/paperspace

STEP 3

These steps are copy from the forum’s thread, thanks to Sabastian again.
Download the script that installs CUDA, Anaconda etc:
wget https://raw.githubusercontent.com/fastai/courses/master/setup/install-gpu.sh

STEP 4
Run the script:
sudo sh install-gpu.sh
At the end you need to pick a password for the jupyter notebook. This script also clones the course materials from https://github.com/fastai/courses/.

STEP 5
reboot, either using the reboot command or the reset option on the console:
sudo reboot

STEP 6
Create a firewall rule for accessing port 8888 from your local machine(you will be using port 8888 for accessing your Notebook), using the console or the command line:

PROJECT is the Project ID that shown in your console’s home page, which I have asked you to copy down earlier.

YOUR_IP is the IP of your local machine, you can do cmd.exe → ipconfig to check what’s your local IP if you don’t know about it.

(Seems they remove the beta command, I haven’t test it yet. In case it fails, go to the console, VPC Network → Firewall Rules, and add a rules that allows tcp:8888 and add your own ip on it)

export PROJECT="project_name"
export YOUR_IP="enter_the_ip_of_your_local_machine"
gcloud compute --project "${PROJECT}" firewall-rules create "jupyter" --allow tcp:8888 --direction "INGRESS" --priority "1000" --network "default" --source-ranges "${YOUR_IP}" --target-tags "jupyter"
(Thanks for Rahul for adding this commands)gcloud compute instances add-tags <instance_name> — tags jupyter

STEP 7
Check if CUDA is installed properly:

sudo modprobe nvidia
nvidia-smi
nvidia-smi

STEP 8
Run jupyter notebook:
jupyter notebook --ip=0.0.0.0 --port=8888
Note the token displayed in the terminal. Go to the notebook using the external IP of your instance. You can find your external IP of your instance in the console.

xxx.xxx.xxx.xxx:8888 is the link of your notebook.

You will need a token to login to your Notebook.

Your token is here:

token

We are all done with the setup, and you can access the notebook with GPU-powered machine. The great thing about GCP is that you have $300 free-credit, which is quite enough for you to explore the notebook(If not, just apply one more gmail and get $300 more!)

Please let me know if you have any question!

--

--