- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 02:53 PM
How do I get MLflow child runs to appear as children of their parent run in the MLflow GUI, if I'm choosing my own experiment location instead of letting everything be written to the default experiment location?
If I run the standard tutorial (https://docs.databricks.com/_extras/notebooks/source/mlflow/mlflow-end-to-end-example-uc.html) of running parameter tuning on an XGBoost model, with logging to MLflow, the individual runs are grouped together nicely in the MLflow UI under the default experiment location:
But there's trouble with the nesting if I take control of the name and location of the MLflow experiment. Say I set up an experiment location as follows:
EXPERIMENT_NAME = '/Users/dxxxx@realchemistry.com/MLflow_experiments/dxxxx_minimal_MLflow'
# Get the experiment ID if it exists, or create a new one
experiment_id = mlflow.get_experiment_by_name(EXPERIMENT_NAME)
if experiment_id is None:
# If the experiment does not exist, create it
experiment_id = mlflow.create_experiment(EXPERIMENT_NAME)
else:
# If the experiment exists, get its ID
experiment_id = experiment_id.experiment_id
If do a single model training run, using
with mlflow.start_run(experiment_id=experiment_id, run_name='untuned_random_forest'):
the model is archived with run name untuned_random_forest to a new experiment page dxxxx_minimal_MLflow exactly as I intend.
However, trouble turns up when I try a parameter optimization job with the runs to be nested. I set the experiment_id using
# Run fmin within an MLflow run context so that each hyperparameter configuration is logged as a child run of a parent
# run called "xgboost_models" .
with mlflow.start_run(experiment_id=experiment_id, run_name='xgboost_models_2') as parent_run:
run_id_value = parent_run.info.run_id
search_space['parent_run_id'] = run_id_value
best_params = fmin(
fn=train_model,
space=search_space,
algo=tpe.suggest,
max_evals=8,
trials=spark_trials,
)which invokes the defined function train_model():
def train_model(params):
mlflow.xgboost.autolog()
with mlflow.start_run(nested=True):
train = xgb.DMatrix(data=X_train, label=y_train)
validation = xgb.DMatrix(data=X_val, label=y_val)
{et cetera}the nesting (note nested=True) doesn't work, or at least doesn't appear to work. The bizarre outcome is that the my experiment page gets a new run called xgboost_models_2, but it doesn't have any children. And all the child runs are visible, but not on my experiment page -- they're only visible on the default experiment page, with no indication that they're children of anything. If you look inside the child runs, they each have a parent_run_id that seems right, but the GUI can't seem to figure out that it should group them under the parent run on my personal experiment page.
x