Google Colab

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 making your runs 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 run data safe even when the Google Colab kernel has died.

Introduction

This guide will show you how to:

  • Install neptune-client,

  • Connect Neptune to your notebook and create the first run,

  • 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.

Quickstart

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.

Learn more how to find API token.

Step 3: Initialize your Neptune Project

Run the code below:

import neptune.new as neptune
run = neptune.init(project='my_workspace/my_project')

Step 4: Run your training script with Neptune

Run the code below:

# Track metadata and hyperparameters of your run
run["JIRA"] = "NPT-952"
run["algorithm"] = "ConvNet"
params = {
"batch_size": 64,
"dropout": 0.2,
"learning_rate": 0.001,
"optimizer": "Adam"
}
run["parameters"] = params
# Track the training process by logging your training metrics
for epoch in range(100):
run["train/accuracy"].log(epoch * 0.6)
run["train/loss"].log(epoch * 0.4)
# Log the final score
run["f1_score"] = 0.66

Step 5: Check metadata on the Neptune UI

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

What’s next

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