FREE GPU to Train Your Machine Learning Models

Mohammed AL-Ma'amari
6 min readJul 11, 2021

Table of Contents:

  1. Introduction
  2. First Way: Using Google Colaboratory:

3. Second Way: Using Kaggle

4. Resources

Why do we need GPUs:

Training a deep learning model that involves intensive compute tasks on extremely large datasets could take days to run on a single processor. However, if you design your program to offload those tasks to one or more GPUs, you can reduce training time to hours instead of days. [source]

[read more] or [here]

How Much Do GPUs Usually Cost?

GPU cloud services could cost from 3 cents to more than 3$ per hour.

This blog shows a comparison of the GPU cloud pricing

But how can one use high-end GPUs for free?

In this blog, I am willing to show you two ways that allow you to train your Machine Learning models for free and without subscribing to any paid service.

First Way: Using Google Colaboratory:

What is Colaboratory?

As mentioned on the official page, “Colaboratory, or “Colab” for short, is a product from Google Research. Colab allows anybody to write and execute arbitrary python code through the browser, and is especially well suited to machine learning, data analysis, and education. More technically, Colab is a hosted Jupyter notebook service that requires no setup to use, while providing free access to computing resources including GPUs.”

How to use GPU in Google Colaboratory Notebook:

1- Create a Google Colaboratory Notebook:

[From Here]

or you can try one of my notebooks [here]:

2- Change the Runtime Type:

a small window will appear:

Choose GPU and save, the notebook will be reset with the new runtime type.

CPU VS GPU:

To see if using GPU really reduces the training process time, training time using CPU is compared to GPU training time:

Training time when using CPU would be about an hour per epoch

On the other hand, training using GPU took exactly 74 seconds (~37 sec/epoch) proving that GPUs are much much faster than CPU when it comes to fitting(training) Neural Networks.

What are the Limitations of Google Colaboratory Notebooks:

Colab resources are not guaranteed and not unlimited, and the usage limits sometimes fluctuate. This is necessary for Colab to be able to provide resources for free. [source]

How long can notebooks run in Colab?

The session can run up to 12 hours, but if the notebook was idle for a long time session could end in less than 1 hour.

What are the usage limits of Colab?

The resources limits can defer from time to time, but usually it is around:

  • Around 12.5 GB of RAM (when not using GPU runtime)
  • 12GB of NVIDIA Tesla K80 GPU (when using GPU runtime)
  • Disk space depends on the free space in your Google Drive.

For more details, see Resource Limits.

You can measure the GPU memory allocated for your notebook using the code provided [here]

Second Way: Using Kaggle:

This is the best way and my go to solution because of many reasons that will be introduced later.

How to use GPU in Kaggle Notebooks:

1- Create a Kaggle Notebook:

[From Here]

or you can try one of my notebooks [here]:

2- Change the Advanced Settings and Choose GPU as the Accelerator:

CPU VS GPU:

To see if using GPU really reduces the training process time, training time using CPU is compared to GPU training time:

Training time when using CPU would be about 33 minutes per epoch

Training using GPU took exactly 42 seconds (21 sec/epoch) proving that GPUs are much much faster than CPU when it comes to fitting(training) Neural Networks.

Can I change from CPU to using GPU after creating the notebook?

Yes, from the right side Settings -> Accelerator -> GPU

What are the Limitations of Kaggle Notebooks:

  • Session time is 9 hours (32400 seconds).
  • CPU usage time is unlimited.
  • GPU quota fluctuates from 30 to 50 hours/week

For more details see [Kaggle Notebooks Documentation]

Why Kaggle Notebooks are Much Better Than Google Colab:

1- Google Colab notebooks need to be open and active during the using and training time, while you can commit a kaggle notebook then close it if you want to come later and see the training results.

Committing a Kaggle notebook

2- In Kaggle you can use any dataset from Kaggle, you can also connect your notebook to your Google Drive.

3- Google Colab uses your Google Drive disk space, so if you run out of disk space you have to free some space out of your Drive, while Kaggle gives you 4GB of disk space.

4- Google Colab gives you ~13GB of GPU memory space, while Kaggle allocates 16GB of GPU memory space to your notebook.

These 4 reasons are not the only reasons that using Kaggle would be your best choice but they are enough to make you prefer Kaggle on Colab.

Resources:

You can follow me on:

--

--

Mohammed AL-Ma'amari

I am a computer engineer | I love machine learning and data science and spend my time learning new stuff about them.