Skip to content

This package logs the carbon emissions of machine learning models 🌿

License

Notifications You must be signed in to change notification settings

datarootsio/mlflow-emissions-sdk

Repository files navigation

maintained by dataroots GitHub tag (latest SemVer) Python 3.11 love

logo-dtr

mlflow_emissions_sdk

This package logs the carbon emissions of machine learning models.

Overview

Training and running industrial machine learning models requires significant computing resources. The environment impacts are often overlooked if not neglected. To make ML engineers more aware about the carbon footprint of their projects we created this package.

The package seamlessly integrates the CodeCarbon_package into the MLFlow MLOps package. Extending the logging capabilities of the latter with the carbon tracking methodology of the former.

Installation

To get started, use the package manager pip to install the mlflow-emissions-package:

pip install mlflow-emissions-package

Make sure that you have an mlflow client running:

mlflow ui

By default, the tracking uri is http://127.0.0.1:5000

To log your emissions you need to provide the tracker with the uri and the name of the experiment. If the experiment does not exist then the tracker will create a new experiment with the given name. Example

Usage

from pprint import pprint
import numpy as np
from sklearn.linear_model import LinearRegression
from mlflow_emissions_sdk.experiment_tracking_training import EmissionsTrackerMlflow


# Create a dictionary 
tracker_info = {
    "tracking_uri" : "http://127.0.0.1:5000",
    "experiment_name": "test_name",
    "run_name": "run_name",
    "flavor" : "sklearn"
}
# Prepare training data
X = np.array([[1, 1], [1, 2], [2, 2], [2, 3]])
y = np.dot(X, np.array([1, 2])) + 3

# Pick a model
model = LinearRegression()

# Instatiates the tracker
runner = EmissionsTrackerMlflow()
runner.read_params(tracker_info)

# Starts the emissions tracking
runner.start_training_job()

# Training the model
history = model.fit(X, y)

# Ends the tracking
runner.end_training_job()

License

This project is licensed under the MIT License. You are free to use, modify, and distribute this software as per the terms of the license. If you find this project helpful, please consider giving it a star on GitHub.

Acknowledgements

A special thanks to Emmanuel for his supervision throughout this project.

Contact

About

This package logs the carbon emissions of machine learning models 🌿

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages