From 08ffcd56a3b25b6e22e4e66e18c95adc70179b82 Mon Sep 17 00:00:00 2001 From: Yiheng Wang <68361391+yiheng-wang-nv@users.noreply.github.com> Date: Thu, 25 Jan 2024 13:28:57 +0800 Subject: [PATCH] Fix weekly cpu test error and add hash check [skip-gpu] (#549) Fixes #548 . ### Description A few sentences describing the changes proposed in this pull request. ### Status **Ready** ### Please ensure all the checkboxes: - [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 --- ci/download_latest_bundle.py | 12 ++++++++++-- ci/get_bundle_list.py | 5 ++++- ci/utils.py | 5 +++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/ci/download_latest_bundle.py b/ci/download_latest_bundle.py index ca5c3f7e..14ea3581 100644 --- a/ci/download_latest_bundle.py +++ b/ci/download_latest_bundle.py @@ -14,15 +14,23 @@ import os from monai.bundle import download -from utils import get_latest_version +from utils import get_checksum, get_hash_func, get_latest_version, get_version_checksum def download_latest_bundle(bundle_name: str, models_path: str, download_path: str): model_info_path = os.path.join(models_path, "model_info.json") version = get_latest_version(bundle_name=bundle_name, model_info_path=model_info_path) - + checksum = get_version_checksum(bundle_name=bundle_name, version=version, model_info_path=model_info_path) download(name=bundle_name, source="monaihosting", version=version, bundle_dir=download_path) + # verify checksum + hash_func = get_hash_func(hash_type="sha1") + bundle_zip_name = f"{bundle_name}_v{version}.zip" + downloaded_checksum = get_checksum(dst_path=os.path.join(download_path, bundle_zip_name), hash_func=hash_func) + if checksum != downloaded_checksum: + raise ValueError(f"Checksum of {bundle_zip_name} is not correct.") + print(f"Checksum of downloaded bundle {bundle_name} is correct.") + if __name__ == "__main__": parser = argparse.ArgumentParser(description="") diff --git a/ci/get_bundle_list.py b/ci/get_bundle_list.py index e49481b7..3e6d5393 100644 --- a/ci/get_bundle_list.py +++ b/ci/get_bundle_list.py @@ -14,10 +14,13 @@ from utils import get_sub_folders +# new added bundles should temporarily be added to this list, and remove until they can be downloaded successfully +EXCLUDE_LIST = ["segmentation_template", "classification_template"] + def main(models_path): bundle_list = get_sub_folders(root_dir=models_path) - + bundle_list = [b for b in bundle_list if b not in EXCLUDE_LIST] print(bundle_list) diff --git a/ci/utils.py b/ci/utils.py index 70432a34..dd35171c 100644 --- a/ci/utils.py +++ b/ci/utils.py @@ -123,6 +123,11 @@ def get_latest_version(bundle_name: str, model_info_path: str): return sorted(versions)[-1] +def get_version_checksum(bundle_name: str, version: str, model_info_path: str): + model_info_dict = get_json_dict(model_info_path) + return model_info_dict[f"{bundle_name}_v{version}"]["checksum"] + + def submit_pull_request(model_info_path: str): # set required info for a pull request branch_name = "auto-update-model-info"