Skip to content

Commit

Permalink
6962 Fix bundle download naming issue (#6969)
Browse files Browse the repository at this point in the history
Fixes #6962 .

### Description

This PR is used to fix the bundle download issue if using monaihosting
source. Detailed information is attached in #6962 .

### 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).
- [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: Yiheng Wang <[email protected]>
Signed-off-by: monai-bot <[email protected]>
Co-authored-by: monai-bot <[email protected]>
  • Loading branch information
yiheng-wang-nv and monai-bot authored Sep 11, 2023
1 parent 339292c commit 5b9d24e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion monai/bundle/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def _get_ngc_bundle_url(model_name: str, version: str) -> str:

def _get_monaihosting_bundle_url(model_name: str, version: str) -> str:
monaihosting_root_path = "https://api.ngc.nvidia.com/v2/models/nvidia/monaihosting"
return f"{monaihosting_root_path}/{model_name}/versions/{version}/files/{model_name.lower()}_v{version}.zip"
return f"{monaihosting_root_path}/{model_name.lower()}/versions/{version}/files/{model_name}_v{version}.zip"


def _download_from_github(repo: str, download_path: Path, filename: str, progress: bool = True) -> None:
Expand Down
29 changes: 21 additions & 8 deletions tests/test_bundle_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,7 @@
{"spatial_dims": 3, "out_channels": 5},
]

TEST_CASE_8 = [
"Spleen_CT_Segmentation",
"cuda" if torch.cuda.is_available() else "cpu",
{"spatial_dims": 3, "out_channels": 5},
]
TEST_CASE_8 = [["models/model.pt", "configs/train.json"], "renalStructures_CECT_segmentation", "0.1.0"]

TEST_CASE_9 = [
["network.json", "test_output.pt", "test_input.pt", "large_files.yaml"],
Expand Down Expand Up @@ -127,7 +123,7 @@ def test_url_download_bundle(self, bundle_files, bundle_name, url, hash_val):

@parameterized.expand([TEST_CASE_6])
@skip_if_quick
def test_monaihosting_download_bundle(self, bundle_files, bundle_name, url):
def test_monaihosting_url_download_bundle(self, bundle_files, bundle_name, url):
with skip_if_downloading_fails():
# download a single file from url, also use `args_file`
with tempfile.TemporaryDirectory() as tempdir:
Expand All @@ -136,7 +132,24 @@ def test_monaihosting_download_bundle(self, bundle_files, bundle_name, url):
parser = ConfigParser()
parser.export_config_file(config=def_args, filepath=def_args_file)
cmd = ["coverage", "run", "-m", "monai.bundle", "download", "--args_file", def_args_file]
cmd += ["--url", url, "--progress", "False", "--source", "monaihosting"]
cmd += ["--url", url, "--progress", "False"]
command_line_tests(cmd)
for file in bundle_files:
file_path = os.path.join(tempdir, bundle_name, file)
self.assertTrue(os.path.exists(file_path))

@parameterized.expand([TEST_CASE_8])
@skip_if_quick
def test_monaihosting_source_download_bundle(self, bundle_files, bundle_name, version):
with skip_if_downloading_fails():
# download a single file from url, also use `args_file`
with tempfile.TemporaryDirectory() as tempdir:
def_args = {"name": bundle_name, "bundle_dir": tempdir, "version": version}
def_args_file = os.path.join(tempdir, "def_args.json")
parser = ConfigParser()
parser.export_config_file(config=def_args, filepath=def_args_file)
cmd = ["coverage", "run", "-m", "monai.bundle", "download", "--args_file", def_args_file]
cmd += ["--progress", "False", "--source", "monaihosting"]
command_line_tests(cmd)
for file in bundle_files:
file_path = os.path.join(tempdir, bundle_name, file)
Expand Down Expand Up @@ -210,7 +223,7 @@ def test_load_weights(self, bundle_files, bundle_name, repo, device, model_file)
output_3 = model_3.forward(input_tensor)
assert_allclose(output_3, expected_output, atol=1e-4, rtol=1e-4, type_test=False)

@parameterized.expand([TEST_CASE_7, TEST_CASE_8])
@parameterized.expand([TEST_CASE_7])
@skip_if_quick
def test_load_weights_with_net_override(self, bundle_name, device, net_override):
with skip_if_downloading_fails():
Expand Down

0 comments on commit 5b9d24e

Please sign in to comment.