How to Use Google Colab Notebooks

Google Colab Notebook was released in late 2017 to make a huge impact in machine learning, artificial intelligence, and data science work.

The number of users accessing the Colab Notebook has increased significantly since the advent of generative AI—particularly Stable Diffusion (SD). Apart from machine learning, data science, and artificial intelligence enthusiasts, ordinary people have started using the Colab notebook to access multiple interesting AI text-to-image models.

To navigate in the world of text-to-image art generators, it is essential to know how to use the Google Colab Notebook.

In this article, I will be explaining how to use Google Colab Notebook in general. But, depending on the Colab notebook, access may vary slightly, and that information can be found in the notebook’s instructions.

What is Google Colab Notebook?

Google Colab Notebook is an interactive environment to write, execute, and share Python code that entirely runs in the cloud. This means you can run the code with zero configuration, free-to-use GPUs, and easy sharing.

This Jupyter notebook is completely free to use and can be run for at most 12 hours depending on the availability and usage pattern. However, you can also opt-in for paid plans if you want more run time and powerful GPUs.

Colab also has three paid options:

Pay As you Go: $9.99 for 100 Compute Units; $49.99 for 500 Compute Units

Colab Pro: $9.99/ month for 100 compute units per month with 90-day validity, faster GPUs, and more memory

Colab Pro+: $49.99/ month for 500 compute units per month with 90-day validity, faster GPUs, more memory, and background execution

Google Colab Pricing

How to Use Google Colab Notebooks

  1. Sign In to your Google Account
  2. Make a Copy in your Google Drive
  3. Check GPU Status
  4. Run Each Cell
  5. Wait for the Result

1. Sign In to your Google Account

Since Colab Notebook is a Google product, you need to sign in to your Google account to use any of the Colab Notebooks.

Once you have signed into your Google account, you can interact with the Google Colab notebook, the web IDE.

2. Make a Copy in your Google Drive

Making a copy of the Colab notebook that you want to access is an optional step.

Some Colab notebooks, such as Disco Diffusion and DreamBooth require access to your Google Drive since they want to store the generated images somewhere. If you encounter these kinds of Colab notebooks, you need to make a copy of them on your Google Drive.

To do so, you need to click File” > “Save a copy in Driveon the Google Colab notebook.

Save the Disco Diffusion into your Google Drive

Other Colab notebooks, like Reverse Prompt Lookup require no access to your Google Drive. In these cases, you don’t need to make a copy on your Google Drive or give access to your Google Drive.

If you are not sure what kind of Colab notebook you are trying to access, just go ahead and follow the next steps without making any copy of it.

3. Check GPU Status

If you are accessing the Colab notebook that is related to generative AI/ text-to-image art generators, you will need a GPU allocation.

By default, the Google Colab notebook will allocate a GPU for you. However, it is important to cross-check it.

To do so, click “Runtime” and see if “GPU” is selected under “Hardware accelerator”.

If GPU is selected, click “Save”. If not, select the GPU manually from the dropdown.

GPU Status on Google Colab

There are three GPUs available in the Colab notebook free plan, namely, the Tesla K80, the Tesla P100, and the Tesla T4.

The Tesla P100 and Tesla T4 perform faster than the Tesla K80 among these GPUs. However, the Tesla K80 GPU is the most commonly allocated GPU in the Google Colab free version.

But, I will give you a tip to get a Tesla T4 or a Tesla P100. To get the Tesla P100 or Tesla T4 GPU in the Google Colab notebook,

  • Click the “Down arrow” in the upper right corner of the Colab notebook. Then, navigate to “Manage session” and click on it. Now, you have to terminate your current active session by clicking on “TERMINATE”.

P100 or T4 GPU

  • Then, you need to start a new session. To do so, run the “Check GPU Status/ Check GPU”.

GPU in Google Colab

  • Repeat this process until you get Tesla T4 or Tesla P100

4. Run Each Cell

After checking the GPU status, all you need to do is run every cell one by one. To do so, just click the “Play” button and wait for the green tick before running the next cells.

However, you need to change certain values in some cells—such as changing the prompt, changing the image URL, or uploading your images before running it. Like I did in Disco Diffusion and Reverse Prompt Lookup.

If you get a warning while started running the cells, just click “Run anyway“.

Use Google Colab Notebooks

5. Wait for the Result

Now, it is time to wait for the output. You will be able to see the output within a few minutes depending on the GPU you are assigned. The more powerful the GPU, the faster the output.

Make sure to not leave the Colab tab not more than a minute or so. If being away for too long, the execution will be failed.

Once the execution is successful, you will get the AI-generated images either on your Google Drive or on the same Colab tab according to the Colab notebook nature.

Conclusion

This is how you can use Google Colab notebook for generative AI models.

You can also write, present, and share your code in the Colab notebook. But, this article is more about how to use Colab in terms of an ordinary user, who is looking to explore the AI text-to-image, text-to-audio, text-to-video, and text-to-animation open-source models.

Share this:

Leave a Comment