Skip to content

Commit

Permalink
Fix test error in tests.ngc_bundle_download (#6935)
Browse files Browse the repository at this point in the history
Fixes #6932.

### Description
Add `remove_ngc_prefix` for ngc source download

### 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: KumoLiu <[email protected]>
  • Loading branch information
KumoLiu authored Sep 4, 2023
1 parent cb4f517 commit 4ea40cf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions monai/bundle/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,10 @@ def load(
device = "cuda:0" if is_available() else "cpu"
if model_file is None:
model_file = os.path.join("models", "model.ts" if load_ts_module is True else "model.pt")
if source == "ngc":
name = _add_ngc_prefix(name)
if remove_prefix:
name = _remove_ngc_prefix(name, prefix=remove_prefix)
full_path = os.path.join(bundle_dir_, name, model_file)
if not os.path.exists(full_path) or model is None:
download(
Expand Down
8 changes: 6 additions & 2 deletions tests/ngc_bundle_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,15 @@ def test_ngc_download_bundle(self, bundle_name, version, remove_prefix, download
self.assertTrue(os.path.exists(full_file_path))
self.assertTrue(check_hash(filepath=full_file_path, val=hash_val))

weights = load(
model = load(
name=bundle_name, source="ngc", version=version, bundle_dir=tempdir, remove_prefix=remove_prefix
)
assert_allclose(
weights[TESTCASE_WEIGHTS["key"]], TESTCASE_WEIGHTS["value"], atol=1e-4, rtol=1e-4, type_test=False
model.state_dict()[TESTCASE_WEIGHTS["key"]],
TESTCASE_WEIGHTS["value"],
atol=1e-4,
rtol=1e-4,
type_test=False,
)


Expand Down

0 comments on commit 4ea40cf

Please sign in to comment.