From c9d0c46412a619f365af2705c70c1cfd7e1b3f12 Mon Sep 17 00:00:00 2001 From: "Xingjun.Wang" Date: Thu, 19 Jun 2025 10:36:44 +0800 Subject: [PATCH 1/2] fix some bugs in HubApi (#1369) --- modelscope/hub/api.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modelscope/hub/api.py b/modelscope/hub/api.py index 8c3570c5..a903c648 100644 --- a/modelscope/hub/api.py +++ b/modelscope/hub/api.py @@ -32,6 +32,7 @@ from modelscope.hub.constants import (API_HTTP_CLIENT_MAX_RETRIES, API_RESPONSE_FIELD_DATA, API_RESPONSE_FIELD_EMAIL, API_RESPONSE_FIELD_GIT_ACCESS_TOKEN, + API_RESPONSE_FIELD_MESSAGE, API_RESPONSE_FIELD_USERNAME, DEFAULT_CREDENTIALS_PATH, DEFAULT_MAX_WORKERS, @@ -372,6 +373,7 @@ class HubApi: set in HubApi class (self.endpoint) re_raise(`bool`): raise exception when error + token (`str`, *optional*): access token to use for checking existence. Returns: True if the repository exists, False otherwise. """ @@ -1426,6 +1428,7 @@ class HubApi: endpoint (Optional[str]): The endpoint to use. In the format of `https://www.modelscope.cn` or 'https://www.modelscope.ai' exist_ok (Optional[bool]): If the repo exists, whether to return the repo url directly. + create_default_config (Optional[bool]): If True, create a default configuration file in the model repo. **kwargs: The additional arguments. Returns: @@ -1437,15 +1440,15 @@ class HubApi: if not endpoint: endpoint = self.endpoint - repo_exists: bool = self.repo_exists(repo_id, repo_type=repo_type, endpoint=endpoint) + self.login(access_token=token, endpoint=endpoint) + + repo_exists: bool = self.repo_exists(repo_id, repo_type=repo_type, endpoint=endpoint, token=token) if repo_exists: if exist_ok: return f'{endpoint}/{repo_type}s/{repo_id}' else: raise ValueError(f'Repo {repo_id} already exists!') - self.login(access_token=token, endpoint=endpoint) - repo_id_list = repo_id.split('/') if len(repo_id_list) != 2: raise ValueError('Invalid repo id, should be in the format of `owner_name/repo_name`') From d092a4350c7dd9e8a832598cfe6d5336f71bcd48 Mon Sep 17 00:00:00 2001 From: "Xingjun.Wang" Date: Thu, 19 Jun 2025 15:49:31 +0800 Subject: [PATCH 2/2] Set the maximum value of MODELSCOPE_DOWNLOAD_PARALLELS to 16 (#1371) --- modelscope/hub/file_download.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modelscope/hub/file_download.py b/modelscope/hub/file_download.py index 1090fceb..c323844e 100644 --- a/modelscope/hub/file_download.py +++ b/modelscope/hub/file_download.py @@ -462,7 +462,7 @@ def parallel_download(url: str, if end + 1 < file_size: tasks.append((file_path, progress, end + 1, file_size - 1, url, file_name, cookies, headers)) - parallels = MODELSCOPE_DOWNLOAD_PARALLELS if MODELSCOPE_DOWNLOAD_PARALLELS <= 4 else 4 + parallels = min(MODELSCOPE_DOWNLOAD_PARALLELS, 16) # download every part with ThreadPoolExecutor( max_workers=parallels,