Skip to content

Commit bfc7132

Browse files
Add maisi bundle (#612)
Fixes # . ### Description A few sentences describing the changes proposed in this pull request. ### 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 <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent f477960 commit bfc7132

34 files changed

+7699
-200
lines changed

.github/workflows/code-format-check.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ jobs:
1717
runs-on: ubuntu-latest
1818
steps:
1919
- uses: actions/checkout@v2
20-
- name: Set up Python 3.9
20+
- name: Set up Python 3.10
2121
uses: actions/setup-python@v2
2222
with:
23-
python-version: 3.9
23+
python-version: 3.10.14
2424
- name: cache weekly timestamp
2525
id: pip-cache
2626
run: |

.github/workflows/premerge-cpu.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ jobs:
1717
runs-on: ubuntu-latest
1818
steps:
1919
- uses: actions/checkout@v2
20-
- name: Set up Python 3.9
20+
- name: Set up Python 3.10
2121
uses: actions/setup-python@v2
2222
with:
23-
python-version: 3.9
23+
python-version: 3.10.14
2424
- name: cache weekly timestamp
2525
id: pip-cache
2626
run: |

ci/bundle_custom_data.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
"pathology_nuclei_segmentation_classification",
2020
"brats_mri_generative_diffusion",
2121
"brats_mri_axial_slices_generative_diffusion",
22+
"maisi_ct_generative",
2223
]
2324

2425
# This list is used for our CI tests to determine whether a bundle contains the preferred files.
2526
# If a bundle does not have any of the preferred files, please add the bundle name into the list.
26-
exclude_verify_preferred_files_list = []
27+
exclude_verify_preferred_files_list = ["maisi_ct_generative"]
2728

2829
# This list is used for our CI tests to determine whether a bundle needs to be tested with
2930
# the `verify_export_torchscript` function in `verify_bundle.py`.
@@ -37,12 +38,13 @@
3738
"mednist_reg",
3839
"brats_mri_axial_slices_generative_diffusion",
3940
"vista3d",
41+
"maisi_ct_generative",
4042
]
4143

4244
# This dict is used for our CI tests to install required dependencies that cannot be installed by `pip install` directly.
4345
# If a bundle has this kind of dependencies, please add the bundle name (key), and the path of the install script (value)
4446
# into the dict.
45-
install_dependency_dict = {}
47+
install_dependency_dict = {"maisi_ct_generative": "ci/install_scripts/install_maisi_ct_generative_dependency.sh"}
4648

4749
# This list is used for our CI tests to determine whether a bundle supports TensorRT export. Related
4850
# test will be employed for bundles in the dict.

ci/get_bundle_requirements.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
ALLOW_MONAI_RC = os.environ.get("ALLOW_MONAI_RC", "false").lower() in ("true", "1", "t", "y", "yes")
2121

22+
SPECIAL_LIB_LIST = ["xformers"]
23+
2224

2325
def increment_version(version):
2426
"""
@@ -75,10 +77,16 @@ def get_requirements(bundle, models_path):
7577
if "numpy_version" in metadata.keys():
7678
numpy_version = metadata["numpy_version"]
7779
libs.append(f"numpy=={numpy_version}")
78-
if "optional_packages_version" in metadata.keys():
79-
optional_dict = metadata["optional_packages_version"]
80-
for name, version in optional_dict.items():
81-
libs.append(f"{name}=={version}")
80+
for package_key in ["optional_packages_version", "required_packages_version"]:
81+
if package_key in metadata.keys():
82+
optional_dict = metadata[package_key]
83+
for name, version in optional_dict.items():
84+
if name not in SPECIAL_LIB_LIST:
85+
libs.append(f"{name}=={version}")
86+
else:
87+
if "pytorch_version" in metadata.keys():
88+
# remove torch from libs
89+
libs = [lib for lib in libs if "torch" not in lib]
8290

8391
if len(libs) > 0:
8492
requirements_file_name = f"requirements_{bundle}.txt"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pip install --extra-index-url https://urm.nvidia.com/artifactory/api/pypi/sw-dlmed-pypi-local/simple xformers==0.0.26+622595c.d20240617

ci/run_premerge_cpu.sh

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ elif [[ $# -gt 1 ]]; then
3030
exit 1
3131
fi
3232

33+
# Usually, CPU test is required, but for some bundles that are too large to run in Github Actions, we can exclude them.
34+
exclude_test_list=("maisi_ct_generative")
35+
is_excluded() {
36+
for item in "${exclude_list[@]}"; do
37+
if [ "$1" == "$item" ]; then
38+
return 0 # Return true (0) if excluded
39+
fi
40+
done
41+
return 1 # Return false (1) if not excluded
42+
}
43+
3344
verify_bundle() {
3445
for dir in /opt/hostedtoolcache/*; do
3546
if [[ $dir != "/opt/hostedtoolcache/Python" ]]; then
@@ -52,21 +63,25 @@ verify_bundle() {
5263
echo $bundle_list
5364
for bundle in $bundle_list;
5465
do
55-
pip install -r requirements-dev.txt
56-
# get required libraries according to the bundle's metadata file
57-
requirements=$(python $(pwd)/ci/get_bundle_requirements.py --b "$bundle")
58-
# check if ALLOW_MONAI_RC is set to 1, if so, append --pre to the pip install command
59-
if [ $ALLOW_MONAI_RC = true ]; then
60-
include_pre_release="--pre"
66+
if is_excluded "$bundle"; then
67+
echo "skip '$bundle' cpu premerge tests."
6168
else
62-
include_pre_release=""
63-
fi
64-
if [ ! -z "$requirements" ]; then
65-
echo "install required libraries for bundle: $bundle"
66-
pip install $include_pre_release -r "$requirements"
69+
pip install -r requirements-dev.txt
70+
# get required libraries according to the bundle's metadata file
71+
requirements=$(python $(pwd)/ci/get_bundle_requirements.py --b "$bundle")
72+
# check if ALLOW_MONAI_RC is set to 1, if so, append --pre to the pip install command
73+
if [ $ALLOW_MONAI_RC = true ]; then
74+
include_pre_release="--pre"
75+
else
76+
include_pre_release=""
77+
fi
78+
if [ ! -z "$requirements" ]; then
79+
echo "install required libraries for bundle: $bundle"
80+
pip install $include_pre_release -r "$requirements"
81+
fi
82+
# verify bundle
83+
python $(pwd)/ci/verify_bundle.py -b "$bundle" -m "min" # min tests on cpu
6784
fi
68-
# verify bundle
69-
python $(pwd)/ci/verify_bundle.py -b "$bundle" -m "min" # min tests on cpu
7085
done
7186
else
7287
echo "this pull request does not change any bundles, skip verify."
@@ -81,6 +96,7 @@ case $BUILD_TYPE in
8196

8297
all)
8398
echo "Run all tests..."
99+
verify_bundle
84100
;;
85101
changed)
86102
echo "Run changed tests..."

ci/run_premerge_gpu.sh

Lines changed: 86 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -16,95 +16,122 @@
1616
#
1717

1818
# Argument(s):
19-
# BUILD_TYPE: all/specific_test_name, tests to execute
19+
# $1 - Dist flag (True/False)
20+
21+
dist_flag=$1
2022

2123
set -ex
22-
BUILD_TYPE=all
23-
export ALLOW_MONAI_RC=true
2424

25-
if [[ $# -eq 1 ]]; then
26-
BUILD_TYPE=$1
25+
export ALLOW_MONAI_RC=true
2726

28-
elif [[ $# -gt 1 ]]; then
27+
if [[ $# -gt 1 ]]; then
2928
echo "ERROR: too many parameters are provided"
3029
exit 1
3130
fi
3231

33-
init_pipenv() {
34-
echo "initializing pip environment: $1"
35-
pipenv install update pip wheel
36-
pipenv install --python=3.9 -r $1
37-
export PYTHONPATH=$PWD
32+
init_venv() {
33+
if [ ! -d "model_zoo_venv" ]; then # Check if the venv directory does not exist
34+
echo "initializing pip environment: $1"
35+
python -m venv model_zoo_venv
36+
source model_zoo_venv/bin/activate
37+
pip install --upgrade pip wheel
38+
pip install -r $1
39+
export PYTHONPATH=$PWD
40+
else
41+
echo "Virtual environment model_zoo_venv already exists. Activating..."
42+
source model_zoo_venv/bin/activate
43+
fi
44+
}
45+
46+
remove_venv() {
47+
if [ -d "model_zoo_venv" ]; then # Check if the venv directory exists
48+
echo "Removing virtual environment..."
49+
deactivate 2>/dev/null || true # Deactivate venv, ignore errors if not activated
50+
rm -rf model_zoo_venv # Remove the venv directory
51+
else
52+
echo "Virtual environment not found. Skipping removal."
53+
fi
3854
}
3955

40-
remove_pipenv() {
41-
echo "removing pip environment"
42-
pipenv --rm
43-
rm Pipfile Pipfile.lock
56+
set_local_env() {
57+
echo "set local pip environment: $1"
58+
pip install --upgrade pip wheel
59+
pip install -r $1
60+
export PYTHONPATH=$PWD
4461
}
4562

4663
verify_bundle() {
4764
echo 'Run verify bundle...'
48-
init_pipenv requirements-dev.txt
4965
head_ref=$(git rev-parse HEAD)
5066
git fetch origin dev $head_ref
5167
# achieve all changed files in 'models'
5268
changes=$(git diff --name-only $head_ref origin/dev -- models)
5369
if [ ! -z "$changes" ]
5470
then
5571
# get all changed bundles
56-
bundle_list=$(pipenv run python $(pwd)/ci/get_changed_bundle.py --f "$changes")
72+
bundle_list=$(python $(pwd)/ci/get_changed_bundle.py --f "$changes")
5773
if [ ! -z "$bundle_list" ]
5874
then
59-
pipenv run python $(pwd)/ci/prepare_schema.py --l "$bundle_list"
60-
for bundle in $bundle_list;
61-
do
62-
init_pipenv requirements-dev.txt
63-
# get required libraries according to the bundle's metadata file
64-
requirements=$(pipenv run python $(pwd)/ci/get_bundle_requirements.py --b "$bundle")
65-
# check if ALLOW_MONAI_RC is set to 1, if so, append --pre to the pip install command
66-
if [ $ALLOW_MONAI_RC = true ]; then
67-
include_pre_release="--pre"
75+
python $(pwd)/ci/prepare_schema.py --l "$bundle_list"
76+
for bundle in $bundle_list;
77+
do
78+
# Check if the bundle is "maisi_ct_generative", if so, set local environment (venv cannot work with xformers)
79+
if [ "$bundle" == "maisi_ct_generative" ]; then
80+
echo "Special handling for maisi_ct_generative bundle"
81+
set_local_env requirements-dev.txt
82+
else
83+
init_venv requirements-dev.txt
84+
fi
85+
# get required libraries according to the bundle's metadata file
86+
requirements=$(python $(pwd)/ci/get_bundle_requirements.py --b "$bundle")
87+
# check if ALLOW_MONAI_RC is set to 1, if so, append --pre to the pip install command
88+
if [ $ALLOW_MONAI_RC = true ]; then
89+
include_pre_release="--pre"
90+
else
91+
include_pre_release=""
92+
fi
93+
if [ ! -z "$requirements" ]; then
94+
echo "install required libraries for bundle: $bundle"
95+
pip install $include_pre_release -r "$requirements"
96+
fi
97+
# get extra install script if exists
98+
extra_script=$(python $(pwd)/ci/get_bundle_requirements.py --b "$bundle" --get_script True)
99+
if [ ! -z "$extra_script" ]; then
100+
echo "install extra libraries with script: $extra_script"
101+
bash $extra_script
102+
fi
103+
# verify bundle
104+
python $(pwd)/ci/verify_bundle.py --b "$bundle"
105+
# unzip data and do unit tests
106+
DATA_DIR="$(pwd)/models/maisi_ct_generative/datasets"
107+
ZIP_FILE="$DATA_DIR/all_masks_flexible_size_and_spacing_3000.zip"
108+
UNZIP_DIR="$DATA_DIR/all_masks_flexible_size_and_spacing_3000"
109+
if [ -f "$ZIP_FILE" ]; then
110+
if [ ! -d "$UNZIP_DIR" ]; then
111+
echo "Unzipping files for MAISI Bundle..."
112+
unzip $ZIP_FILE -d $DATA_DIR
113+
echo "Unzipping complete."
68114
else
69-
include_pre_release=""
70-
fi
71-
if [ ! -z "$requirements" ]; then
72-
echo "install required libraries for bundle: $bundle"
73-
pipenv install $include_pre_release -r "$requirements"
115+
echo "Unzipped content already exists, continuing..."
74116
fi
75-
# get extra install script if exists
76-
extra_script=$(pipenv run python $(pwd)/ci/get_bundle_requirements.py --b "$bundle" --get_script True)
77-
if [ ! -z "$extra_script" ]; then
78-
echo "install extra libraries with script: $extra_script"
79-
bash $extra_script
80-
fi
81-
# verify bundle
82-
pipenv run python $(pwd)/ci/verify_bundle.py --b "$bundle"
83-
# do unit tests
84-
pipenv run python $(pwd)/ci/unit_tests/runner.py --b "$bundle"
85-
remove_pipenv
86-
done
117+
fi
118+
test_cmd="python $(pwd)/ci/unit_tests/runner.py --b \"$bundle\""
119+
if [ "$dist_flag" = "True" ]; then
120+
test_cmd="$test_cmd --dist True"
121+
fi
122+
eval $test_cmd
123+
# if not maisi_ct_generative, remove venv
124+
if [ "$bundle" != "maisi_ct_generative" ]; then
125+
remove_venv
126+
fi
127+
done
87128
else
88129
echo "this pull request does not change any bundles, skip verify."
89130
fi
90131
else
91132
echo "this pull request does not change any files in 'models', skip verify."
92-
remove_pipenv
133+
remove_venv
93134
fi
94135
}
95136

96-
case $BUILD_TYPE in
97-
98-
all)
99-
echo "Run all tests..."
100-
verify_bundle
101-
;;
102-
103-
verify_bundle)
104-
verify_bundle
105-
;;
106-
107-
*)
108-
echo "ERROR: unknown parameter: $BUILD_TYPE"
109-
;;
110-
esac
137+
verify_bundle

0 commit comments

Comments
 (0)