Run your Deep Learning Model at Google Colab — Fast and Free GPU

Oindrila Sen
Mar 1 · 5 min read

I created my first Deep Learning Model to generate Text using LSTM. The basic model ran for a few hours on my macOS Sierra (10.12.6). Let’s put it this way — the results were not so satisfactory. So, I became ambitious and thought of running a model with lots of layers — a deep and wider model. It turned out that was really me being over-ambitious. Initially, it displayed an ETA of 60 hours. I let it run for 2 days and 2 nights. Then, the next morning, I woke up and checked my kernel was dead!

After that heart-breaking incident, I asked myself:

How do I build an enormous deep learning model without waiting for results for days?

The answer was expensive! So, I asked the next question.

How do I build a large deep learning model without burning a hole in my pocket?

Thanks to Google, the answer is GoogleColab!

It’s an online browser-based platform that allows us to train our big and complex machine learning models for free without any hassle! On top of that, it allows running Jupyter Notebooks! So, to sum up, Collaboratory, or “Colab” is fabulous because:

Colab allows us to write and execute Python in our browser, with

  • Zero configuration required
  • Free access to GPUs
  • Easy sharing

Sounds too good to be true, right?

It took me a few minutes to run the basic model which actually ran for hours in my local machine. I am so excited! That brings me to my next post which is as below:

How to run a Jupyter Notebook on Google Colab?

Step1: Open Google Colab

Open Google Colab using this link. Now, we have a lot of options here:

  1. Upload the Notebook from my local machine

2. Connect to Github and open a Notebook

I uploaded my basic model notebook from my Github.

3. Open a Notebook from Google Drive

Now, once the Notebook is uploaded, it opened in a similar interface as Jupyter Notebook like below:

Step2: Choosing GPU/ TPU on Google Colab

By default, Colab notebooks run on CPU. We can switch our notebook to run with GPU Or TPU. I had to actually google to understand what is the difference between TPU and GPU and which one to choose. Well, my understanding is as below:

So, my basic thumb rule is that for a little more complex problem like any Deep Learning problem, I will choose GPU. Now, let me show you how to choose GPU for running a notebook.

Navigation is as below:

Runtime -> Change runtime type -> Hardware accelator -> GPU -> Save

Once it is connected, we need to add the Datafile.

Step3: Upload a Datafile

Now, to run a Model, we need Data. While running a Jupyter Notebook on my local MacOSx, I used the data file stored in my local directory. But, to train the model at Google Colab, we need to load the data. There must be a couple of options to load data. But here, I am mentioning the one I used and worked out well for me.

Steps to Upload a data file:

  1. Click on the folder/files icon.

Then click on the Upload icon and upload the data file from your local directory.

Once the file is uploaded, it will display a note/message like below.

Click “OK” and you will see your Data File on the left-hand side panel.

That’s it! Now, we are all set to run the Jupyter Notebook.

Step 4: Train the Deep Learning Model

Now, we are all set to train the Deep Learning Model in a few minutes. While running a cell, it will display a warning message like below:

Click “Run Anyway” if you are confident with your code!

For the basic Deep Learning Model, it took 3 minutes and I got the output. Amazing right?

Step 5: Save the Notebook

All the notebooks on Colab are automatically stored on your Google Drive. Also, a copy of the notebook can be saved on Github or as a gist.

Conclusion:

Working with Google Colab is easy. It makes training a deep learning model possible. Above all, it is free! It also allows sharing the notebook. Try your hand on Google Colab and you will not regret it.

Originally published at https://oindrilasen.com on March 1, 2021.

MLearning.ai

Data Scientists must think like an artist when finding a solution

Oindrila Sen

Written by

Data Scientist, Story Teller

MLearning.ai

Data Scientists must think like an artist when finding a solution, when creating a piece of code.Artists enjoy working on interesting problems, even if there is no obvious answer.

Oindrila Sen

Written by

Data Scientist, Story Teller

MLearning.ai

Data Scientists must think like an artist when finding a solution, when creating a piece of code.Artists enjoy working on interesting problems, even if there is no obvious answer.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store