Deep Learning with Python and fast.ai, Part 0: Setup GPU Virtual Machine on Google Cloud

Fast.ai is a terrific deep learning framework based on PyTorch. The main author, Jeremy Howard, has already published the whole MOOC based on fast.ai on the official website. This fantastic MOOC helped students all over the world to make a better understand of deep learning.

On October 2nd, fast.ai released the 1.0 version along with the new PyTorch 1.0 preview. In this version, the fast.ai got improved a lot.

The diagram above comes from the documentation of fast.ai. It shows the new structure of fast.ai 1.0 framework. With the new well-designed modules, you can train models for picture classification, NLP problem, and tabular data tasks more easily.

As fast.ai 1.0 is still in the early stage, there are not so many cloud GPU platforms support PyTorch + fast.ai 1.0 now. If you want to try it out, the official websites recommended two ways, namely salamander.ai and Google Cloud.

I have tried them both. However, I found salamander.ai still needs to improve its stability and efficiency. When you start to run a notebook, it will take for a long time to get things ready, and may exhaust your patience.

Google Cloud, on the other hand, is a good choice. It’s more stable, comparing with salamander.ai, and when you get it ready to run, it’s quite convenient. Yet another good news is, if you are a new user of Google Cloud Platform, you will be given $300. With that amount of money, you can practice deep learning for hundreds of hours!

I tried to follow the instructions and got the virtual machine deployed on Google Cloud. However, I think the blog missed some steps, and may confuse the new users. So I decide to provide you with this step-by-step tutorial. Hope you can setup a Google Cloud virtual machine for fast.ai 1.0 smoothly.

Let’s begin to get hands dirty.

First, Please navigate to Google Cloud website.

You need to register a new account, and then login. You can refer to this page if you encounter any problem.

For the first time to use google cloud, you will be asked to provide valid billing method. You can use your credit card information to do so.

To run the deep learning example comes along with this tutorial, it will cost you less than a dollar. So do not worry.

Go to this link, and create a new project named “try-fastai”. And click on the CREATE button.

Open this link, and hit the blue button “launch on compute engine”.

In the following pop-up window, click on “try-fastai”.

And you will be navigated to the following page:

Change the Deployment name to “fastai”.

Change the Framework to “Pytorch 1.0 Preview/FastAi 1.0 (CUDA 9.2) [EXPERIMENTAL]"

Make sure the GPU option is selected.

Change the boot disk type to SSD (optional).

The configuration should be like this:

Now hit the Deploy button on the bottom left.

The new Deployment needs several minutes to be ready. Please be patient.

When the deployment is done, you will see the information on this page:

Copy this line:

gcloud compute ssh --project try-fastai --zone us-west1-b fastai-vm -- -L 8080:localhost:8080

Paste it into your favorite editor or Notebook App.

Please note this command will be necessary each time you want to use your google cloud deep learning instance.

While waiting for the deployment process, you can go to this link to get your Google Cloud SDK installed.

Google will direct you to the corresponding operating system tab.

Download the installation package according to your OS. For example, I use macOS, so I will download macOS 64-bit version.

You will get a tarball.

You can unzip it to your hard drive.

Use the Terminal and cd command to go into the extracted directory.

./install.sh

You can continue the installation by input “Y”.

Start a new shell, and type in:

gcloud init

You will be asked to login.

Choose your account information in the popped up browser.

Pick cloud project to use:

Choose “ [1] try-fastai"

When you are asked to configure a default Compute Region and Zone, choose “N”.

Now you are all set.

Copy the command from your editor or note App, paste it to your terminal.

gcloud compute ssh --project try-fastai --zone us-west1-b fastai-vm -- -L 8080:localhost:8080

For the first time running this command, you will be asked to input passphrase. Just compose one and make sure you can remember it. I suggest you also keep it in your note App.

If you need the new version of Fast.ai 1.0 (v3) course material, run:

git clone https://github.com/fastai/course-v3

Now, you can run :

jupyter lab

Copy the url in the last two lines in the prompted message.

Paste it into your browser and hit enter. Now you can use the Jupyter Lab just like running it locally.

Use the directory navigate bar on the left pane to dive into course-v3/nbs/dl1 and open lesson1-pets.ipynb.

In the Menu, Choose Run, and select Restart Kernel and Run All Cells to see if the notebook works well.

For my case, everything goes smoothly.

Please remember, when you are running the virtual machine, you’ll be charged according to the usage time. So when you no longer need to VM instance, do go to this link:

Choose “Stop”.

You will no longer be billed after the instance stopped.

The next time you need to use the virtual machine, just go back to this link, and start the vm again.

Then in your terminal, re-run:

gcloud compute ssh --project try-fastai --zone us-west1-b fastai-vm -- -L 8080:localhost:8080

And then, launch Jupyter Lab again. All your previous work are still there.

Happy Deep Learning!