Improve the Performance of Your Google Colab with Just 7 Lines of Code

Joe Ng
2 min readFeb 2, 2020

--

The Google Colaboratory is a free Jupyter notebook environment that requires no setup and runs entirely in the cloud.Most importantly, it provides a free GPU/TPU for acceleration of training processes in ML.

Should You choose GPU or TPU?

Generally,the TPU(Tensor Processing Unit)takes considerably more training time than the GPU when the batch size is small.When batch size increases the TPU performance is comparable to that of the GPU. A lot of users still prefer the GPU(Nvidia Tesla K80) over the TPU.

Increase Your RAM space from 12 GB to 25 GB

Trust me, just type these 3 lines of code and this will probably be the first time in your programming/Machine Learning career that you are actually happy when an error occurs. Despite this, be aware that your runtime’s state and all your local files would be LOST after this action. Therefore, only use this whenever you are sure that you can afford run all the code all over again or you are creating a new project.

arr=[]
while(1):
arr.append(1)

You should see this appear on your PC screen after the error:

The choice is definitely a no-brainer. After switching to the 25 RAM runtime environment, your connection to the Google Compute engine Backend would also be more stable.

Load Huge Datasets Using the Unzip Method to Save Disk Memory

First and foremost, upload the zip file of the dataset to your Google Drive.Then mount your drive:

from google.colab import drive
drive.mount('/content/drive')

You should be able to see the ‘drive’ folder which contains the contents of your Google Drive lying in the ‘files section. Go from Files →drive →My Drive →YOUR UPLOADED ZIP FILE. Right click at the zip file to copy its path. Run this snippet:

!unzip -q “COPIED_PATH_OF ZIP_FILE”
!rm “COPIED_PATH_OF ZIP_FILE”
#rm is to remove the unneeded zip file after unzipping it

Voila! The folders in your dataset will appear in the ‘Files’ section.

In conclusion, there are still many amazing features of Colab for us to explore. If you are getting started for AI/Deep Learning, Colab is a great avenue to deploy your model in a Jupyter environment without having to purchase any hardware. Happy coding!

--

--