Skip to content

Commit 2d02788

Browse files
authored
[tool] fix: attach to existing MLflow run when MLFLOW_RUN_ID is set (#4740)
1 parent 854ca34 commit 2d02788

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

verl/utils/tracking.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,17 @@ def __init__(self, project_name, experiment_name, default_backend: str | list[st
8686
MLFLOW_TRACKING_URI = os.environ.get("MLFLOW_TRACKING_URI", "sqlite:////tmp/mlruns.db")
8787
mlflow.set_tracking_uri(MLFLOW_TRACKING_URI)
8888

89-
# Project_name is actually experiment_name in MLFlow
90-
# If experiment does not exist, will create a new experiment
91-
experiment = mlflow.set_experiment(project_name)
92-
mlflow.start_run(experiment_id=experiment.experiment_id, run_name=experiment_name)
89+
# Some cloud providers like Azure ML or Databricks automatically set MLFLOW_RUN_ID
90+
# If set, attach to the existing run instead of creating a new one
91+
run_id = os.environ.get("MLFLOW_RUN_ID")
92+
if run_id:
93+
mlflow.start_run(run_id=run_id)
94+
else:
95+
# Project_name is actually experiment_name in MLFlow
96+
# If experiment does not exist, will create a new experiment
97+
experiment = mlflow.set_experiment(project_name)
98+
mlflow.start_run(experiment_id=experiment.experiment_id, run_name=experiment_name)
99+
93100
mlflow.log_params(_compute_mlflow_params_from_objects(config))
94101
self.logger["mlflow"] = _MlflowLoggingAdapter()
95102

0 commit comments

Comments
 (0)