Cert EspressoLearn. Practise. Find your flow.

A LITTLE FOCUS.
A BIG NEXT STEP.

Your pace. Your space.
Databricks · Databricks Machine Learning Professional

Nested runs and custom logging in MLflow

Databricks Machine Learning Professional · Lesson 8 of 22 · 52:45

YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗

Learning with these videos? Subscribe for new courses and exam-style questions.

In this lesson

Prepare for the Databricks Certified Machine Learning Professional exam. In this lesson: parent and child runs, finding the children of a run, custom metrics with steps and custom parameters, and custom artifacts such as figures and files. Includes three original practice questions.

Study notes

The text of this lesson, to read at your own pace. Information as of November 2026.

Three hundred runs

Pebblecove's data scientists ran three hundred tuning trials last week, and the experiment now shows a flat list of runs that nobody can read. Which trials belong to which search, which model won, and where is the confusion matrix of the winner? This lesson covers nested runs in MLflow, and logging your own metrics, parameters, and artifacts from code.

Parent and child runs

A nested run is a run started inside another run, which becomes its parent run. You open the parent with mlflow dot start_run, and inside it, you open each child run with start_run and nested set to true. MLflow tags every child with mlflow dot parentRunId, the identifier of its parent, and the experiment page groups the children under their parent, so three hundred trials become three searches that you can expand. Typical uses are one parent for a tuning search and one child per trial, one parent per model family, or one child per group, like each home of lesson five.

Finding the children

To read the results from code, mlflow dot search_runs takes a filter string. A filter on the tag mlflow dot parentRunId, equal to the parent's identifier, returns all its children as a pandas DataFrame, with their parameters and metrics as columns. You can then sort them by a metric, and log a summary to the parent, like the best score and the best parameters, so the parent tells the story of its search.

Custom metrics and parameters

Beyond autologging, you can log anything from code. log_param and log_params record inputs, like a hyperparameter or the name of the training table, and set_tag adds metadata to filter on later, like the region or the model family. log_metric logs a number, and its step argument builds a series, like the validation loss at each epoch, which the run page draws as a curve. A custom metric is just a value that your own code computes, like the cost of the missed cancellations, logged next to the standard ones. And log_input records the dataset that trained the model, to keep its lineage.

Custom artifacts

Artifacts are files attached to a run. log_artifact uploads one file, like a confusion matrix image or a feature importance report, and log_artifacts uploads a whole folder. Some helpers skip the file: log_dict writes a dictionary in JSON or YAML, log_text writes a string, log_figure writes a matplotlib or plotly figure, and log_table writes a table that the run page can display. Large outputs, like a full table of predictions, are better written as files, then logged, or stored in a volume. And to write to a run that is not active, like a finished parent, MlflowClient takes the run identifier, with the same kinds of calls.

Recap

Let's recap. A child run is opened with start_run and nested set to true, inside its parent run. Each child carries the tag mlflow dot parentRunId, and search_runs with a filter on it returns the children. Parameters and tags hold inputs and metadata, and log_metric with a step builds a curve. Artifacts are files: log_artifact for a file, and log_dict, log_text, log_figure, or log_table for objects. And MlflowClient writes to any run by its identifier.

Quick checks for this lesson

The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.

  1. A tuning loop calls start_run for each trial while the parent run is active, but without nested=True. What happens?

    • The trial runs become children anyway
    • MLflow raises an error: a run is already active
    • The parent run is ended and replaced
    • Each trial goes to a new experiment
    Show the answer

    MLflow raises an error: a run is already active

    Start_run will not open a second active run unless nested is true, so it raises an error. “The trial runs become children anyway” is wrong, since only nested runs become children. “The parent run is ended and replaced” is wrong, since the active parent is not ended for you. And “Each trial goes to a new experiment” is wrong, since runs stay in the active experiment.

  2. Which filter string returns every child of a given parent run?

    • params.parent_id = '<parent id>'
    • attributes.run_id = '<parent id>'
    • tags.mlflow.parentRunId = '<parent id>'
    • tags.mlflow.runName = '<parent id>'
    Show the answer

    tags.mlflow.parentRunId = '<parent id>'

    MLflow tags each child with mlflow dot parentRunId, so a filter on that tag returns the children. “params.parent_id = '<parent id>'” is a parameter that nobody logged. “attributes.run_id = '<parent id>'” would return the parent itself. And “tags.mlflow.runName = '<parent id>'” would match a run name, not the link between runs.

  3. After each epoch, the team wants the validation loss as a curve on the run page. Which call fits?

    • mlflow.log_param("val_loss", loss)
    • mlflow.log_dict({"val_loss": loss}, "loss.json")
    • mlflow.set_tag("val_loss", loss)
    • mlflow.log_metric("val_loss", loss, step=epoch)
    Show the answer

    mlflow.log_metric("val_loss", loss, step=epoch)

    Log_metric with a step adds one point per epoch, and the run page draws the series as a curve. “mlflow.log_param("val_loss", loss)” is for fixed inputs, and a parameter cannot change its value within a run. “mlflow.log_dict({"val_loss": loss}, "loss.json")” only writes a file, which is replaced at each epoch. And “mlflow.set_tag("val_loss", loss)” only adds metadata, with no history to plot.