How to use gpu in google colab?
Last Updated :
31 Jul, 2024
Google colab is a service provided by Google for a lot of researchers and developers around the globe. It is a Jupyter Notebook-like environment in one single place without any prerequisites. It is free to use with a limited number of computer resources and engines including free access to GPUs i.e. Graphics Processing Units for accelerated parallel processing of code. It also comes with a premium version with more readily available resources computational resources. It is one of the best platforms for all students interested in the field of computer science especially machine learning, data science, artificial intelligence, etc. Colab provides a free workspace in the form of Python3 or R notebooks. These notebooks can be used to implement various compute-heavy tasks in a very easy manner.
In this article, we will learn to use GPU i.e. Graphics Processing Unit in our google colab notebook. You can also refer to the video solution for this end which is attached at the end of this article.
What is GPU (Graphics Processing Unit)?
It is a very specialized computation technology to boost a number of different tasks by utilizing parallel processing. The GPUs can work along with CPUs to do all the tasks in a concurrent manner. Similarly, most of the ML/AI tasks require a lot of complex mathematical calculations and hence, take a lot of time. By using GPUs, these tasks can be accelerated to be done in a much faster way.
Prerequisite - A Google Account. Refer to this article which explains How to Create a New Gmail Account? (2023), which is equivalent to creating a Google Account.
Let's get started :
Step 1: Go to Google Colab website on the browser of your choice and click on the "Open Colab" option on the right-hand side top menu bar. This will open up a google colab notebook.
.jpg)
Step 2: Let's first sign in into our google account, if you are not already signed in.

Step 3: A dialog box will be open which will mention all your recent notebooks on colab. Click on "New notebook" in the bottom menu bar to create a new notebook.

Step 4: In order to connect and start a colab session, click on "connect" button on the right-hand top side of the notebook. It will initialize a session, allocate some resources and start a session for us.

Step 5: But, in this session only CPU engines are allocated. In order to connect to GPU, click on the small down arrow icon, just besides the Connect button, go to "Change runtime type" option.
Step 6: In the dialog box, select the "T4 GPU" radio button, and then click on "Save" button. This will reinitialize a session for us, but, now with GPU computational resources.

Step 7: As we can see now, the GPU RAM is also allocated to our notebook.

Step 8: To check the type of GPU allocated to our notebook, use the following command.
!nvidia-smi

As can be seen in the above image, a Tesla T4 GPU is allocated to us with a RAM size of almost 15GBs. By following the above steps, we can easily connect to the colab notebook with GPU resources.
Please refer to the following video, to get a more detailed idea about the process which showcase all the steps mentioned above.
Similar Reads
How to use R with Google Colab?
Google Colab is a cloud based coding platform providing free access to limited resources like GPU or TPU. It comprises cells where one can write codes and execute them. It also provides the facility of sharing in real time. Some of the features are:It allows users to share notebooks in real time.It
3 min read
How to use TensorBoard in Google Colab?
TensorBoard is indeed an invaluable tool. It serves as a comprehensive visualization toolkit with the TensorFlow ecosystem, enabling practitioners to experiment, fine-tune, and monitor, the training of machine learning models with ease. By offering a dynamic and intuitive dashboard, TensorBoard allo
7 min read
How to Install and Use Git in Google Colab?
Google Colab is a popular platform for data scientists and machine learning enthusiasts to write and execute Python code in a Jupyter Notebook environment. While it provides a robust environment for coding, integrating version control systems like Git can enhance productivity by allowing you to trac
2 min read
How to Open web camera in Google Colab?
If you want to create a machine learning model but say you donât have a computer that can take the workload, Google Colab is the platform for you. In this article, we will see how we can open a camera in Google Colab. What is Google Colab?Google offers the Google Colab service to numerous researcher
3 min read
How to Use Google Drive in Linux
Google Drive is one of the famous cloud storage services provided by Google. Google Drive allows users to store files online and access them from anywhere. Google Drive is available for all major platforms i.e. Windows, MacOS, Linux, and others. In this article, we will learn how to use Google Drive
8 min read
How to Import Tensorflow in Google Colab
Google Colab is a cloud-based Jupyter notebook environment that allows you to write and execute Python code in the browser with zero configuration required. It provides free access to computing resources, including GPUs and TPUs, making it an excellent platform for machine learning and data science
2 min read
How to upload folders to Google Colab?
Google Colab is a service provided by Google for a lot of researchers and developers around the globe. It is a Jupyter Notebook-like environment in one single place without any prerequisites. It is free to use with a limited number of computer resources and engines including free access to GPUs i.e.
4 min read
Ways to import CSV files in Google Colab
Colab (short for Collaboratory) is Google's free platform which enables users to code in Python. It is a Jupyter Notebook-based cloud service, provided by Google. This platform allows us to train the Machine Learning models directly in the cloud and all for free. Google Colab does whatever your Jupy
4 min read
How to update Google Colab's Python version?
The importance of having a current version will be covered in this article, especially for activities involving machine learning and data science. Python versions that are out-of-date or extremely old may experience a number of issues, one of which is incompatibility with recent packages. The usage
7 min read
How to use GPU acceleration in PyTorch?
PyTorch is a well-liked deep learning framework that offers good GPU acceleration support, enabling users to take advantage of GPUs' processing power for quicker neural network training. This post will discuss the advantages of GPU acceleration, how to determine whether a GPU is available, and how t
7 min read