DEV Community

Cover image for Boost your Colab Notebooks with GCP and AWS Instance in a few minutes
Zoheb Abai
Zoheb Abai

Posted on • Edited on

Boost your Colab Notebooks with GCP and AWS Instance in a few minutes

For Data Scientists, Notebooks have become the 'de facto' tool while working on a project. Whether they perform EDA on the initially available dataset or begin with some data preprocessing steps or experiment with different models and libraries, notebook is the one they begin with. In this respect, Colab Notebooks are second to none - Easily available with almost all the libraries pre-installed, efficient enough with readily available GPUs and TPUs, can be saved on multiple locations from Drive to GitHub and also shared live with colleagues.

But sometimes you might require resources more than Colab typically offers, for example, you might require multi-GPUs or higher GPU RAM or maybe a better GPU or more than 12 hours of runtime (default) to conclude a successful DS experiments in your notebook. In this blog, I shall cover how to upgrade your Colab in a few minutes, receiving all the above mentioned benefits, without moving your code elsewhere, having Google Cloud Platform or Amazon Web Service Instance as its backend.

Google Cloud Platform

When you first sign up on GCP, you will have $300 free credits.

Request an increase in GPU Quota

Your account typically does not come with GPU quota. You have to explicitly request for it under IAM Admin > Quotas.
You should change your quota of GPU (all regions). Filter the Metric to GPU (all regions), increase its limit

Alt Text

And Submit a request. Wait until GCP sends you a second email (the first email is just to notify you that they received the request). It would take a couple of minutes (or hours maybe) for them to approve.

Create an Instance of your choice

Now go to Compute Engine > VM instances and create an instance

Alt Text

Fill the details as shown below:

Alt Text

Alt Text

Alt Text

Alt Text

Alt Text

And click Create.

Also, do this.

Alt Text

Once your instance is up, it shall display similar to this

Alt Text

Amazon Web Services

If you are using AWS for the first time, you can apply for receiving $300 free credits.

Request an increase in GPU Quota

Your account typically does not come with GPU quota. You have to explicitly request for it under Support > Create Case > Service Limit Increase. You should increase EC2 All P instances in your region by limit 1.

Alt Text

Write a short description of the use case and submit a request. Wait until AWS replies to you back. It would take a couple of minutes (or hours maybe) for them to approve.

Create an Instance of your choice

Now go to EC2 > Launch instance and create an instance

Alt Text

Follow the steps as shown below:

Alt Text

Alt Text

Alt Text

Alt Text

Alt Text

Alt Text

Download the key pair in your local storage (and maybe copy it into a secure location too). Tick the box and click Launch Instances. It shall show similar to this

Alt Text

Once your instance is up, it shall display similar to this

Alt Text

Command Line Terminal and Colab

For GCP:

Install Google Cloud SDK using the quick start for your operating system.

Once Google cloud is set up, initialize GCloud SDK for your Google account:

gcloud init

Now Connect to your server and forward your port:

gcloud beta compute ssh --zone "us-central1-a" "colab-backend" --project "myfirstproject" -- -L 8888:localhost:8888

For AWS:

Go to the directory where your EC2 security key is located and run

chmod 0400 awsec2keypair1.pem

Next,

ssh -L localhost:8888:localhost:8888 -i "awsec2keypair1.pem" ubuntu@ec2-33-142-118-69.compute-1.amazonaws.com

Common for both GCP & AWS:

First make sure this is installed:

pip install --upgrade jupyter_http_over_ws>=0.0.1a3 && \
jupyter serverextension enable --py jupyter_http_over_ws

For AWS (not required for GCP): Before launching notebook please activate the environment:

source activate pytorch_p36

you can check envs list by running conda info --envs

Finally, launch your Jupyter notebook:

jupyter notebook \
--NotebookApp.allow_origin='https://colab.research.google.com' \
--port=8888 \
--NotebookApp.port_retries=0

It shall display similar to this:

Alt Text

Copy the notebook link, go to Colab and follow these steps:

Alt Text

Alt Text

and click Connect.

To check if GCP/AWS backend is integrated:

Alt Text

Note: Google Colab currently doesn’t support integration with Google Drive while connected to a local runtime.

And Voilà! Your SUPER-Colab is ready!

Alt Text

Important: Don't forget to stop your GPU/AWS instance once you are done.

Let me know in the comments if you face any issue.

Top comments (0)