Skip to main content

MLflow integration for ai2-tango

Project description

tango-mlflow

Actions Status Python version pypi version License

MLflow integration for ai2-tango

Introduction

tango-mlflow is a Python library that connects the Tango to MLflow. Tango, developed by AllenAI, is a flexible pipeline library for managing experiments and caching outputs of each step. MLflow, on the other hand, is a platform that helps manage the Machine Learning lifecycle, including experimentation, reproducibility, and deployment.

This integration enables you to store and manage complete experimental settings and artifacts of your Tango run in MLflow, thus enhancing your experiment tracking capabilities.

Here's a screenshot of the MLflow interface when executing with tango-mlflow:

239279085-79ca2c6b-f9a1-49aa-a301-bb502a2340d2

  • Tango run: The top-level run in MLflow corresponds to a single execution in Tango, and its name matches the execution name in Tango.
  • Tango steps: Results of each step in Tango are recorded as nested runs in MLflow. The names of these nested runs correspond to the names of the steps in Tango.
  • Parameters and Metrics: The entire settings for the execution, as well as the parameters for each step, are automatically logged in MLflow.
  • Artifacts and Caching: The cached outputs of each step's execution are saved as artifacts under the corresponding MLflow run. These can be reused when executing Tango, enhancing efficiency and reproducibility.

Installation

Install tango-mlflow by running the following command in your terminal:

pip install tango-mlflow[all]

Usage

You can use the MLFlowWorkspace with command line arguments as follows:

tango run --workspace mlflow://your_experiment_name --include-package tango_mlflow

Alternatively, you can define your configuration in a tango.yml file:

workspace:
  type: mlflow
  experiment_name: your_experiment_name

include_package:
  - tango_mlflow

In the above tango.yml configuration, type specifies the workspace type as MLflow, and experiment_name sets the name of your experiment in MLflow. The include_package field needs to include the tango_mlflow package to use tango-mlflow functionality.

Remember to replace your_experiment_name with the name of your specific experiment.

Functionalities

Logging metrics into MLflow

The tango-mlflow package provides the MLflowStep class, which allows you to easily log the results of each step execution to MLflow.

from tango_mlflow.step import MLflowStep

class TrainModel(MLflowStep):
    def run(self, **params):

        # pre-process...

        for epoch in range(max_epochs):
            loss = train_epoch(...)
            metrics = evaluate_model(...)
            # log metrics with mlflow_logger
            for name, value in metrics.items():
                self.mlflow_logger.log_metric(name, value, step=epoch)

        # post-process...

In the example above, the TrainModel step inherits from MLflowStep. Inside the step, you can directly record metrics to the corresponding MLflow run by invoking self.mlflow_logger.log_metric(...).

Please note, this functionality must be used in conjunction with MLFlowWorkspace.

Summarizing Tango run metrics

You can specify a step to record its returned metrics as representative values of the Tango run by setting the class variable MLFLOW_SUMMARY = True. This feature enables you to conveniently view metrics for each Tango run directly in the MLflow interface

class EvaluateModel(Step):
    MLFLOW_SUMMARY = True  # Enables MLflow summary!

    def run(self, ...) -> dict[str, float]:
        # compute metrics ...
        return metrics

In the example above, the EvaluateModel step returns metrics that are logged as the representative values for that Tango run. These metrics are then recorded in the corresponding (top-level) MLflow run.

Please note the following requirements:

  • The return value of a step where MLFLOW_SUMMARY = True is set must always be dict[str, float].
  • You don't necessarily need to inherit from MLflowStep to use MLFLOW_SUMMARY.

Tuning hyper-parameters with Optuna

tango-mlflow also provides the tango-mlflow tune command for tuning hyperparameters with Optuna. For more details, please refer to the examples/breast_cancer directory.

Examples

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tango_mlflow-1.1.0.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

tango_mlflow-1.1.0-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

Details for the file tango_mlflow-1.1.0.tar.gz.

File metadata

  • Download URL: tango_mlflow-1.1.0.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.9 Linux/5.15.0-1037-azure

File hashes

Hashes for tango_mlflow-1.1.0.tar.gz
Algorithm Hash digest
SHA256 ae8a7358711438a194441a66875a5b5a5499c3d082310af4ad07f886030fbfdc
MD5 6708c9147e72e824209d84deab86005b
BLAKE2b-256 b42aef6822917a3bee307fc7aae714caf4bec85f2b5f83441d4c9df7150a729d

See more details on using hashes here.

File details

Details for the file tango_mlflow-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: tango_mlflow-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.9 Linux/5.15.0-1037-azure

File hashes

Hashes for tango_mlflow-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 79b62994227847a7b00fb1fe2d0853c7338855d879a9f22702d3db008ce15ed0
MD5 196fc29f69b595644f45e9607a951fba
BLAKE2b-256 75097b005bf3196d814d7e402062aa2a6aa4d74edd1cbddbbb039293102c12b8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page