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

Define initialize, run, finalize sections in bundle config #294

Closed
Nic-Ma opened this issue Jan 6, 2023 · 4 comments
Closed

Define initialize, run, finalize sections in bundle config #294

Nic-Ma opened this issue Jan 6, 2023 · 4 comments
Assignees

Comments

@Nic-Ma
Copy link
Collaborator

Nic-Ma commented Jan 6, 2023

Is your feature request related to a problem? Please describe.
Currently, to support code execution in order, we defined expressions in a list of bundle config, like:
https://github.com/Project-MONAI/model-zoo/blob/dev/models/spleen_ct_segmentation/configs/multi_gpu_train.json#L27
But when loading the bundle in other applications, like MONAI Label, MONAI FL, we want to get the trainer or other components and hard to execute all the expressions in the list immediately, so we re-define much logic in the python parser, like:
https://github.com/Project-MONAI/MONAI/blob/dev/monai/fl/client/monai_algo.py#L460

To easily connect with other apps, I think we should clearly define the expressions in initialize, run, finalize sections, then others can call the operations separately. For example:

{
    "initialize": [
        "$import torch.distributed as dist",
        "$dist.is_initialized() or dist.init_process_group(backend='nccl')",
        "$torch.cuda.set_device(@device)",
        "$monai.utils.set_determinism(seed=123)",
        "$setattr(torch.backends.cudnn, 'benchmark', True)",
        "$import logging",
        "$@train#trainer.logger.setLevel(logging.WARNING if dist.get_rank() > 0 else logging.INFO)",
        "$@validate#evaluator.logger.setLevel(logging.WARNING if dist.get_rank() > 0 else logging.INFO)"
    ],
    "run": [
        "$@train#trainer.run()"
    ],
    "finalize": [
        "$dist.destroy_process_group()"
    ]
}

Will also create another ticket to define a high level API Bundle to simplify the bundle loading in other apps.

@Nic-Ma
Copy link
Collaborator Author

Nic-Ma commented Jan 6, 2023

CC @wyli @SachidanandAlle @holgerroth for more discussion.

Thanks.

Nic-Ma added a commit to Project-MONAI/MONAI that referenced this issue Mar 15, 2023
Fixes #5821 .

### Description

The main idea of this PR is to solve 3 pain points of the current bundle
training or inference workflow:
1. Training or inference is defined in a "rigid" `training` or
`evaluation` list, so 3rd party package can't flexibly initialize and
run the workflows separately, see:
Project-MONAI/model-zoo#294. This PR splits it
into `initialize`, `run` and `finalize`, and still compatible with
current existing bundles.
2. 3rd party packages need to access the bundle config directly with
specifed keys based on `ConfigParser`, but some developers of bundles
don't want to write JSON or YAML configs. This PR implemented the
interface to support both config-based and python-based workflows.
3. MONAI Label, MONAI deploy, MONAI-FL require many fixed properties of
a training or inference workflow, but we don't have definition for them
in the code, just described in the developer guide doc of model-zoo.
This PR implemented the `TrainProperties` and `inferenceProperties`
interfaces and check tool.

### 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).
- [ ] 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: Nic Ma <nma@nvidia.com>
Signed-off-by: root <root@apt-sh-ai.nvidia.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: root <root@apt-sh-ai.nvidia.com>
@Nic-Ma
Copy link
Collaborator Author

Nic-Ma commented Mar 21, 2023

Hi @yiheng-wang-nv ,

As PR Project-MONAI/MONAI#5822 had been merged into MONAI 1.2rc1, could you please help update existing bundles to this initialize, run, finalize sections and update the MONAI dependency version to 1.2?
Let's merge it to dev-1.2 branch according to the plan.

Thanks in advance.

@yiheng-wang-nv
Copy link
Collaborator

Update: I'm now working on this ticket. According to the latest discussion with @Nic-Ma , we will use dev branch only.
As for the bundles, I will update spleen_ct_segmentation first, and submit a separate PR for others.

yiheng-wang-nv added a commit that referenced this issue Mar 24, 2023
part of #294 

### Description
This PR modifies `spleen_ct_segmentation` with new interface. All
scripts and commands in the readme are checked locally.

### Status
**Ready**

### Please ensure all the checkboxes:
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Codeformat tests passed locally by running `./runtests.sh
--codeformat`.
- [x] In-line docstrings updated.
- [x] Update `version` and `changelog` in `metadata.json` if changing an
existing bundle.
- [x] Please ensure the naming rules in config files meet our
requirements (please refer to: `CONTRIBUTING.md`).
- [x] Ensure versions of packages such as `monai`, `pytorch` and `numpy`
are correct in `metadata.json`.
- [x] Descriptions should be consistent with the content, such as
`eval_metrics` of the provided weights and TorchScript modules.
- [x] Files larger than 25MB are excluded and replaced by providing
download links in `large_file.yml`.
- [x] Avoid using path that contains personal information within config
files (such as use `/home/your_name/` for `"bundle_root"`).
yiheng-wang-nv added a commit that referenced this issue Mar 24, 2023
part of #294 .

### Description
This PR is used to fix the typo comes from #331 .

### Status
**Ready**

### Please ensure all the checkboxes:
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Codeformat tests passed locally by running `./runtests.sh
--codeformat`.
- [ ] In-line docstrings updated.
- [ ] Update `version` and `changelog` in `metadata.json` if changing an
existing bundle.
- [ ] Please ensure the naming rules in config files meet our
requirements (please refer to: `CONTRIBUTING.md`).
- [ ] Ensure versions of packages such as `monai`, `pytorch` and `numpy`
are correct in `metadata.json`.
- [ ] Descriptions should be consistent with the content, such as
`eval_metrics` of the provided weights and TorchScript modules.
- [ ] Files larger than 25MB are excluded and replaced by providing
download links in `large_file.yml`.
- [ ] Avoid using path that contains personal information within config
files (such as use `/home/your_name/` for `"bundle_root"`).
yiheng-wang-nv added a commit that referenced this issue Apr 4, 2023
Part of #294 .

### Description
This PR updates several bundles with `BundleWorkflow ` interface, and
also fix a few errors. Commands in all bundles are tested with
`monai==1.2.0rc3` locally with the changes except the following two:
~~1. `wholeBody_ct_segmentation`~~ (checked)
~~2. `pathology_nuclei_segmentation_classification`~~ (checked)
~~because I do not have these two datasets locally.~~

### Status
**Ready**

### Please ensure all the checkboxes:
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Codeformat tests passed locally by running `./runtests.sh
--codeformat`.
- [ ] In-line docstrings updated.
- [ ] Update `version` and `changelog` in `metadata.json` if changing an
existing bundle.
- [ ] Please ensure the naming rules in config files meet our
requirements (please refer to: `CONTRIBUTING.md`).
- [ ] Ensure versions of packages such as `monai`, `pytorch` and `numpy`
are correct in `metadata.json`.
- [ ] Descriptions should be consistent with the content, such as
`eval_metrics` of the provided weights and TorchScript modules.
- [ ] Files larger than 25MB are excluded and replaced by providing
download links in `large_file.yml`.
- [ ] Avoid using path that contains personal information within config
files (such as use `/home/your_name/` for `"bundle_root"`).

---------

Signed-off-by: Yiheng Wang <vennw@nvidia.com>
Signed-off-by: tangy5 <yucheng.tang@vanderbilt.edu>
Co-authored-by: tangy5 <yucheng.tang@vanderbilt.edu>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@yiheng-wang-nv
Copy link
Collaborator

This ticket is resolved

yiheng-wang-nv added a commit to yiheng-wang-nv/model-zoo that referenced this issue Jul 29, 2024
part of Project-MONAI#294 

### Description
This PR modifies `spleen_ct_segmentation` with new interface. All
scripts and commands in the readme are checked locally.

### Status
**Ready**

### Please ensure all the checkboxes:
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Codeformat tests passed locally by running `./runtests.sh
--codeformat`.
- [x] In-line docstrings updated.
- [x] Update `version` and `changelog` in `metadata.json` if changing an
existing bundle.
- [x] Please ensure the naming rules in config files meet our
requirements (please refer to: `CONTRIBUTING.md`).
- [x] Ensure versions of packages such as `monai`, `pytorch` and `numpy`
are correct in `metadata.json`.
- [x] Descriptions should be consistent with the content, such as
`eval_metrics` of the provided weights and TorchScript modules.
- [x] Files larger than 25MB are excluded and replaced by providing
download links in `large_file.yml`.
- [x] Avoid using path that contains personal information within config
files (such as use `/home/your_name/` for `"bundle_root"`).
yiheng-wang-nv added a commit to yiheng-wang-nv/model-zoo that referenced this issue Jul 29, 2024
…MONAI#335)

part of Project-MONAI#294 .

### Description
This PR is used to fix the typo comes from Project-MONAI#331 .

### Status
**Ready**

### Please ensure all the checkboxes:
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Codeformat tests passed locally by running `./runtests.sh
--codeformat`.
- [ ] In-line docstrings updated.
- [ ] Update `version` and `changelog` in `metadata.json` if changing an
existing bundle.
- [ ] Please ensure the naming rules in config files meet our
requirements (please refer to: `CONTRIBUTING.md`).
- [ ] Ensure versions of packages such as `monai`, `pytorch` and `numpy`
are correct in `metadata.json`.
- [ ] Descriptions should be consistent with the content, such as
`eval_metrics` of the provided weights and TorchScript modules.
- [ ] Files larger than 25MB are excluded and replaced by providing
download links in `large_file.yml`.
- [ ] Avoid using path that contains personal information within config
files (such as use `/home/your_name/` for `"bundle_root"`).
yiheng-wang-nv added a commit to yiheng-wang-nv/model-zoo that referenced this issue Jul 29, 2024
Part of Project-MONAI#294 .

### Description
This PR updates several bundles with `BundleWorkflow ` interface, and
also fix a few errors. Commands in all bundles are tested with
`monai==1.2.0rc3` locally with the changes except the following two:
~~1. `wholeBody_ct_segmentation`~~ (checked)
~~2. `pathology_nuclei_segmentation_classification`~~ (checked)
~~because I do not have these two datasets locally.~~

### Status
**Ready**

### Please ensure all the checkboxes:
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Codeformat tests passed locally by running `./runtests.sh
--codeformat`.
- [ ] In-line docstrings updated.
- [ ] Update `version` and `changelog` in `metadata.json` if changing an
existing bundle.
- [ ] Please ensure the naming rules in config files meet our
requirements (please refer to: `CONTRIBUTING.md`).
- [ ] Ensure versions of packages such as `monai`, `pytorch` and `numpy`
are correct in `metadata.json`.
- [ ] Descriptions should be consistent with the content, such as
`eval_metrics` of the provided weights and TorchScript modules.
- [ ] Files larger than 25MB are excluded and replaced by providing
download links in `large_file.yml`.
- [ ] Avoid using path that contains personal information within config
files (such as use `/home/your_name/` for `"bundle_root"`).

---------

Signed-off-by: Yiheng Wang <vennw@nvidia.com>
Signed-off-by: tangy5 <yucheng.tang@vanderbilt.edu>
Co-authored-by: tangy5 <yucheng.tang@vanderbilt.edu>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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

No branches or pull requests

2 participants