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

Add maisi bundle #612

Merged
merged 33 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5c7fe19
Add vista3d bundle
yiheng-wang-nv Jul 30, 2024
c4fa6dc
update properties check pipeline
yiheng-wang-nv Jul 30, 2024
4f58c20
add maisi bundle
yiheng-wang-nv Jul 30, 2024
3813190
update metadata
yiheng-wang-nv Jul 30, 2024
80802a1
remove large file
yiheng-wang-nv Jul 30, 2024
a1d8652
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 30, 2024
2ea4e02
update license check
yiheng-wang-nv Jul 31, 2024
f843807
update json file place
yiheng-wang-nv Jul 31, 2024
133b257
update license structure
yiheng-wang-nv Jul 31, 2024
6f7761d
update license file
yiheng-wang-nv Jul 31, 2024
f0d62f0
Merge branch 'add-vista3d' into add-maisi
yiheng-wang-nv Jul 31, 2024
351097e
update maisi bundle
yiheng-wang-nv Jul 31, 2024
1447688
specify format check python version
yiheng-wang-nv Aug 1, 2024
218de41
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 1, 2024
f192198
fix precommit issue
yiheng-wang-nv Aug 1, 2024
d075097
update maisi test
yiheng-wang-nv Aug 1, 2024
75b2934
remove comment code
yiheng-wang-nv Aug 1, 2024
69dd9ff
update ci scripts
yiheng-wang-nv Aug 2, 2024
4108dc9
Merge branch 'dev' into add-maisi
yiheng-wang-nv Aug 2, 2024
8741859
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 2, 2024
dd2271d
fix test error
yiheng-wang-nv Aug 2, 2024
edd1aac
update metadata
yiheng-wang-nv Aug 2, 2024
89a39a0
fix codeformat issue
yiheng-wang-nv Aug 2, 2024
61a9dcc
update base script
yiheng-wang-nv Aug 2, 2024
c38fc8b
update scripts
yiheng-wang-nv Aug 2, 2024
f74a804
avoid duplicate unzip
yiheng-wang-nv Aug 2, 2024
7d424d5
rename mgpu test
yiheng-wang-nv Aug 2, 2024
c39aeb2
update pre merge cpu
yiheng-wang-nv Aug 2, 2024
ad09448
skip maisi cpu test
yiheng-wang-nv Aug 2, 2024
d46bcb0
use 775
yiheng-wang-nv Aug 5, 2024
7bdac8f
update unzip place
yiheng-wang-nv Aug 5, 2024
f4ac996
revert vista3d test changes
yiheng-wang-nv Aug 5, 2024
e7b5806
add a list
yiheng-wang-nv Aug 5, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/code-format-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: 3.10.14
- name: cache weekly timestamp
id: pip-cache
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/premerge-cpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: 3.10.14
- name: cache weekly timestamp
id: pip-cache
run: |
Expand Down
6 changes: 4 additions & 2 deletions ci/bundle_custom_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
"pathology_nuclei_segmentation_classification",
"brats_mri_generative_diffusion",
"brats_mri_axial_slices_generative_diffusion",
"maisi_ct_generative",
]

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

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

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

# This list is used for our CI tests to determine whether a bundle supports TensorRT export. Related
# test will be employed for bundles in the dict.
Expand Down
16 changes: 12 additions & 4 deletions ci/get_bundle_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

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

SPECIAL_LIB_LIST = ["xformers"]


def increment_version(version):
"""
Expand Down Expand Up @@ -75,10 +77,16 @@ def get_requirements(bundle, models_path):
if "numpy_version" in metadata.keys():
numpy_version = metadata["numpy_version"]
libs.append(f"numpy=={numpy_version}")
if "optional_packages_version" in metadata.keys():
optional_dict = metadata["optional_packages_version"]
for name, version in optional_dict.items():
libs.append(f"{name}=={version}")
for package_key in ["optional_packages_version", "required_packages_version"]:
if package_key in metadata.keys():
optional_dict = metadata[package_key]
for name, version in optional_dict.items():
if name not in SPECIAL_LIB_LIST:
libs.append(f"{name}=={version}")
else:
if "pytorch_version" in metadata.keys():
# remove torch from libs
libs = [lib for lib in libs if "torch" not in lib]

if len(libs) > 0:
requirements_file_name = f"requirements_{bundle}.txt"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pip install --extra-index-url https://urm.nvidia.com/artifactory/api/pypi/sw-dlmed-pypi-local/simple xformers==0.0.26+622595c.d20240617
42 changes: 29 additions & 13 deletions ci/run_premerge_cpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ elif [[ $# -gt 1 ]]; then
exit 1
fi

# Usually, CPU test is required, but for some bundles that are too large to run in Github Actions, we can exclude them.
exclude_test_list=("maisi_ct_generative")
is_excluded() {
for item in "${exclude_list[@]}"; do
if [ "$1" == "$item" ]; then
return 0 # Return true (0) if excluded
fi
done
return 1 # Return false (1) if not excluded
}

verify_bundle() {
for dir in /opt/hostedtoolcache/*; do
if [[ $dir != "/opt/hostedtoolcache/Python" ]]; then
Expand All @@ -52,21 +63,25 @@ verify_bundle() {
echo $bundle_list
for bundle in $bundle_list;
do
pip install -r requirements-dev.txt
# get required libraries according to the bundle's metadata file
requirements=$(python $(pwd)/ci/get_bundle_requirements.py --b "$bundle")
# check if ALLOW_MONAI_RC is set to 1, if so, append --pre to the pip install command
if [ $ALLOW_MONAI_RC = true ]; then
include_pre_release="--pre"
if is_excluded "$bundle"; then
echo "skip '$bundle' cpu premerge tests."
else
include_pre_release=""
fi
if [ ! -z "$requirements" ]; then
echo "install required libraries for bundle: $bundle"
pip install $include_pre_release -r "$requirements"
pip install -r requirements-dev.txt
# get required libraries according to the bundle's metadata file
requirements=$(python $(pwd)/ci/get_bundle_requirements.py --b "$bundle")
# check if ALLOW_MONAI_RC is set to 1, if so, append --pre to the pip install command
if [ $ALLOW_MONAI_RC = true ]; then
include_pre_release="--pre"
else
include_pre_release=""
fi
if [ ! -z "$requirements" ]; then
echo "install required libraries for bundle: $bundle"
pip install $include_pre_release -r "$requirements"
fi
# verify bundle
python $(pwd)/ci/verify_bundle.py -b "$bundle" -m "min" # min tests on cpu
fi
# verify bundle
python $(pwd)/ci/verify_bundle.py -b "$bundle" -m "min" # min tests on cpu
done
else
echo "this pull request does not change any bundles, skip verify."
Expand All @@ -81,6 +96,7 @@ case $BUILD_TYPE in

all)
echo "Run all tests..."
verify_bundle
;;
changed)
echo "Run changed tests..."
Expand Down
145 changes: 86 additions & 59 deletions ci/run_premerge_gpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,95 +16,122 @@
#

# Argument(s):
# BUILD_TYPE: all/specific_test_name, tests to execute
# $1 - Dist flag (True/False)

dist_flag=$1

set -ex
BUILD_TYPE=all
export ALLOW_MONAI_RC=true

if [[ $# -eq 1 ]]; then
BUILD_TYPE=$1
export ALLOW_MONAI_RC=true

elif [[ $# -gt 1 ]]; then
if [[ $# -gt 1 ]]; then
echo "ERROR: too many parameters are provided"
exit 1
fi

init_pipenv() {
echo "initializing pip environment: $1"
pipenv install update pip wheel
pipenv install --python=3.9 -r $1
export PYTHONPATH=$PWD
init_venv() {
if [ ! -d "model_zoo_venv" ]; then # Check if the venv directory does not exist
echo "initializing pip environment: $1"
python -m venv model_zoo_venv
source model_zoo_venv/bin/activate
pip install --upgrade pip wheel
pip install -r $1
export PYTHONPATH=$PWD
else
echo "Virtual environment model_zoo_venv already exists. Activating..."
source model_zoo_venv/bin/activate
fi
}

remove_venv() {
if [ -d "model_zoo_venv" ]; then # Check if the venv directory exists
echo "Removing virtual environment..."
deactivate 2>/dev/null || true # Deactivate venv, ignore errors if not activated
rm -rf model_zoo_venv # Remove the venv directory
else
echo "Virtual environment not found. Skipping removal."
fi
}

remove_pipenv() {
echo "removing pip environment"
pipenv --rm
rm Pipfile Pipfile.lock
set_local_env() {
echo "set local pip environment: $1"
pip install --upgrade pip wheel
pip install -r $1
export PYTHONPATH=$PWD
}

verify_bundle() {
echo 'Run verify bundle...'
init_pipenv requirements-dev.txt
head_ref=$(git rev-parse HEAD)
git fetch origin dev $head_ref
# achieve all changed files in 'models'
changes=$(git diff --name-only $head_ref origin/dev -- models)
if [ ! -z "$changes" ]
then
# get all changed bundles
bundle_list=$(pipenv run python $(pwd)/ci/get_changed_bundle.py --f "$changes")
bundle_list=$(python $(pwd)/ci/get_changed_bundle.py --f "$changes")
if [ ! -z "$bundle_list" ]
then
pipenv run python $(pwd)/ci/prepare_schema.py --l "$bundle_list"
for bundle in $bundle_list;
do
init_pipenv requirements-dev.txt
# get required libraries according to the bundle's metadata file
requirements=$(pipenv run python $(pwd)/ci/get_bundle_requirements.py --b "$bundle")
# check if ALLOW_MONAI_RC is set to 1, if so, append --pre to the pip install command
if [ $ALLOW_MONAI_RC = true ]; then
include_pre_release="--pre"
python $(pwd)/ci/prepare_schema.py --l "$bundle_list"
for bundle in $bundle_list;
do
# Check if the bundle is "maisi_ct_generative", if so, set local environment (venv cannot work with xformers)
if [ "$bundle" == "maisi_ct_generative" ]; then
echo "Special handling for maisi_ct_generative bundle"
set_local_env requirements-dev.txt
else
init_venv requirements-dev.txt
fi
# get required libraries according to the bundle's metadata file
requirements=$(python $(pwd)/ci/get_bundle_requirements.py --b "$bundle")
# check if ALLOW_MONAI_RC is set to 1, if so, append --pre to the pip install command
if [ $ALLOW_MONAI_RC = true ]; then
include_pre_release="--pre"
else
include_pre_release=""
fi
if [ ! -z "$requirements" ]; then
echo "install required libraries for bundle: $bundle"
pip install $include_pre_release -r "$requirements"
fi
# get extra install script if exists
extra_script=$(python $(pwd)/ci/get_bundle_requirements.py --b "$bundle" --get_script True)
if [ ! -z "$extra_script" ]; then
echo "install extra libraries with script: $extra_script"
bash $extra_script
fi
# verify bundle
python $(pwd)/ci/verify_bundle.py --b "$bundle"
# unzip data and do unit tests
DATA_DIR="$(pwd)/models/maisi_ct_generative/datasets"
ZIP_FILE="$DATA_DIR/all_masks_flexible_size_and_spacing_3000.zip"
UNZIP_DIR="$DATA_DIR/all_masks_flexible_size_and_spacing_3000"
if [ -f "$ZIP_FILE" ]; then
if [ ! -d "$UNZIP_DIR" ]; then
echo "Unzipping files for MAISI Bundle..."
unzip $ZIP_FILE -d $DATA_DIR
echo "Unzipping complete."
else
include_pre_release=""
fi
if [ ! -z "$requirements" ]; then
echo "install required libraries for bundle: $bundle"
pipenv install $include_pre_release -r "$requirements"
echo "Unzipped content already exists, continuing..."
fi
# get extra install script if exists
extra_script=$(pipenv run python $(pwd)/ci/get_bundle_requirements.py --b "$bundle" --get_script True)
if [ ! -z "$extra_script" ]; then
echo "install extra libraries with script: $extra_script"
bash $extra_script
fi
# verify bundle
pipenv run python $(pwd)/ci/verify_bundle.py --b "$bundle"
# do unit tests
pipenv run python $(pwd)/ci/unit_tests/runner.py --b "$bundle"
remove_pipenv
done
fi
test_cmd="python $(pwd)/ci/unit_tests/runner.py --b \"$bundle\""
if [ "$dist_flag" = "True" ]; then
test_cmd="$test_cmd --dist True"
fi
eval $test_cmd
# if not maisi_ct_generative, remove venv
if [ "$bundle" != "maisi_ct_generative" ]; then
remove_venv
fi
done
else
echo "this pull request does not change any bundles, skip verify."
fi
else
echo "this pull request does not change any files in 'models', skip verify."
remove_pipenv
remove_venv
fi
}

case $BUILD_TYPE in

all)
echo "Run all tests..."
verify_bundle
;;

verify_bundle)
verify_bundle
;;

*)
echo "ERROR: unknown parameter: $BUILD_TYPE"
;;
esac
verify_bundle
KumoLiu marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading