Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7601 fix mlflow artifacts #7604

Merged
merged 9 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions monai/bundle/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"experiment_name": "monai_experiment",
"run_name": None,
# may fill it at runtime
"execute_config": None,
"save_execute_config": True,
Nic-Ma marked this conversation as resolved.
Show resolved Hide resolved
"is_not_rank0": (
"$torch.distributed.is_available() \
and torch.distributed.is_initialized() and torch.distributed.get_rank() > 0"
Expand All @@ -125,7 +125,7 @@
"tracking_uri": "@tracking_uri",
"experiment_name": "@experiment_name",
"run_name": "@run_name",
"artifacts": "@execute_config",
"artifacts": "@save_execute_config",
"iteration_log": True,
"epoch_log": True,
"tag_name": "train_loss",
Expand All @@ -148,7 +148,7 @@
"tracking_uri": "@tracking_uri",
"experiment_name": "@experiment_name",
"run_name": "@run_name",
"artifacts": "@execute_config",
"artifacts": "@save_execute_config",
"iteration_log": False,
"close_on_complete": True,
},
Expand Down
26 changes: 16 additions & 10 deletions monai/bundle/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,13 +506,19 @@ def patch_bundle_tracking(parser: ConfigParser, settings: dict) -> None:
parser[k] = v
# save the executed config into file
default_name = f"config_{time.strftime('%Y%m%d_%H%M%S')}.json"
filepath = parser.get("execute_config", None)
if filepath is None:
if "output_dir" not in parser:
# if no "output_dir" in the bundle config, default to "<bundle root>/eval"
parser["output_dir"] = f"{EXPR_KEY}{ID_REF_KEY}bundle_root + '/eval'"
# experiment management tools can refer to this config item to track the config info
parser["execute_config"] = parser["output_dir"] + f" + '/{default_name}'"
filepath = os.path.join(parser.get_parsed_content("output_dir"), default_name)
Path(filepath).parent.mkdir(parents=True, exist_ok=True)
parser.export_config_file(parser.get(), filepath)
# Users can set the `save_execute_config` to `False`, `/path/to/artifacts` or `True`.
Nic-Ma marked this conversation as resolved.
Show resolved Hide resolved
# If set to False, nothing will be recorded. If set to True, the default path will be logged.
# If set to a file path, the given path will be logged.
filepath = parser.get("save_execute_config", True)
if filepath:
if isinstance(filepath, bool):
if "output_dir" not in parser:
# if no "output_dir" in the bundle config, default to "<bundle root>/eval"
parser["output_dir"] = f"{EXPR_KEY}{ID_REF_KEY}bundle_root + '/eval'"
# experiment management tools can refer to this config item to track the config info
parser["save_execute_config"] = parser["output_dir"] + f" + '/{default_name}'"
filepath = os.path.join(parser.get_parsed_content("output_dir"), default_name)
Path(filepath).parent.mkdir(parents=True, exist_ok=True)
parser.export_config_file(parser.get(), filepath)
else:
parser["save_execute_config"] = None
6 changes: 3 additions & 3 deletions tests/test_fl_monai_algo.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
tracking={
"handlers_id": DEFAULT_HANDLERS_ID,
"configs": {
"execute_config": f"{_data_dir}/config_executed.json",
"save_execute_config": f"{_data_dir}/config_executed.json",
"trainer": {
"_target_": "MLFlowHandler",
"tracking_uri": path_to_uri(_data_dir) + "/mlflow_override",
Expand Down Expand Up @@ -201,7 +201,7 @@ def test_train(self, input_params):
algo.finalize()

# test experiment management
if "execute_config" in algo.train_workflow.parser:
if "save_execute_config" in algo.train_workflow.parser:
self.assertTrue(os.path.exists(f"{_data_dir}/mlflow_override"))
shutil.rmtree(f"{_data_dir}/mlflow_override")
self.assertTrue(os.path.exists(f"{_data_dir}/config_executed.json"))
Expand All @@ -224,7 +224,7 @@ def test_evaluate(self, input_params):
algo.evaluate(data=data, extra={})

# test experiment management
if "execute_config" in algo.eval_workflow.parser:
if "save_execute_config" in algo.eval_workflow.parser:
self.assertGreater(len(list(glob.glob(f"{_data_dir}/mlflow_*"))), 0)
for f in list(glob.glob(f"{_data_dir}/mlflow_*")):
shutil.rmtree(f)
Expand Down
Loading