Skip to content

Integrate with Comet

CodeCarbon integrates seamlessly with Comet, a powerful experiment tracking and visualization platform. This integration allows you to track the carbon footprint of your machine learning experiments alongside your training metrics, hyperparameters, and other experiment details.

Summary

Prerequisites

Before you begin, you'll need:

  1. A Comet account (free tier available)
  2. Your Comet API key (available in your account settings)

Installation

Install the required Comet ML library:

pip install comet_ml>=3.2.2

Setup Steps

Step 1: Create a Comet Account

  1. Go to Comet's website and create a free account
  2. From your account settings page, copy your personal API key

Step 2: Configure Your Experiment

In your Python script, initialize a Comet experiment with your API key:

from comet_ml import Experiment
from codecarbon import EmissionsTracker

experiment = Experiment(api_key="YOUR API KEY")

Step 3: Run Your Experiment

Run your experiment as normal. CodeCarbon will automatically create an EmissionsTracker object that Comet will track:

# Your training code here
model.fit(X_train, y_train)

Step 4: Add the CodeCarbon Footprint Panel

Once your experiment completes, view it in the Comet UI:

  1. Click on the Panel tab in the left sidebar
  2. Click Add Panel
  3. In the Panel Gallery, click the Public tab
  4. Search for CodeCarbon Footprint
  5. Add the panel to your experiment

Summary

Step 5: Save Your View

To automatically display the CodeCarbon visualization in future experiments, save your View from the Panels tab.

Summary

Example

A complete working example is available in the CodeCarbon repository at examples/mnist-comet.py.

Next Steps