Google Colab – Now Build Large Deep Learning Models on your Machine!
- Fundamentals of Deep Learning
- Articles on Deep Learning
- Introduction to Neural Networks
- Computer Vision using Deep Learning
Table of Contents
- What is Google Colab?
- GPUs and TPUs on Colab
- Getting Started with Google Colab
- Google Colab Runtimes
- Using Terminal Commands on Google Colab
- Cloning Repositories in Google Colab
- Uploading Files and Datasets
- Saving Your Notebook
- Exporting Data/Files from Google Colab
- Sharing Your Notebook
- What’s next?
What is Google Colab?
Google Colaboratory is a free online cloud-based Jupyter notebook environment that allows us to train our machine learning and deep learning models on CPUs, GPUs, and TPUs.
Here’s what I truly love about Colab. It does not matter which computer you have, what it’s configuration is, and how ancient it might be. You can still use Google Colab! All you need is a Google account and a web browser. And here’s the cherry on top – you get access to GPUs like Tesla K80 and even a TPU, for free!
TPUs are much more expensive than a GPU, and you can use it for free on Colab. It’s worth repeating again and again – it’s an offering like no other.
Are you are still using that same old Jupyter notebook on your system for training models? Trust me, you’re going to love Google Colab.
GPUs and TPUs on Google Colab
Ask anyone who uses Colab why they love it. The answer is unanimous – the availability of free GPUs and TPUs. Training models, especially deep learning ones, takes numerous hours on a CPU. We’ve all faced this issue on our local machines. GPUs and TPUs, on the other hand, can train these models in a matter of minutes or seconds.
If you still need a reason to work with GPUs, check out this excellent explanation by Faizan Shaikh.
Whether it is a data science hackathon or a deep learning project, I always prefer a GPU over any other CPU because of the sheer computational power and speed of execution. But, not everyone can afford a GPU because they are expensive. That’s where Google Colab comes into play.
It gives you a decent GPU for free, which you can continuously run for 12 hours. For most data science folks, this is sufficient to meet their computation needs. Especially if you are a beginner, then I would highly recommend you start using Google Colab.
Google Colab gives us three types of runtime for our notebooks:
- GPUs, and
As I mentioned, Colab gives us 12 hours of continuous execution time. After that, the whole virtual machine is cleared and we have to start again. We can run multiple CPU, GPU, and TPU instances simultaneously, but our resources are shared between these instances.
Let’s take a look at the specifications of different runtimes offered by Google Colab:
It will cost you A LOT to buy a GPU or TPU from the market. Why not save that money and use Google Colab from the comfort of your own machine?
Getting Started with Google Colab
You can go to Google Colab using this link. This is the screen you’ll get when you open Colab:
Click on the NEW NOTEBOOK button to create a new Colab notebook. You can also upload your local notebook to Colab by clicking the upload button:
You can also import your notebook from Google Drive or GitHub, but they require an authentication process.
You can rename your notebook by clicking on the notebook name and change it to anything you want. I usually name them according to the project I’m working on.
Google Colab Runtimes – Choosing the GPU or TPU Option
The ability to choose different types of runtimes is what makes Colab so popular and powerful. Here are the steps to change the runtime of your notebook:
Step 1: Click ‘Runtime’ on the top menu and select ‘Change Runtime Type’:
Step 2: Here you can change the runtime according to your need:
A wise man once said, “With great power comes great responsibility.” I implore you to shut down your notebook after you have completed your work so that others can use these resources because various users share them. You can terminate your notebook like this:
Using Terminal Commands on Google Colab
You can use the Colab cell for running terminal commands. Most of the popular libraries come installed by default on Google Colab. Yes, Python libraries like Pandas, NumPy, scikit-learn are all pre-installed.
If you want to run a different Python library, you can always install it inside your Colab notebook like this:
!pip install library_name
Pretty easy, right? Everything is similar to how it works in a regular terminal. We just you have to put an exclamation(!) before writing each command like:
Cloning Repositories in Google Colab
You can also clone a Git repo inside Google Colaboratory. Just go to your GitHub repository and copy the clone link of the repository:
Then, simply run:
!git clone https://github.com/analyticsvidhya/Complete-Guide-to-Parameter-Tuning-in-XGBoost-with-codes-in-Python.git
And there you go!
Uploading Files and Datasets
Saving Your Notebook
All the notebooks on Colab are stored on your Google Drive. The best thing about Colab is that your notebook is automatically saved after a certain time period and you don’t lose your progress.
If you want, you can export and save your notebook in both *.py and *.ipynb formats:
Not just that, you can also save a copy of your notebook directly on GitHub, or you can create a GitHub Gist:
I love the variety of options we get.
Exporting Data/Files from Google Colab
You can export your files directly to Google Drive, or you can export it to the VM instance and download it by yourself:
Exporting directly to the Drive is a better option when you have bigger files or more than one file. You’ll pick up these nuances as you work on bigger projects in Colab.
Sharing Your Notebook
Google Colab also gives us an easy way of sharing our work with others. This is one of the best things about Colab:
Just click the Share button, and it gives us the option of creating a shareable link that we can share through any platform. You can also invite others using their email IDs. It’s exactly the same as sharing a Google Doc or Google Sheet. The intricacies and simplicity of Google’s ecosystem are astounding!
Google Colab now also provides a paid platform called Google Colab Pro, priced at $9.99 a month. In this plan, you can get the Tesla T4 or Tesla P100 GPU, and an option of selecting an instance with a high RAM of around 27 GB. Also, your maximum computation time is doubled from 12 hours to 24 hours. How cool is that?
You can consider this plan if you need high computation power because it is still quite cheap when compared to other cloud GPU providers like AWS, Azure, and even GCP.
I am also working on another article where I’ll be giving you all the tips and tricks you need to know to master Google Colab. If you found this article informative, then please share it with your friends and comment below with your feedback or queries.You can also read this article on Analytics Vidhya's Android APP