Getting Started with Google Colab: Your Ultimate Setup Guide for Generative AI Projects

Aditya Ravi Raj
4 min readSep 8, 2024

--

Google Colab logo

Google Colab is a cloud-based Jupyter Notebook service that requires no setup and offers free access to powerful computing resources, including GPUs and TPUs. It’s ideal for machine learning, data science, and educational projects. Colab is particularly useful for conducting smaller research experiments that need significant computational power. The free tier provides access to an Nvidia T4 GPU with 15 GB of VRAM and 12 GB of CPU RAM.

  1. Create a Google Account: If you don’t have one already, sign up for a Google account.
  2. Access Colab: To get started with a Colab notebook, simply click here and sign in using your Google account.
  3. Create a New Notebook: Once logged in, you’ll be greeted by a pop-up window. Click on the “New notebook” icon to create a fresh notebook.

4. Name Your Notebook: In the new window, rename your file by clicking on the filename in the top left corner to suit your project.

5. Choose Runtime Type: Decide whether you need a GPU for your task. If not, you can directly click the “Connect” button in the top-right corner. Once connected, you’ll see a prompt confirming the active runtime.

If you need a GPU runtime, you’ll need to adjust the settings by navigating to Runtime -> Change runtime type.

After selecting a pop-up will appear, where you can select your preferred hardware accelerator, such as a T4 GPU or TPU, based on your needs. If you’re unsure which to choose, opt for the T4 GPU, as NVIDIA GPUs are widely supported by most generative AI libraries. After selecting your preferred option, confirm the change by clicking “OK” on the warning message, and then hit “Save.”

You are going to see below changes to your resource tracker.

Keep in mind that each time you change the runtime, all your code blocks will be reset, and you’ll need to re-execute them. This ensures that the new runtime settings are applied across your entire notebook. you can do this easily from Runtime -> Run all.

6. To add a secret key, click on the key icon in the left panel. Since it’s your first time, you won’t have any secrets listed yet. Click on “Add new secret”. As a best practice, give your secret a name using all uppercase letters and underscores (e.g., API_KEY_NAME). Then, paste your API key into the value field.
For google you can get a free api key from here or by going to the “Create Gnemini API Key”

Note: The free tier of Colab comes with limitations on GPU runtime sessions, which you can check here. Due to these restrictions, I typically write and test my code in a CPU environment before switching to a GPU runtime to execute all the code blocks of the final version.
Alternatively, you can opt for a Colab Pro subscription, which provides access to more powerful GPUs, such as the NVIDIA A100, along with longer and more stable runtime sessions. This can be especially useful for larger-scale projects that require extended compute resources.

Thanks for reading!

I love writing about Generative AI, Data Structures and coding concepts. Feel free to connect with me here on Medium or on LinkedIn.

--

--

Aditya Ravi Raj
Aditya Ravi Raj

Written by Aditya Ravi Raj

Software Developer with 2 years of experience in Java Backend and generative AI.