What you will be able to do
- Control which tracking server and experiment an MLflow run is written to, and predict where a run goes when no experiment is set
- Log parameters, step-wise metrics, tags and artifacts from code, including to a run that has already finished
- Log computed metrics and parameters in bulk with dictionaries, and attach saved files with log_artifact
- Structure tuning trials, cross-validation folds and ensemble members as child runs under one parent with nested=True
- Query an experiment's runs as a DataFrame and filter them by metric, parameter or tag
Key concept
Parent and child runs — A run opened with mlflow.start_run(nested=True) while another run is active becomes a child of that run. It is a separate run in the same experiment with its own parameters and metrics, and it is linked back to the parent so the whole job can be read as one tree.
1.Where MLflow runs and experiments are stored
MLflow tracking organizes model development into experiments and runs. A run is one execution of model code. An experiment is a collection of related runs that you compare and filter. Every logging call you make goes to a run, the run belongs to an experiment, and the experiment lives on a tracking server. On Databricks that server is hosted for you and keeps experiment data in your workspace, with no setup.
Two settings decide where your data lands. The tracking URI picks the server and defaults to the current workspace. mlflow.set_tracking_uri("databricks://remote-workspace-url") points at a different one. The experiment picks the container on that server, and you set it with mlflow.set_experiment("/Shared/my-experiment"). A workspace experiment like that can take runs started from any notebook or from the API.
The default is the notebook experiment. It has the same name and ID as the notebook, and only runs started inside that notebook can be logged to it. That suits solo exploration. When a job, a second notebook or an API client has to write to the same place, set a workspace experiment explicitly. One side effect is worth knowing: deleting a notebook experiment through the API moves the notebook itself to Trash.
| Setting | Call | Default when unset |
|---|---|---|
| Tracking URI (which server) | mlflow.set_tracking_uri(...) | The current Databricks workspace |
| Experiment (which container) | mlflow.set_experiment("/Shared/...") | The notebook experiment |
Checkpoint 1 of 7· Fill the gap
A scheduled job and a teammate's notebook both need to log their runs to the same experiment. Which call completes this sample so that runs from either one land in that shared location?
experiment_name = "/Shared/name_of_experiment/"
mlflow. ? (experiment_name)Only runs started inside a notebook can be logged to that notebook's experiment. For a job or a second notebook to log to the same place, you set a workspace experiment with mlflow.set_experiment(). set_tracking_uri only chooses which server receives the data, not which experiment on it.
Source: docs.databricks.com2.Logging parameters, step-wise metrics, tags and artifacts
Autologging is the quickest way to start: MLflow records training code for many frameworks without any extra calls. It only knows what the framework exposes, though. To choose exactly which parameters and metrics are recorded, or to attach files such as a CSV or a plot, use the logging API. The two work together. Autologging captures the standard parameters and metrics, and explicit calls in the same run add things it can't know about, such as a business metric.
Each kind of data has its own job. Parameters and metrics are key-value pairs. A parameter describes an input, such as a learning rate. A metric records a result, and you can log it again with a step to build a curve. Tags are key-value metadata you add so you can search for runs later. Artifacts are output files, and they appear in the run's Artifacts tab.
# Log from rank 0 only; all nodes share the same MLFLOW_RUN_ID.
if os.environ.get("RANK", "0") == "0":
with mlflow.start_run(run_id=os.environ["MLFLOW_RUN_ID"]):
mlflow.log_param("learning_rate", 3e-4)
for step, loss in enumerate(training_losses):
mlflow.log_metric("train_loss", loss, step=step)Two details in that snippet matter for the exam. Passing run_id= to mlflow.start_run reopens a run that already exists instead of creating a new one. Use it when a metric computed later, perhaps in another notebook, belongs on a run whose process has already exited. Also, step=step keeps every value of train_loss as a separate point. Without steps, repeated values of one key are hard to tell apart, and run search compares runs on the last value logged.
Custom logging means the names and values come from your code, so they can be computed at any point while the run is open. A revenue-impact figure worked out after evaluation, a threshold chosen at runtime and a summary of the best Optuna trial are all logged the same way as a learning rate.
mlflow.log_metric("best_trial_logloss", study.best_trial.value)
mlflow.log_params({f"best_{key}": value for key, value in study.best_trial.params.items()})log_param and log_metric take one key and one value. log_params, log_metrics and set_tags take a dictionary, which suits values produced in a loop or a comprehension. Here the best trial's hyperparameters are logged with a best_ prefix built in code, so the winning values are easy to tell apart from the search settings on the same run.
Artifacts are files, so the file has to exist before it can be logged. mlflow.log_artifact takes a path rather than an in-memory object: save the plot, CSV or table first, then pass its path. Databricks recommends this for large objects such as big pandas tables, images, plots and models.
mlflow.log_artifact("/Volumes/<catalog>/<schema>/<volume>/myLargeFilePath.txt")Checkpoint 2 of 7· Check yourself
Your training notebook already uses MLflow autologging for a scikit-learn model. You also want a revenue-impact metric and a confusion-matrix PNG recorded on the same run. What is the right approach?
Autologging only records what the framework exposes. Explicit logging API calls in the same run add the extra items, such as a business metric or a plot logged as an artifact. Tags are searchable key-value metadata, not a way to store output files.
“or to log additional artifacts such as CSV files or plots, use the MLflow logging API.”Source: docs.databricks.com
3.Nested runs for tuning trials, folds and ensembles
Some experiments produce many related results that belong to one job: forty tuning trials, five cross-validation folds, or three base learners feeding a stacked ensemble. Putting all of them in one run collapses them, because a repeated metric key overwrites what you can compare. Starting forty unrelated top-level runs loses the fact that they belong together. Nested runs avoid both problems. A parent run holds the job, and each unit of work becomes a child run with its own metrics.
The pattern is two calls to the same function. Open the parent with with mlflow.start_run():. Inside that block, open each child with mlflow.start_run(nested=True). Optionally give it a name, for example mlflow.start_run(run_name="base_learner", nested=True). With Optuna, the child call goes inside the objective function, so each trial gets its own run. For cross-validation it goes inside the fold loop, and for an ensemble it is called once per base learner. nested is an argument to start_run, never to log_metric, because nesting is a relationship between runs, not between individual values.
Children are real, independent runs in the same experiment as their parent. A fold's AUC is logged to that fold's child and does not overwrite anything on the parent. After the loop ends and the children have closed, the parent is the active run again. That makes it the place to log the roll-up, such as mean AUC across folds. You don't need an experiment per fold or per trial. An experiment is a collection of related runs, and the parent-child link already provides the grouping.
| Approach | What you get |
|---|---|
| Parent start_run(), then start_run(nested=True) per trial/fold/learner | One parent with one linked child run per unit, each holding its own metrics |
| Reuse one run and log every trial into it | One run; per-trial values of the same key collapse into one series |
| Separate top-level runs sharing a custom tag | Independent runs you must regroup by hand with a tag search |
| One experiment per trial or fold | Results scattered across experiments, with no parent to roll them up |
Distributed work follows the same model. In Ray, the driver opens the parent run, and each remote task gets the parent's run_id plus credentials so it can open its child run from a different process. The run_id is what ties a child to its parent, even when they run on different machines.
Checkpoint 3 of 7· Check yourself
For five cross-validation folds, a teammate suggests creating a separate MLflow experiment for each fold so the per-fold AUC values don't collide. Which design keeps each fold's AUC separate and still groups the folds as one job?
An experiment is a collection of related runs, so the folds belong in one experiment. Inside it, each fold is a child run opened with start_run(nested=True), and the parent logs the roll-up. nested is an argument to start_run, not to log_metric, and reusing one run for the folds collapses the values of the repeated key.
“An experiment is a collection of related runs. In an experiment, you can compare and filter runs to understand how your model performs”Source: docs.databricks.com
Checkpoint 4 of 7· Exam question
A data science team is using Optuna to tune hyperparameters for a gradient boosting model in a Databricks notebook. They want every trial's parameters and metrics logged as a distinct MLflow run, but all trials should be grouped visually under a single parent run representing the overall tuning job. Which approach achieves this?
Correct answer: A — Wrap the tuning loop in mlflow.start_run() to open the parent run, then call mlflow.start_run(nested=True) inside the objective function so each trial becomes a child run.
- A. Passing
nested=Truewhile a parent run is active creates a true parent-child relationship, so the tracking UI andsearch_runsAPI group each trial's run beneath the tuning job's parent run automatically. - B. Reusing a single run object across every trial merges all trials' metric histories into one run, so individual trial results overwrite or blend together instead of staying separable.
- C. Creating a new experiment per trial scatters the trials across unrelated top-level containers; experiments are not nested inside each other, so this cannot reproduce a parent-child grouping.
- D. A tag on rows within one run is a manual workaround that never produces independent per-trial run objects with their own metric histories, unlike genuine nested runs.
Checkpoint 5 of 7· Exam question
A team trains three different base learners (a random forest, a gradient boosted tree, and a linear model) and then combines their predictions into a stacked ensemble. They want the MLflow experiment to show one top-level run for the ensemble and three linked runs underneath it, one per base learner. Which pattern satisfies this requirement?
Correct answer: A — Open the ensemble run with mlflow.start_run(), then inside it call mlflow.start_run(run_name="base_learner", nested=True) once per base learner to create three child runs.
- A. Calling
start_run(nested=True)while the ensemble run is active links each base learner's run to it as a child, so the tracking UI displays the three runs nested beneath the ensemble run. - B. Tagging independent top-level runs does not create an actual hierarchy; the three runs remain siblings in the run list and must be manually joined by the tag rather than shown nested.
- C. Prefixing metric names inside a single run mixes every base learner's history into one run's metric charts, which loses the ability to compare each model as its own tracked run.
- D. Registering model versions in Model Registry tracks deployment and lineage of already-trained artifacts, not the experiment-tracking run hierarchy needed while training the base learners.
4.Querying runs and filtering child runs by parent
Run data can be read as a DataFrame. mlflow.search_runs() returns a pandas DataFrame with one row per run, and the MLflow experiments data source returns the same data as a Spark DataFrame for larger analyses or dashboards.
Filters use the same syntax as the experiment page's search box. Examples are metrics.r2 > 0.3, params.elasticNetParam = 0.5, and MIN(metrics.rmse) <= 1 to match on the minimum value instead of the last one. Tags use the form tags.<key>="<value>", with the value in quotes. Each child run records its parent's ID in the mlflow.parentRunId tag. So mlflow.search_runs(filter_string="tags.mlflow.parentRunId = '<parent_run_id>'") returns only the children of one parent, for example the five folds of a single model configuration.
Both filters return the right rows. But the parent link is set automatically by nested=True, so the runs also form a tree in the UI and the parent has somewhere to hold the aggregate result. A hand-made tag depends on every script remembering to set it, and there is no parent run to hold the ensemble's own metrics.
Checkpoint 6 of 7· Check yourself
You need to analyse metrics from thousands of runs with Spark for a dashboard. Which way of reading MLflow run data gives you an Apache Spark DataFrame directly?
There are two DataFrame APIs. The Python client's search_runs returns a pandas DataFrame, and a filter_string doesn't change that. The MLflow experiments data source returns the same run data as a Spark DataFrame, which suits larger analyses and dashboards.
“The MLflow Python client search_runs API returns a pandas DataFrame. The Read MLflow experiments data source returns an Apache Spark DataFrame.”Source: docs.databricks.com
Checkpoint 7 of 7· Exam question
A team performs 5-fold cross-validation for a classifier and wants each fold's metrics logged separately while still being able to roll results up under one parent run per model configuration. Which of the following statements about implementing this with MLflow nested runs are correct?(Select 3)
Correct answers: A, B, D — Opening the parent run first and calling mlflow.start_run(nested=True) inside the fold loop creates one child run per fold, holding that fold's own metrics.; The parent run can log the averaged cross-validation metric, such as mean AUC, after the fold loop finishes, kept separate from each individual fold's metric values.; Calling mlflow.search_runs() with a filter on the mlflow.parentRunId tag returns only the fold-level child runs that belong to that specific parent run.
- A. Because the parent run is already active, wrapping each fold's training in a nested
start_runcall produces a distinct child run object per fold with its own isolated metric history. - B. Metrics logged directly to the still-active parent run, such as an aggregate mean AUC computed after the loop, live on the parent run and stay independent of any child run's own metrics.
- C. Child runs are separate run objects with their own metric storage; they do not overwrite the parent run's metrics, so this describes behavior that nested runs do not exhibit.
- D. MLflow automatically tags every nested run with its parent's run ID, so filtering
search_runson that tag is the documented way to retrieve exactly the child runs of one parent. - E. Nested runs share the same experiment as their parent by default; splitting folds across separate experiments is unnecessary and would actually break the parent-child grouping in the UI.
- F. The
nestedargument belongs tomlflow.start_run(), which is what establishes the parent-child link;log_metric()has nonestedparameter and simply logs to whichever run is currently active.
Sources
(5)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.https://docs.databricks.com/aws/en/mlflow/trackingOfficial docs
“Tracking URI: Determines which server to use (defaults to current Databricks workspace)”
↩︎ Where MLflow runs and experiments are stored“If no active experiment is set, runs are logged to the notebook experiment.”
↩︎ Where MLflow runs and experiments are stored“to log additional artifacts such as CSV files or plots, use the MLflow logging API.”
↩︎ Logging parameters, step-wise metrics, tags and artifacts“MLflow imposes a quota limit on the number of total parameters, tags, and metric steps for all existing and new runs”
↩︎ Logging parameters, step-wise metrics, tags and artifacts“An experiment is a collection of related runs.”
↩︎ Nested runs for tuning trials, folds and ensembles“The MLflow Python client search_runs API returns a pandas DataFrame.”
↩︎ Querying runs and filtering child runs by parent“Only MLflow runs initiated within a notebook can be logged to the notebook experiment.”
↩︎ Exam trap 4“or to log additional artifacts such as CSV files or plots, use the MLflow logging API.”
↩︎ Checkpoint“An experiment is a collection of related runs. In an experiment, you can compare and filter runs to understand how your model performs”
↩︎ Checkpoint“The MLflow Python client search_runs API returns a pandas DataFrame. The Read MLflow experiments data source returns an Apache Spark DataFrame.”
↩︎ Checkpoint - 2.
“If no experiment is active, Databricks creates a notebook experiment.”
↩︎ Where MLflow runs and experiments are stored - 3.https://docs.databricks.com/aws/en/mlflow/runsOfficial docs
“Tags are key-value pairs that you can create and use later to search for runs.”
↩︎ Logging parameters, step-wise metrics, tags and artifacts“You can also search for runs by tag.”
↩︎ Querying runs and filtering child runs by parent - 4.https://docs.databricks.com/aws/en/machine-learning/ai-runtime/examples/tutorials/sgc-xgboost-optuna-tuningOfficial docs
“mlflow.log_params({f"best_{key}": value for key, value in study.best_trial.params.items()})”
↩︎ Logging parameters, step-wise metrics, tags and artifacts - 5.
“Databricks recommends persisting the artifact as a file.”
↩︎ Logging parameters, step-wise metrics, tags and artifacts“This run acts as a hierarchical container for all subsequent child runs.”
↩︎ Nested runs for tuning trials, folds and ensembles“This run acts as a hierarchical container for all subsequent child runs.”
↩︎ Key concept“Each child run can independently log its own metrics.”
↩︎ Exam trap 1“This setup establishes the hierarchical parent-child relationship between runs.”
↩︎ Exam trap 2“Directly log the saved file by specifying the path”
↩︎ Exam trap 3