From 9b3e378aa1217637c5dfc1fe65c302cf76f54e1b Mon Sep 17 00:00:00 2001 From: dongy Date: Tue, 31 Oct 2023 10:56:20 -0700 Subject: [PATCH 1/8] init Signed-off-by: dongy --- monai/apps/auto3dseg/auto_runner.py | 5 +++++ monai/apps/auto3dseg/bundle_gen.py | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/monai/apps/auto3dseg/auto_runner.py b/monai/apps/auto3dseg/auto_runner.py index 23fb3eb250..80ae34180e 100644 --- a/monai/apps/auto3dseg/auto_runner.py +++ b/monai/apps/auto3dseg/auto_runner.py @@ -83,6 +83,8 @@ class AutoRunner: zip url will be downloaded and extracted into the work_dir. allow_skip: a switch passed to BundleGen process which determines if some Algo in the default templates can be skipped based on the analysis on the dataset from Auto3DSeg DataAnalyzer. + mlflow_tracking_uri: a tracking URI for MLflow server which could be local directory or address of the remote + tracking Server; MLflow runs will be recorded locally in algorithms' model folder if the value is None. kwargs: image writing parameters for the ensemble inference. The kwargs format follows the SaveImage transform. For more information, check https://docs.monai.io/en/stable/transforms.html#saveimage. @@ -209,6 +211,7 @@ def __init__( not_use_cache: bool = False, templates_path_or_url: str | None = None, allow_skip: bool = True, + mlflow_tracking_uri: str | None = None, **kwargs: Any, ): logger.info(f"AutoRunner using work directory {work_dir}") @@ -220,6 +223,7 @@ def __init__( self.algos = algos self.templates_path_or_url = templates_path_or_url self.allow_skip = allow_skip + self.mlflow_tracking_uri = mlflow_tracking_uri self.kwargs = deepcopy(kwargs) if input is None and os.path.isfile(self.data_src_cfg_name): @@ -783,6 +787,7 @@ def run(self): templates_path_or_url=self.templates_path_or_url, data_stats_filename=self.datastats_filename, data_src_cfg_name=self.data_src_cfg_name, + mlflow_tracking_uri=self.mlflow_tracking_uri, ) if self.gpu_customization: diff --git a/monai/apps/auto3dseg/bundle_gen.py b/monai/apps/auto3dseg/bundle_gen.py index a091739dd3..c5d50fb4df 100644 --- a/monai/apps/auto3dseg/bundle_gen.py +++ b/monai/apps/auto3dseg/bundle_gen.py @@ -85,6 +85,7 @@ def __init__(self, template_path: PathLike): self.template_path = template_path self.data_stats_files = "" self.data_list_file = "" + self.mlflow_tracking_uri = None self.output_path = "" self.name = "" self.best_metric = None @@ -129,6 +130,17 @@ def set_data_source(self, data_src_cfg: str) -> None: """ self.data_list_file = data_src_cfg + def set_mlflow_tracking_uri(self, mlflow_tracking_uri: str | None = None) -> None: + """ + Set the tracking URI for MLflow server + + Args: + mlflow_tracking_uri: a tracking URI for MLflow server which could be local directory or address of + the remote tracking Server; MLflow runs will be recorded locally in algorithms' model folder if + the value is None. + """ + self.mlflow_tracking_uri = mlflow_tracking_uri + def fill_template_config(self, data_stats_filename: str, algo_path: str, **kwargs: Any) -> dict: """ The configuration files defined when constructing this Algo instance might not have a complete training @@ -432,6 +444,9 @@ class BundleGen(AlgoGen): data_stats_filename: the path to the data stats file (generated by DataAnalyzer). data_src_cfg_name: the path to the data source config YAML file. The config will be in a form of {"modality": "ct", "datalist": "path_to_json_datalist", "dataroot": "path_dir_data"}. + mlflow_tracking_uri: a tracking URI for MLflow server which could be local directory or address of + the remote tracking Server; MLflow runs will be recorded locally in algorithms' model folder if + the value is None. .. code-block:: bash python -m monai.apps.auto3dseg BundleGen generate --data_stats_filename="../algorithms/datastats.yaml" @@ -444,6 +459,7 @@ def __init__( templates_path_or_url: str | None = None, data_stats_filename: str | None = None, data_src_cfg_name: str | None = None, + mlflow_tracking_uri: str | None = None, ): if algos is None or isinstance(algos, (list, tuple, str)): if templates_path_or_url is None: @@ -496,6 +512,7 @@ def __init__( self.data_stats_filename = data_stats_filename self.data_src_cfg_name = data_src_cfg_name + self.mlflow_tracking_uri = mlflow_tracking_uri self.history: list[dict] = [] def set_data_stats(self, data_stats_filename: str) -> None: @@ -578,6 +595,7 @@ def generate( gen_algo = deepcopy(algo) gen_algo.set_data_stats(data_stats) gen_algo.set_data_source(data_src_cfg) + gen_algo.set_mlflow_tracking_uri(self.mlflow_tracking_uri) name = f"{gen_algo.name}_{f_id}" if allow_skip: From 2d09cdacd024f4e8c3f9da10fd54f0a8f0de43ac Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 31 Oct 2023 17:58:23 +0000 Subject: [PATCH 2/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- monai/apps/auto3dseg/bundle_gen.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monai/apps/auto3dseg/bundle_gen.py b/monai/apps/auto3dseg/bundle_gen.py index c5d50fb4df..c772a376c9 100644 --- a/monai/apps/auto3dseg/bundle_gen.py +++ b/monai/apps/auto3dseg/bundle_gen.py @@ -135,7 +135,7 @@ def set_mlflow_tracking_uri(self, mlflow_tracking_uri: str | None = None) -> Non Set the tracking URI for MLflow server Args: - mlflow_tracking_uri: a tracking URI for MLflow server which could be local directory or address of + mlflow_tracking_uri: a tracking URI for MLflow server which could be local directory or address of the remote tracking Server; MLflow runs will be recorded locally in algorithms' model folder if the value is None. """ @@ -444,7 +444,7 @@ class BundleGen(AlgoGen): data_stats_filename: the path to the data stats file (generated by DataAnalyzer). data_src_cfg_name: the path to the data source config YAML file. The config will be in a form of {"modality": "ct", "datalist": "path_to_json_datalist", "dataroot": "path_dir_data"}. - mlflow_tracking_uri: a tracking URI for MLflow server which could be local directory or address of + mlflow_tracking_uri: a tracking URI for MLflow server which could be local directory or address of the remote tracking Server; MLflow runs will be recorded locally in algorithms' model folder if the value is None. .. code-block:: bash From f224d1b2bfed824ff2cfa362a2efe248fc410198 Mon Sep 17 00:00:00 2001 From: dongy Date: Tue, 31 Oct 2023 11:17:45 -0700 Subject: [PATCH 3/8] update Signed-off-by: dongy --- monai/apps/auto3dseg/bundle_gen.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monai/apps/auto3dseg/bundle_gen.py b/monai/apps/auto3dseg/bundle_gen.py index c5d50fb4df..c772a376c9 100644 --- a/monai/apps/auto3dseg/bundle_gen.py +++ b/monai/apps/auto3dseg/bundle_gen.py @@ -135,7 +135,7 @@ def set_mlflow_tracking_uri(self, mlflow_tracking_uri: str | None = None) -> Non Set the tracking URI for MLflow server Args: - mlflow_tracking_uri: a tracking URI for MLflow server which could be local directory or address of + mlflow_tracking_uri: a tracking URI for MLflow server which could be local directory or address of the remote tracking Server; MLflow runs will be recorded locally in algorithms' model folder if the value is None. """ @@ -444,7 +444,7 @@ class BundleGen(AlgoGen): data_stats_filename: the path to the data stats file (generated by DataAnalyzer). data_src_cfg_name: the path to the data source config YAML file. The config will be in a form of {"modality": "ct", "datalist": "path_to_json_datalist", "dataroot": "path_dir_data"}. - mlflow_tracking_uri: a tracking URI for MLflow server which could be local directory or address of + mlflow_tracking_uri: a tracking URI for MLflow server which could be local directory or address of the remote tracking Server; MLflow runs will be recorded locally in algorithms' model folder if the value is None. .. code-block:: bash From 1acb27ecaf410459079a64c3792882ee9309a217 Mon Sep 17 00:00:00 2001 From: dongy Date: Tue, 31 Oct 2023 16:48:23 -0700 Subject: [PATCH 4/8] update Signed-off-by: dongy --- monai/apps/auto3dseg/bundle_gen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monai/apps/auto3dseg/bundle_gen.py b/monai/apps/auto3dseg/bundle_gen.py index c772a376c9..9d817db3cb 100644 --- a/monai/apps/auto3dseg/bundle_gen.py +++ b/monai/apps/auto3dseg/bundle_gen.py @@ -130,7 +130,7 @@ def set_data_source(self, data_src_cfg: str) -> None: """ self.data_list_file = data_src_cfg - def set_mlflow_tracking_uri(self, mlflow_tracking_uri: str | None = None) -> None: + def set_mlflow_tracking_uri(self, mlflow_tracking_uri: None | str = None) -> None: """ Set the tracking URI for MLflow server From 85676e52905d6977e23a5b45c6a64c263a444487 Mon Sep 17 00:00:00 2001 From: dongy Date: Tue, 31 Oct 2023 17:21:56 -0700 Subject: [PATCH 5/8] update Signed-off-by: dongy --- monai/apps/auto3dseg/bundle_gen.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/monai/apps/auto3dseg/bundle_gen.py b/monai/apps/auto3dseg/bundle_gen.py index 9d817db3cb..beead97c75 100644 --- a/monai/apps/auto3dseg/bundle_gen.py +++ b/monai/apps/auto3dseg/bundle_gen.py @@ -130,7 +130,7 @@ def set_data_source(self, data_src_cfg: str) -> None: """ self.data_list_file = data_src_cfg - def set_mlflow_tracking_uri(self, mlflow_tracking_uri: None | str = None) -> None: + def set_mlflow_tracking_uri(self, mlflow_tracking_uri: str) -> None: """ Set the tracking URI for MLflow server @@ -541,6 +541,21 @@ def get_data_src(self): """Get the data source filename""" return self.data_src_cfg_name + def set_mlflow_tracking_uri(self, mlflow_tracking_uri): + """ + Set the tracking URI for MLflow server + + Args: + mlflow_tracking_uri: a tracking URI for MLflow server which could be local directory or address of + the remote tracking Server; MLflow runs will be recorded locally in algorithms' model folder if + the value is None. + """ + self.mlflow_tracking_uri = mlflow_tracking_uri + + def get_mlflow_tracking_uri(self): + """Get the tracking URI for MLflow server""" + return self.mlflow_tracking_uri + def get_history(self) -> list: """Get the history of the bundleAlgo object with their names/identifiers""" return self.history @@ -592,10 +607,11 @@ def generate( for f_id in ensure_tuple(fold_idx): data_stats = self.get_data_stats() data_src_cfg = self.get_data_src() + mlflow_tracking_uri = self.get_mlflow_tracking_uri() gen_algo = deepcopy(algo) gen_algo.set_data_stats(data_stats) gen_algo.set_data_source(data_src_cfg) - gen_algo.set_mlflow_tracking_uri(self.mlflow_tracking_uri) + gen_algo.set_mlflow_tracking_uri(mlflow_tracking_uri) name = f"{gen_algo.name}_{f_id}" if allow_skip: From 857e56f7477c2891c131c2ed41483627d1741a17 Mon Sep 17 00:00:00 2001 From: dongy Date: Wed, 1 Nov 2023 15:26:42 -0700 Subject: [PATCH 6/8] update Signed-off-by: dongy --- monai/apps/auto3dseg/bundle_gen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monai/apps/auto3dseg/bundle_gen.py b/monai/apps/auto3dseg/bundle_gen.py index beead97c75..b47ccec852 100644 --- a/monai/apps/auto3dseg/bundle_gen.py +++ b/monai/apps/auto3dseg/bundle_gen.py @@ -130,7 +130,7 @@ def set_data_source(self, data_src_cfg: str) -> None: """ self.data_list_file = data_src_cfg - def set_mlflow_tracking_uri(self, mlflow_tracking_uri: str) -> None: + def set_mlflow_tracking_uri(self, mlflow_tracking_uri: str | None) -> None: """ Set the tracking URI for MLflow server From 8ee6069e26fd09b9982fee03f42620db4235bcc1 Mon Sep 17 00:00:00 2001 From: dongy Date: Wed, 1 Nov 2023 15:39:23 -0700 Subject: [PATCH 7/8] update Signed-off-by: dongy --- monai/apps/auto3dseg/bundle_gen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monai/apps/auto3dseg/bundle_gen.py b/monai/apps/auto3dseg/bundle_gen.py index b47ccec852..9d26e9d0fd 100644 --- a/monai/apps/auto3dseg/bundle_gen.py +++ b/monai/apps/auto3dseg/bundle_gen.py @@ -139,7 +139,7 @@ def set_mlflow_tracking_uri(self, mlflow_tracking_uri: str | None) -> None: the remote tracking Server; MLflow runs will be recorded locally in algorithms' model folder if the value is None. """ - self.mlflow_tracking_uri = mlflow_tracking_uri + self.mlflow_tracking_uri = mlflow_tracking_uri # type: ignore def fill_template_config(self, data_stats_filename: str, algo_path: str, **kwargs: Any) -> dict: """ From 0024d621d5da928409f5a7d9b5169c5a2751c930 Mon Sep 17 00:00:00 2001 From: dongy Date: Wed, 1 Nov 2023 18:29:38 -0700 Subject: [PATCH 8/8] update Signed-off-by: dongy --- monai/apps/auto3dseg/bundle_gen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monai/apps/auto3dseg/bundle_gen.py b/monai/apps/auto3dseg/bundle_gen.py index 9d26e9d0fd..03b9c8bbf4 100644 --- a/monai/apps/auto3dseg/bundle_gen.py +++ b/monai/apps/auto3dseg/bundle_gen.py @@ -139,7 +139,7 @@ def set_mlflow_tracking_uri(self, mlflow_tracking_uri: str | None) -> None: the remote tracking Server; MLflow runs will be recorded locally in algorithms' model folder if the value is None. """ - self.mlflow_tracking_uri = mlflow_tracking_uri # type: ignore + self.mlflow_tracking_uri = mlflow_tracking_uri # type: ignore def fill_template_config(self, data_stats_filename: str, algo_path: str, **kwargs: Any) -> dict: """