Neptune-Google Colab Integration

What will you get with this integration?

Google Colab is a temporary runtime environment. This means you lose all your data (unless saved externally) once you restart your kernel.

This is where you can leverage Neptune. By running your experiments on Google Colab and tracking them with Neptune you can log and download things like:

  • parameters,

  • metrics and losses,

  • hardware consumption,

  • model checkpoints and other artifacts,

By doing that you can keep your experiment data safe even when the Google Colab kernel has died.


This guide will show you how to:

  • Install neptune-client

  • Connect Neptune to your notebook and create the first experiment

  • Log simple metrics to Neptune and explore them in the Neptune UI

Before you start

Make sure that you have an account with both Google and Neptune.


Step 1: Install Neptune client

Go to your first cell in Google Colab and install neptune-client:

pip install neptune-client

Step 2: Set Neptune API token

  • Go to the Neptune web app and get your API token

  • Run the code below:

    from getpass import getpass
    api_token = getpass('Enter your private Neptune API token: ')
  • Enter the token in the input box. This will save your token to api_token.

Step 3: Initialize your Neptune Project

Run the code below:

import neptune
neptune.init(project_qualified_name = 'your_user_name/your_project_name',
             api_token = api_token)

Step 4: Run your training script with Neptune

Run the code below:

from numpy import random
from time import sleep


neptune.log_metric('single_metric', 0.62)

for i in range(100):
    sleep(0.2) # to see logging live
    neptune.log_metric('random_training_metric', i*random.random())
    neptune.log_metric('other_random_training_metric', 0.5*i*random.random())


Step 5: Check metrics on the Neptune UI

Follow the link shown to view your experiment progress and metrics in the Neptune UI.

What’s next

Now that you know how to integrate Neptune with Google Colab, you can check: