Skip to main content

How to Log a GridSearchCV Search in MLflow with Parent and Child Runs

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

A hyperparameter search trains the same model many times, once per combination of settings. With autologging on, MLflow records a GridSearchCV search as one tidy group: a parent run for the search as a whole, with the best settings, and a child run for each candidate, with its cross-validation scores. This guide records a four-candidate search, with real output from MLflow 3.18.0.

Syntax​

Syntax
mlflow.sklearn.autolog(log_models=False)

with mlflow.start_run(run_name="<parent name>"):
GridSearchCV(estimator, param_grid, cv=folds).fit(X, y)
PartWhat it means
mlflow.sklearn.autolog()Turns autologging on. A search's fit then logs a parent run and child runs
log_models=FalseLeaves out the saved models, so the runs only hold the search. Without it, MLflow also saves the search and its best model
with mlflow.start_run(...)The parent run, with a name you choose. Without it, MLflow starts one with a random name

Prerequisites​

Step 1: Run a Search with Autologging​

The example tries four depths for a decision tree on the iris flowers, with 5-fold cross-validation. Create grid_search_runs.py:

The grid_search_runs.py script in a macOS-style code window: it sets the tracking server and the experiment grid-search-demo, calls mlflow.sklearn.autolog with log_models False, builds a GridSearchCV over a DecisionTreeClassifier with max_depth 1 to 4 and cv 5, and fits it inside a run named tree-depths.

grid_search_runs.py
import mlflow
from sklearn.datasets import load_iris
from sklearn.model_selection import GridSearchCV
from sklearn.tree import DecisionTreeClassifier

mlflow.set_tracking_uri("http://127.0.0.1:8080")
mlflow.set_experiment("grid-search-demo")
mlflow.sklearn.autolog(log_models=False)

X, y = load_iris(return_X_y=True, as_frame=True)
search = GridSearchCV(DecisionTreeClassifier(random_state=0), {"max_depth": [1, 2, 3, 4]}, cv=5)

with mlflow.start_run(run_name="tree-depths"):
search.fit(X, y)
Terminal
uv run python grid_search_runs.py
Output
2026/11/21 11:01:39 INFO mlflow.tracking.fluent: Experiment with name 'grid-search-demo' does not exist. Creating a new experiment.
/Users/you/source/mlflow-demo/.venv/lib/python3.15/site-packages/sklearn/metrics/_classification.py:3424: FutureWarning: `y_pred` was renamed to `y_proba` in version 1.9 and will be removed in 1.11. Use `y_proba` instead.
warnings.warn(
2026/11/21 11:01:45 INFO mlflow.sklearn.utils: Logging the 4 best runs, no runs will be omitted.
🏃 View run overjoyed-deer-505 at: http://127.0.0.1:8080/#/experiments/4/runs/67e920bb4d3042e6a61535cdd7515606
🧪 View experiment at: http://127.0.0.1:8080/#/experiments/4
🏃 View run unique-cod-423 at: http://127.0.0.1:8080/#/experiments/4/runs/ab3afca17d0c44279fa47eb1bdc97762
🧪 View experiment at: http://127.0.0.1:8080/#/experiments/4
🏃 View run fun-midge-625 at: http://127.0.0.1:8080/#/experiments/4/runs/6bf838e890ab46188a17636445d8337b
🧪 View experiment at: http://127.0.0.1:8080/#/experiments/4
🏃 View run judicious-mole-206 at: http://127.0.0.1:8080/#/experiments/4/runs/37a060b59b944858b7c971fbfb578440
🧪 View experiment at: http://127.0.0.1:8080/#/experiments/4
🏃 View run tree-depths at: http://127.0.0.1:8080/#/experiments/4/runs/9c7a323812b445538166d6a517f25c01
🧪 View experiment at: http://127.0.0.1:8080/#/experiments/4

A terminal running uv run python grid_search_runs.py: the experiment is created, a FutureWarning from scikit-learn appears, MLflow says Logging the 4 best runs, no runs will be omitted, then prints links to four child runs and to the parent run tree-depths.

  • Logging the 4 best runs, no runs will be omitted.: one child run per candidate. MLflow logs the best 5 by default, so all 4 fit.
  • Five View run lines: the four children, with names MLflow picked, then the parent, tree-depths.
  • The FutureWarning comes from MLflow itself, not from this script: MLflow 3.18 computes the training log loss with the argument name y_pred, which scikit-learn 1.9 renamed to y_proba. It changes nothing in the results. I reported it to MLflow as issue #28012.

Step 2: Look at the Runs​

In the experiment's runs table, the parent has a + next to its name. Click it to show its children:

The grid-search-demo runs table with the parent tree-depths expanded: best_cv_score 0.9667 on the parent, and four child runs with their mean_test_score and max_depth: 0.9333 for depth 2, 0.96 for depth 3, 0.6667 for depth 1 and 0.9667 for depth 4.

The table shows the columns best_cv_score, mean_test_score and max_depth, chosen with its Columns button.

RunWhat autologging recorded
Parent tree-depthsThe search's own settings, such as cv and param_grid; the best candidate's settings as best_max_depth; best_cv_score; scores of the best model, refitted on all the data, on that same data, such as training_accuracy_score; the file cv_results.csv with every candidate
Each childAll the tree's settings with that candidate's max_depth; its cross-validation results mean_test_score, std_test_score and rank_test_score, and its fit and score times

Depth 4 won, with 0.9667, which is the parent's best_cv_score.

Common Mistakes​

MistakeWhat happensDo this instead
Calling fit outside start_runThe parent run gets a random nameWrap the search in mlflow.start_run(run_name=...)
Expecting every candidate as a child when the grid is largeOnly the 5 best get child runsSet max_tuning_runs: How to Log Every Candidate of a Grid Search in MLflow with max_tuning_runs
Judging the search by the parent's training_* metricsThey're scores on the data the model learned fromUse best_cv_score, and score a held-out test set

Troubleshooting​

SymptomLikely causeFix
FutureWarning: `y_pred` was renamed to `y_proba`... from _classification.pyMLflow 3.18's own call to scikit-learn's log_lossNothing to change in your code; the results are correct
Child runs show the same DurationMLflow creates them after the search, with the parent's start time: it can't know when each candidate ranExpected; read each candidate's mean_fit_time instead
No child runsAutologging wasn't on before fitCall mlflow.sklearn.autolog() first

FAQ​

Does this work with RandomizedSearchCV?​

Yes: autologging handles GridSearchCV and RandomizedSearchCV the same way.

Where are the per-fold scores?​

In the parent's cv_results.csv. Child runs keep the averages and leave the per-fold split… columns out.

How do I find the children from Python?​

Search for runs whose mlflow.parentRunId tag is the parent's ID: How to Find the Child Runs of a Parent Run in MLflow.

Conclusion​

mlflow.sklearn.autolog() turned one search.fit into a parent run, tree-depths, with the best depth and score, and four child runs, one per candidate, with their cross-validation scores. Name the parent with start_run, and raise max_tuning_runs when you want more than the best 5 candidates as children.

Additional Resources​