Battling out the GPU Frustration with Google Colab | by sriganesh lokesh | Towards Data Science

With a momentous increase in the size of datasets for machine learning and deep learning models to fit, there has been an escalation in the demand for GPUs to faster train the model. As students of data science, we all know how long our challenged laptops take to run a machine learning or deep learning model with a dataset containing millions of records.
Generally, basic Laptops and PCs take a huge chunk of the user’s time in fitting the data to the constructed model. So the process of HyperTuning the model will take a hit with such a constraint.
An alternative to this situation would be to buy an external GPU, which will cost 250–300$ on average for a basic model. For a student, this is a steep price to pay for a college project which he/she is working hard for.
I KNOW IT IS FRUSTRATING!!!
Thanks to Google, students can stop worrying about such a situation, as Google provides a free GPU on the cloud for running large scale machine learning projects.
This article will get you started with Google Colab, a free GPU cloud service with an editor based on Jupyter Notebook.
Users can run their Machine Learning and Deep Learning models built on the most popular libraries currently available — Keras, Pytorch, Tensorflow and OpenCV.
To get started, you will need some knowledge of Python and Jupyter notebook along with basic machine learning concepts.
Google Colab is a perfect tool for Python’s popular libraries such as Keras, Tensorflow, Pytorch. You have the power to create a new Python 3 or Python 2 Notebook, Open Notebooks stored in the respective google accounts used to create the notebooks and can upload notebooks from the local computer. In the case of uploading our dataset on to the platform, there is a drawback, wherein the dataset is removed when the session is restarted. We can Mount Google Drive to the Notebook, which is a cool feature instead of uploading the file each time we open the notebook.
We can launch the platform by clicking on the link below
colab.research.google.com
Once you click on the link, you are asked to log in with your Google account wherein all the notebooks which you create will be automatically stored for future use.
The Examples tab provides some code which has to be properly reviewed in order to use most of the features of Google Colab.
Recent tab provides the last few notebooks which you had created or worked on.
Google Drive tab provides all the notebooks linked to your google account.
Github tab lets you link your github account to google colab.
Upload tab provides a link to upload file from the local computer. Most of the hidden features can be known by extensively using the platform.
This is the basic layout that is generated when a new notebook is created. Most of the features are similar to Jupyter Notebook. You can change the name of the notebook by double-clicking on Untitled.ipynb. +Code and + Text are used to add a new code cell or markdown cell respectively. The notebook can be shared with other users by adding their Gmail address so that everyone can make the appropriate changes in one place. You can start a new session by clicking the Connect button on the top right corner of the screen.
Before starting the session, it is a good practice to change the runtime type to GPU( As it is the main purpose behind the usage of Google Colab) which can be accessed in the Runtime tab.
Google Colab is a very simple yet powerful platform to run your Machine Learning and Deep Learning models without worrying about GPU power. If you are used to working in Jupyter Notebook, then this will be a piece of cake.
I would like to stress on Markdowns as they add a lot of weight while developing a Jupyter Notebook. It helps you to tell a story through your code, which is a must if you are aspiring to be a Data Scientist. The management mainly requires the output rather than the code involved and this eases that process. Google Colab provides a live preview of the markdown written so that you don’t have to make minor changes by running the cell every time.
This window appears to the left of the screen with an arrow associated with it. Here, you can upload a file from the local computer or Mount your Google Drive (i will explain in the latter part of the post).
from google.drive import drive drive.mount(/content/gdrive)
!pip install keras
!git clone https://github.com/pytorch/pytorch
!python setup.py
TPU(Tensor Processing Unit) was developed by Google to provide high computational power to train machine learning and deep learning models. Even though an NVIDIA Tesla K80 is present at your disposable, TPU provides much more in terms of power. As per the information provided by Google’s Colab documentation, A GPU provides 1.8TFlops and has a 12GB RAM while TPU delivers 180TFlops and provides a 64GB RAM.
Google Colab is a great alternative for Jupyter Notebook for running high computational deep learning and machine learning models. You can share your code with other developers on the go so that they can help you optimize your code. Most of the python libraries come pre-installed with Google Colab so it reduces the burden of installing each and every library. And the main feature would be FREE GPU!!!.
There are some limitations with free products as usual. (insignificant restrictions but can make a difference in certain scenarios). You can only use Python 2.7(Deprecated from Jan 2020) or 3.6 as the programming language, with no support for R. GPU allocation per user is restricted to 12 hours at a time. The GPU used is the NVIDIA Tesla K80, and once the session is complete, the user can continue using the resource by connecting to a different VM.
I would recommend you to refer Your One-Stop Guide to Google Colab which provides a deeper understanding of Google Colab with more tips and tricks.