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

MLflow handler get wrong when running two run without name #6415

Closed
binliunls opened this issue Apr 21, 2023 · 2 comments · Fixed by #6446
Closed

MLflow handler get wrong when running two run without name #6415

binliunls opened this issue Apr 21, 2023 · 2 comments · Fixed by #6446

Comments

@binliunls
Copy link
Contributor

binliunls commented Apr 21, 2023

Describe the bug
This line in the MLFlowHandler with the or not self.run_name logic will lead to a bug. When running two bundles with run_name=None to the MLFlowHandler, the first one can be run successfully. While the 2nd one comes to this line, since it has no run name, this line will put all previous runs into a list. And the logic below will fetch the latest run and record the 2nd bundle workflow info into it, i.e. the first run.

If simply remove this or not self.run_name logic, it will cause another issue. For example, if there are two MLFlowHandlers in one workflow, like the train workflow, which has two MLFlowHandlers for trainer and validator. Since these two handlers are initialized in different time, they will have two different default run_name, which will make the train information and the validation information of the same bundle workflow into to two different runs.

To Reproduce
Steps to reproduce the behavior:

  1. Start a MONAI 1.2 docker.
  2. Download the spleen_ct_segmentation bundle, go into the root folder of the bundle and run the command below twice.
    python -m monai.bundle run --config_file configs/train.json --bundle_root ./ --train#trainer#max_epochs 10 --tracking ../tracking.json

The tracking.json file is like:

"handlers_id": {
					"trainer": {
						"id": "train#trainer",
						"handlers": "train#handlers"
					},
					"validator": {
						"id": "evaluate#evaluator",
						"handlers": "validate#handlers"
					},
					"evaluator": {
						"id": "evaluator",
						"handlers": "handlers"
					}
				},
				"configs": {
					"tracking_uri": "http://127.0.0.1:5000",
					"experiment_name": "monai_experiment_bundle",
					"run_name": null,
					"is_not_rank0": "$torch.distributed.is_available() and torch.distributed.is_initialized() and torch.distributed.get_rank() > 0",
					"trainer": {
						"_target_": "MLFlowHandler",
						"_disabled_": "@is_not_rank0",
						"tracking_uri": "@tracking_uri",
						"experiment_name": "@experiment_name",
						"run_name": "@run_name",
						"iteration_log": true,
						"output_transform": "$monai.handlers.from_engine(['loss'], first=True)",
						"close_on_complete": true
					},
					"validator": {
						"_target_": "MLFlowHandler",
						"_disabled_": "@is_not_rank0",
						"tracking_uri": "@tracking_uri",
						"experiment_name": "@experiment_name",
						"run_name": "@run_name",
						"iteration_log": false
					},
					"evaluator": {
						"_target_": "MLFlowHandler",
						"_disabled_": "@is_not_rank0",
						"tracking_uri": "@tracking_uri",
						"experiment_name": "@experiment_name",
						"run_name": "@run_name",
						"iteration_log": false,
						"close_on_complete": true
					}
				}
			}

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Environment

Ensuring you use the relevant python executable, please paste the output of:

python -c 'import monai; monai.config.print_debug_info()'

Additional context
Add any other context about the problem here.

@Nic-Ma
Copy link
Contributor

Nic-Ma commented Apr 21, 2023

Hi @binliunls ,

What do you mean "running two bundles"? You run 2 bundles in parallel with multi-thread? Or just run 2 bundles one by one? If one by one, I think we should set close_on_complete=True? Does it work?

Thanks.

@binliunls
Copy link
Contributor Author

Hi @binliunls ,

What do you mean "running two bundles"? You run 2 bundles in parallel with multi-thread? Or just run 2 bundles one by one? If one by one, I think we should set close_on_complete=True? Does it work?

Thanks.

Hi @Nic-Ma ,
I mean run two bundles one by one. And the close_on_complete was already set to true in the tracking.json file. I tried to set the close_on_complete parameter in the validator to true, and it still didn't work.

wyli pushed a commit that referenced this issue Apr 29, 2023
Fixes #6415  .

### Description

Fix the mlflow handler bug. When running a bundle with ` MLFLowHandler`
back to back without assigning the run name , the later run info will be
recorded into the former run, although the former run is finished. This
PR checks the status of runs and filters the finished ones.

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing
functionality to change).
- [x] New tests added to cover the changes.
- [ ] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [ ] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [ ] In-line docstrings updated.
- [ ] Documentation updated, tested `make html` command in the `docs/`
folder.

---------

Signed-off-by: binliu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants