Intro to Google Colab, how to use a GPU or TPU for free

A free video tutorial from Lazy Programmer Inc.
Artificial intelligence and machine learning engineer
43 courses
614,403 students
Learn more from the full course
[2025] Tensorflow 2: Deep Learning & Artificial Intelligence
Machine Learning & Neural Networks for Computer Vision, Time Series Analysis, NLP, GANs, Reinforcement Learning, +More!
26:23:49 of on-demand video • Updated June 2025
Artificial Neural Networks (ANNs) / Deep Neural Networks (DNNs)
Predict Stock Returns
Time Series Forecasting
Computer Vision
How to build a Deep Reinforcement Learning Stock Trading Bot
GANs (Generative Adversarial Networks)
Recommender Systems
Image Recognition
Convolutional Neural Networks (CNNs)
Recurrent Neural Networks (RNNs)
Use Tensorflow Serving to serve your model using a RESTful API
Use Tensorflow Lite to export your model for mobile (Android, iOS) and embedded devices
Use Tensorflow's Distribution Strategies to parallelize learning
Low-level Tensorflow, gradient tape, and how to build your own custom models
Natural Language Processing (NLP) with Deep Learning
Demonstrate Moore's Law using Code
Transfer Learning to create state-of-the-art image classifiers
Earn the Tensorflow Developer Certificate
Understand important foundations for OpenAI ChatGPT, GPT-4, DALL-E, Midjourney, and Stable Diffusion
English [Auto]
In this lecture we are going to go over a very new and exciting environment for writing deep learning code in Python which is Google's core lab short for code laboratory. For those of you who like to use Jupiter notebook this is an even better option. This is basically the same as you put a notebook with the following bonuses first. It's hosted by Google which means you don't have to use your own computing power. You'll notice that when you need to download data files it happens extremely quickly because while Google's network is extremely fast. Second you get access to a GP you and even Google's new TB you which is pretty amazing a tepee you is not something you can buy for your personal computer. So it's pretty nice to be able to make use of one. Remember that the weight tends to flow code is written. You don't have to worry about what kind of device you're using. Well for the most part generally speaking the same code will work whether you're using a CB you GP you or TB you third the code lab notebooks are stored in your google drive. So it's in the cloud. You'll never lose it and it's very easy to share with other people. Fourth is that many of the libraries you need for deep learning machine learning and data science are already included. In fact I was surprised that there were many more than I assumed there would be. There are even competing Deep Learning libraries already included such as piano and Pi torch. So for those of you who hate doing environments setup myself included this is really truly awesome. So in this lecture we're not going to do anything really technically complicated. Rather we're just going to talk about Google collab and do some short demos. So you know how it works and can see for yourself that it's just like writing Python anywhere else to start. I'm going to assume you already know how to create a Google Drive account if you don't have one go to drive dot google dot com and sign up once you have your google drive account and you've logged in you'll see this interface from here. You can hit the new menu which allows you to create all different kinds of files such as Google Docs a spreadsheet presentation and so forth. So let's do this. So now what you want to do is go to the more menu and hit code laboratory. All right. So as you can see this brings up a new notebook. And from here you can mostly use this as you would a normal notebook. Now one thing that might happen to you is that you might not see core laboratory in the menu at all. So as you can see I've hit the new menu and I've hit more but I don't see color in this case. Here's what you can do. You want to select connect more apps from here. Just search for collab. And the first thing that will pop up is Google's collab add this and Google collab will become available from the menu which is looked at so if we go there again we can see that cold app and now appears where it should so let's go in and rename this notebook to TAF 2.0 intro. So first we're gonna get right to the good stuff. How can we make use of a GP you or TB you in order to do this. You want to go to the runtime menu and select change runtime type as you can see there are two select boxes here. The first one lets you select which python version you want to use. So we'll be using Python 3 for this cause. The second lets you select what kind of device you want to use. So that's either none which is the default or GP you or TB you now note that sometimes the GP you or TB you might not be available. This is because these are shared resources so your fellow peers taking this course and other machine learning students and researchers all around the world might be using Google whole app and we are all sharing these resources. So if our usage of these resources hits the limit of what's available then you might not have a GP you or you available when you need them. For this reason some of the code you'll see in this course may be done on my local machine as well. But remember Python code works the same anywhere so it does not make a difference next. You can see that there are two main types of cells that we can create in the notebook code and text. You can click on either of these to create a new cell of that type let's click on text since that's a little easier and it's not really something we are going to use very often. So let's just get it out of the way so I'm actually going to delete the very first cell all right. So as you can see when I click this it creates a new cell with what looks like a rich text editor. You'll notice that it's split into halves the left half is where you enter your text and the right half is a preview of what it will look like. So let's enter some text. This is my title now you can click the little T Big T icon which changes it into header text so you can see that it makes this a little bigger and bolder appropriate for a title next let's enter some regular text. This is regular text and note that there are also these arrow brackets so it looks like it's going to let us enter code snippets. So let's try that. And so as you can see it makes the text a mono space font which is appropriate for code. Now there are some other options here. So you can make a link you can add images you can indent. You can add a numbered or bullet list and so forth. So if you're interested play around with this. Otherwise we're not going to mention it again. Next we have the code cell. So let's create one of those all right. And as mentioned we're not going to write any fancy code in this lecture. We just want to do something simple to make sure everything works as expected. So let's start by importing num pi and map plot lib all right. Beautiful. As I mentioned earlier these already company installed next let's create a new code cell and make a sine wave. So first we need to create some x values so let's make X go from zero to 10 pi with 1000 points in between next let's make Y at the sign of X next let's create a new cell and plot what we just created so that's just peels heat up plot x y now since this is a notebook there's no need to call peels that show since the plot will just appear in the notebook itself. All right. Very cool works just like a regular notebook at this point. We've convinced ourselves that Google collab can do the usual things you'd expect from a group in a notebook. Now as I mentioned earlier one thing that's very nice about COLA is that it already comes with a bunch of useful libraries pre installed. In my opinion this makes Google Ecolab way better than Japan a notebook. And if anyone ever asked me to write in a notebook environment I would choose color by default. I'm not a big fan of notebook but I am a big fan of collab so here we can see that I've written some code to try and import a bunch of libraries specifically these libraries are libraries that have been using my causes some more than others. Some are pretty rarely used so you might not expect that they would be included. Libraries like word cloud which we've only used once so far and yet if we look we see that everything I've tried to import here does not throw an error so this tells us that these libraries are indeed available. What's interesting to me is that some of these libraries are not machine learning related at all. Of course we've used them in my courses because they are generally useful as Python libraries but it's nice to see the folks at Google also make use of these same libraries and so thought to include them. So here you can see the usual stuff such as psychic learn name pi CI pi map plot live and pandas. We also have torch and piano which is surprising because they are competing deep learning libraries and development with piano has been stopped for a while now. We also have seaborne word cloud beautiful soup which is for example at a CML passing requests which is for making a CTP cause network X which is for graph functionality CV 2 which is for open CV and gym which is open a gym. All in all very impressive and much more than I expected so there are some final caveats to call that that I want to mention. First the main thing you have to remember is that this is the cloud. So these are shared resources. So one way this affects you is if you leave your notebook alone for a long time it will become inactive and disconnect any computation that you may have run earlier won't be saved. So for example if you define a variable A equals five AND THEN YOU COME BACK LATER AFTER your notebook was disconnected and you tried to print a it'll say a is not defined so you see this notebook has disconnected. So let's say to reconnect and I print a it's gonna say a is not defined another way this affects you is that you might run out of memory. So if that happens you might want to try running the code on your local machine instead. And as mentioned earlier the GP you A.P. you might be unavailable. So either you can run your code without the GP you or TB you or you can run the same code locally as always options you had previously are still available for example you can provision a GP you instance on a W.S. which if you choose the correct EMI or Amazon machine instance will come with the usual libraries pre installed also.