mlflow.tracking

The MLflow Tracking package provides a Python CRUD interface to MLflow Experiments and Runs. This is a lower level API that more directly translates to REST calls. For a more fluent API of managing an ‘active run’, see mlflow.

class mlflow.tracking.MLflowService(store)

Bases: object

Client to an MLflow Tracking Server that can create and manage experiments and runs. This may either manage files locally or remotely depending on the AbstractStore provided.

create_experiment(name, artifact_location=None)

Creates an experiment.

Parameters:
  • name – must be unique
  • artifact_location – If not provided, the server will pick an appropriate default.
Returns:

integer id of the created experiment

create_run(experiment_id, user_id=None, run_name=None, source_type=None, source_name=None, entry_point_name=None, start_time=None, source_version=None, tags=None)

Creates a new mlflow.entities.Run object, which can be associated with metrics, parameters, artifacts, etc. Unlike mlflow.projects.run(), does not actually run code, just creates objects. Unlike mlflow.start_run(), this does not change the “active run” used by mlflow.log_param() and friends.

Parameters:
  • user_id – If not provided, we will use the current user as a default.
  • start_time – If not provided, we will use the current timestamp.
  • tags – A dictionary of key-value pairs which will be converted into RunTag objects.
Returns:

mlflow.entities.Run which was created

get_experiment(experiment_id)
Returns:mlflow.entities.Experiment
get_run(run_id)
Returns:mlflow.entities.Run associated with this run id
list_experiments()
Returns:list of mlflow.entities.Experiment
list_runs(experiment_id)
Returns:list of mlflow.entities.Run (with only RunInfo filled)
log_artifact(artifact_uri, local_path, artifact_path=None)

Writes a local file to the remote artifact_uri.

Parameters:
  • local_path – of the file to write
  • artifact_path – If provided, will be directory in artifact_uri to write to
log_artifacts(artifact_uri, local_dir, artifact_path=None)

Writes a directory of files to the remote artifact_uri.

Parameters:
  • local_dir – of the file to write
  • artifact_path – If provided, will be directory in artifact_uri to write to
log_metric(run_id, key, value, timestamp=None)

Logs a metric against the given run id. If timestamp is not provided, we will use the current timestamp.

log_param(run_id, key, value)

Logs a parameter against the given run id. Value will be converted to a string.

set_terminated(run_id, status=None, end_time=None)

Sets a Run’s status to terminated

Parameters:
  • status – A string value of mlflow.entities.RunStatus. Defaults to FINISHED.
  • end_time – If not provided, defaults to the current time.
mlflow.tracking.get_service(tracking_uri=None)
Parameters:tracking_uri – Address of local or remote tracking server. If not provided, this will default to the store set by mlflow.tracking.set_tracking_uri. See https://mlflow.org/docs/latest/tracking.html#where-runs-get-recorded for more info.
Returns:mlflow.tracking.MLflowService
mlflow.tracking.get_tracking_uri()

Return the current tracking URI. This may not correspond to the tracking URI of the currently active run, since the tracking URI can be updated via set_tracking_uri.

Returns:the tracking URI.
mlflow.tracking.set_tracking_uri(uri)

Set the tracking server URI to the passed-in value. This does not affect the currently active run (if one exists), but takes effect for any successive runs.

The provided URI can be one of three types:

  • An empty string, or a local file path, prefixed with file:/. Data is stored locally at the provided file (or ./mlruns if empty).
  • An HTTP URI like https://my-tracking-server:5000.
  • A Databricks workspace, provided as just the string ‘databricks’ or, to use a specific Databricks profile (per the Databricks CLI), ‘databricks://profileName’.