Skip to content

Commit df1ba5d

Browse files
authored
Fix bundle download error from ngc source (#8307)
Fixes #8306 This previous api has been deprecated, update based on: https://docs.ngc.nvidia.com/api/?urls.primaryName=Private%20Artifacts%20(Models)%20API#/artifact-file-controller/downloadAllArtifactFiles ### 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: YunLiu <[email protected]>
1 parent e39bad9 commit df1ba5d

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

monai/bundle/scripts.py

+20-5
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def _get_git_release_url(repo_owner: str, repo_name: str, tag_name: str, filenam
174174

175175

176176
def _get_ngc_bundle_url(model_name: str, version: str) -> str:
177-
return f"{NGC_BASE_URL}/{model_name.lower()}/versions/{version}/zip"
177+
return f"{NGC_BASE_URL}/{model_name.lower()}/versions/{version}/files"
178178

179179

180180
def _get_ngc_private_base_url(repo: str) -> str:
@@ -218,6 +218,21 @@ def _remove_ngc_prefix(name: str, prefix: str = "monai_") -> str:
218218
return name
219219

220220

221+
def _get_all_download_files(request_url: str, headers: dict | None = None) -> list[str]:
222+
if not has_requests:
223+
raise ValueError("requests package is required, please install it.")
224+
headers = {} if headers is None else headers
225+
response = requests_get(request_url, headers=headers)
226+
response.raise_for_status()
227+
model_info = json.loads(response.text)
228+
229+
if not isinstance(model_info, dict) or "modelFiles" not in model_info:
230+
raise ValueError("The data is not a dictionary or it does not have the key 'modelFiles'.")
231+
232+
model_files = model_info["modelFiles"]
233+
return [f["path"] for f in model_files]
234+
235+
221236
def _download_from_ngc(
222237
download_path: Path,
223238
filename: str,
@@ -229,12 +244,12 @@ def _download_from_ngc(
229244
# ensure prefix is contained
230245
filename = _add_ngc_prefix(filename, prefix=prefix)
231246
url = _get_ngc_bundle_url(model_name=filename, version=version)
232-
filepath = download_path / f"{filename}_v{version}.zip"
233247
if remove_prefix:
234248
filename = _remove_ngc_prefix(filename, prefix=remove_prefix)
235-
extract_path = download_path / f"{filename}"
236-
download_url(url=url, filepath=filepath, hash_val=None, progress=progress)
237-
extractall(filepath=filepath, output_dir=extract_path, has_base=True)
249+
filepath = download_path / filename
250+
filepath.mkdir(parents=True, exist_ok=True)
251+
for file in _get_all_download_files(url):
252+
download_url(url=f"{url}/{file}", filepath=f"{filepath}/{file}", hash_val=None, progress=progress)
238253

239254

240255
def _download_from_ngc_private(

0 commit comments

Comments
 (0)