read_mlflow_metrics

read_mlflow_metrics(
    runs
    *
    keys=None
    x='step'
    smoothing=0.0
    max_points=DEFAULT_MAX_POINTS
    tracking_uri=None
)

Read the training curves of MLflow runs.

One chart per metric, as the MLflow UI’s model metrics draw it: the step along the x axis, the value along the y axis, and one line per run.

Parameters

Name Type Description Default
runs str, mlflow.entities.Run, pandas.DataFrame, or iterable of these The runs, as for :func:load_mlflow_metrics: a run id, a run, what mlflow.search_runs() returns, or a list of ids and runs. required
keys iterable of str Only these metrics, in this order, such as ["train_loss"]. None
x ('step', 'relative_time') What the x axis counts. "step"
smoothing float A smoothing weight, from 0 up to but not including 1, applied as TensorBoard applies it. Above 0, each run is drawn twice: as logged, and smoothed, under the run’s name followed by (smoothed). 0 draws the values as logged only. 0
max_points int or None At most this many points per line, evenly spaced and always keeping the first and last, so a long run stays quick to walk. None keeps every point. 1000
tracking_uri str The tracking server to read from. By default MLflow’s own. None

Returns

Name Type Description
list of maidr.mlflow.MetricChart One per metric. Pass one to :func:maidr.show, :func:maidr.render or :func:maidr.save_html, or store it in a run with :func:log_mlflow_chart.

Raises

Name Type Description
ImportError If mlflow is not installed.
ValueError If x is not one of the above, smoothing is not in [0, 1) or max_points is below 2.

Notes

Every value of a metric is read, with MlflowClient.get_metric_history, and placed in order of its step and then the time it was logged, so two values logged at one step are both kept, in the order they were logged. max_points then thins the line. A logged NaN is a gap in it.

Examples

>>> import mlflow
>>> import maidr
>>> runs = mlflow.search_runs(experiment_names=["llm-finetune"])
>>> charts = maidr.read_mlflow_metrics(runs, keys=["train_loss"])
>>> maidr.save_html(charts[0], "loss.html")