Collaborative experiment tracking in Kedro-Viz
Tags: kedro, machinelearning, python, tutorial
Published: 2023-06-02 14:09:58

When training a model in machine learning, the goal is to determine the optimal configuration of attributes such as hyper-parameters, metrics, and training data. The process of identifying the best combinations requires running a lot of experiments and comparing them. As I mentioned in my [previous article](https://kedro.org/blog/experiment-tracking-with-kedro), experiment tracking is a way to record all the metadata you need to compare machine-learning experiments and recreate them for your project.

## What is Kedro-Viz?

[Kedro-Viz](https://github.com/kedro-org/kedro-viz) is an interactive development tool for building and visualising data science pipelines with [Kedro](https://github.com/kedro-org/kedro). It enables you to monitor the status of your ML project, present it to stakeholders, and easily bring new team members up to speed. You can try it out using our [hosted demo](https://demo.kedro.org/).

“_There's no better method to give an overview of a pipeline's structure in such an engaging, interactive, and thorough way. Our asset's pipelines are very complex, but are structured with modular pipelines, so being able to show the overall structure at the modular pipeline level, before jumping into each individual pipeline helps prevent the audience from getting overwhelmed by the number of nodes and datasets shown_”.

**Senior Data Scientist at Consultancy**

## What is experiment tracking in Kedro-Viz?

Experiment tracking on Kedro-Viz enables users to select, plot, and compare how multiple metrics change over time, and identify the best-performing ML experiment, with no additional dependencies to manage or infrastructure needed.

The video below demonstrates experiment tracking on Kedro-Viz:

{% embed https://youtu.be/odXhTEa50PU %}

During a project with multiple team members, you could end up with a scenario where the results of your experiments are spread across many machines because people are iterating on their individual computers. This makes the tracking process difficult to manage at a team level, as suggested by this feedback from our users.

> _"You might train one model locally on your computer. You might train another one in the cloud. Joe might run another pipeline or another experiment. Having all of those experiments in one place as a single source of truth is really powerful._

> _"If we could write our metrics files to an S3 bucket and then run experiment tracking pointing at that S3 bucket, that simplifies our workflow in many different ways and would be really helpful. And it would make Kedro experiment tracking just as easy, if not easier, than MLFlow for us."_

> _"Can you use an existing database so that we can keep track of runs happening in different places?_"

We have found a way to address this pain point and enable you to collaborate more easily. We are excited to announce that we've [launched collaborative experiment tracking](https://www.linen.dev/s/kedro/t/12096327/kedro-kedro-kedro-kedro-kedro-kedro-viz-6-2-0-is-out-kedro-k#ba733439-8aac-46f5-9c37-d015287835cc) in Kedro-Viz 6.2.0. The new feature enables a team of users to log their experiments to a shared cloud storage service and view and compare each others' experiments in their own experiment tracking view. This simplifies their workflow, providing a single ‘source of truth’ and encourages multi-user collaboration.

We are releasing this feature in stages across different versions, and the first phase is [Kedro-Viz 6.2.0](https://github.com/kedro-org/kedro-viz/releases). This version enables users to read experiments of other users that are stored on Amazon S3 or similar storage solutions on other cloud providers, as long as they are supported by [fsspec](https://filesystem-spec.readthedocs.io/en/latest/). Future versions of collaborative experiment tracking aim to improve the user experience through automatic reloading and optimisation by caching.

## Get started with collaborative experiment tracking

Follow these steps to set up collaborative experiment tracking in Kedro-Viz:

### Step 1: Update Kedro-Viz

Ensure you have the latest version of Kedro-Viz (6.2.0 or later).

```bash
pip install kedro-viz --upgrade
```

### Step 2: Set up cloud storage

Kedro-Viz uses [fsspec](https://filesystem-spec.readthedocs.io/en/latest/api.html?highlight=s3#other-known-implementations) to save and read `session_store` files from a variety of data stores, including local file systems, network file systems, cloud object stores (e.g., Amazon S3, Azure Blob Storage, Google Cloud Storage), and HDFS.

Set up a central cloud storage repository such as a AWS S3 bucket to store all your team's experiments.

### Step 3: Configure your Kedro project

Locate the `settings.py` file in your Kedro project directory and add the following:

```python
from kedro_viz.integrations.kedro.sqlite_store import SQLiteStore
from pathlib import Path

SESSION_STORE_CLASS = SQLiteStore
SESSION_STORE_ARGS = {
    "path": str(Path(__file__).parents[2] / "data"),
    "remote_path": "s3://my-bucket-name/path/to/experiments",
}
```

### Step 4: Set up a unique username

Kedro-Viz saves your experiments as SQLite database files on the central cloud storage. To ensure that all users have unique filenames, you need to set up your `**KEDRO_SQLITE_STORE_USERNAME**` in the environment variables. By default, Kedro-Viz will take your computer username if this is not specified.

```bash
export KEDRO_SQLITE_STORE_USERNAME ="your_unique__username"
```

### **Step 5: Configure cloud storage credentials**

From Kedro-Viz version 6.2, the only way to set up credentials for accessing your cloud storage is through environment variables, as shown below for [Amazon S3 cloud storage](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html).

```bash
export AWS_ACCESS_KEY_ID="your_access_key_id"
export AWS_SECRET_ACCESS_KEY="your_secret_access_key"
export AWS_REGION="your_aws_region"
```

In the screenshot below we show an example of the session store and Kedro-Viz output for three team members (Huong, Tynan, and Rashida):

![Session store showing the 3 objects for Huong, Tynan, and Rashida](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vt9sgfuto8gzhbf11h6v.png)

Session store showing the 3 objects for Huong, Tynan, and Rashida.

![Three separate Kedro-Viz runs by Huong, Tynan, and Rashida](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/juydxwja7hlf4r61lwe0.png)

Three separate Kedro-Viz runs by Huong, Tynan, and Rashida.

This tutorial offers a very swift run through of the configuration process. For further information, check out the [documentation on the experiment tracking feature](https://docs.kedro.org/en/stable/experiment_tracking/index.html) and keep up-to-date with the latest news about Kedro and Kedro-Viz on our [Slack workspace](https://slack.kedro.org).

Many thanks to the Kedro-Viz team especially [@Rashida Kanchwala](https://github.com/rashidakanchwala) for contributing to this post.