From c316211e2d84f124f623d2170506dd5eac82f6e0 Mon Sep 17 00:00:00 2001 From: "mulin.lyh" Date: Mon, 1 Jul 2024 14:39:32 +0800 Subject: [PATCH] shorten check model timeout and snapshot_download file patter folder/ to folder/* --- modelscope/hub/api.py | 4 ++-- modelscope/hub/check_model.py | 2 +- modelscope/hub/snapshot_download.py | 8 ++++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/modelscope/hub/api.py b/modelscope/hub/api.py index fe61e31f..da4ce5d4 100644 --- a/modelscope/hub/api.py +++ b/modelscope/hub/api.py @@ -61,7 +61,7 @@ logger = get_logger() class HubApi: """Model hub api interface. """ - def __init__(self, endpoint: Optional[str] = None): + def __init__(self, endpoint: Optional[str] = None, timeout=API_HTTP_CLIENT_TIMEOUT): """The ModelScope HubApi。 Args: @@ -86,7 +86,7 @@ class HubApi: self.session, method, functools.partial( getattr(self.session, method), - timeout=API_HTTP_CLIENT_TIMEOUT)) + timeout=timeout)) def login( self, diff --git a/modelscope/hub/check_model.py b/modelscope/hub/check_model.py index ab1500db..59a77bfe 100644 --- a/modelscope/hub/check_model.py +++ b/modelscope/hub/check_model.py @@ -48,7 +48,7 @@ def check_local_model_is_latest( 'Snapshot': 'True' } } - _api = HubApi() + _api = HubApi(timeout=0.5) try: _, revisions = _api.get_model_branches_and_tags( model_id=model_id, use_cookies=cookies) diff --git a/modelscope/hub/snapshot_download.py b/modelscope/hub/snapshot_download.py index 9d8d8ac7..053b4c3b 100644 --- a/modelscope/hub/snapshot_download.py +++ b/modelscope/hub/snapshot_download.py @@ -118,10 +118,18 @@ def snapshot_download( ignore_file_pattern = [] if isinstance(ignore_file_pattern, str): ignore_file_pattern = [ignore_file_pattern] + ignore_file_pattern = [ + item if not item.endswith('/') else item + '*' + for item in ignore_file_pattern + ] if allow_file_pattern is not None: if isinstance(allow_file_pattern, str): allow_file_pattern = [allow_file_pattern] + allow_file_pattern = [ + item if not item.endswith('/') else item + '*' + for item in allow_file_pattern + ] for model_file in model_files: if model_file['Type'] == 'tree' or \