diff --git a/docs/en/release_note.md b/docs/en/release_note.md index 92acefbd666987eca771ff1444350a80c0c0d415..60035888cd01d763194a6c47e7954d1eb4d6e96c 100644 --- a/docs/en/release_note.md +++ b/docs/en/release_note.md @@ -6,20 +6,10 @@ #### New Functions -- The **snapshot_download** and **om_hub_download** APIs are supported by the Gitee AI community. -- The **upload_folder**, **upload_file**, **om_hub_download**, **snapshot_download**, **create_repo**, and **create_branch** APIs are supported by the HuggingFace community. -- The **get_model_ci_info** API is added to query information about the model usability test. -- The log module is optimized and timestamps are added. - #### Document Updates -Documents related to new functions are added. - ### Resolved Issues -- The license check is performed after the file upload is complete, which affects user experience. -- The info method of the OmFileSystem class responds slowly. - ### Known Issues None diff --git a/docs/zh/release_note.md b/docs/zh/release_note.md index fe36a01db346f9482a20dc121dcc03a6132f3e37..3dd2e2f72c1379f07d2972d7f89c390da0401ddf 100644 --- a/docs/zh/release_note.md +++ b/docs/zh/release_note.md @@ -6,20 +6,10 @@ #### 新增功能 -- snapshot_download、om_hub_download下载相关接口支持Gitee AI社区。 -- upload_folder、upload_file、om_hub_download、snapshot_download、create_repo、create_branch接口支持huggingface社区。 -- 新增get_model_ci_info接口,用于查询模型可用性测试相关信息。 -- 日志模块优化以及新增时间戳。 - #### 文档更新 -补充新增功能相关文档。 - ### 已修复问题 -- 上传文件时,license检查位于上传完成之后,影响体验的问题。 -- OmFileSystem类info方法响应慢问题。 - ### 已知问题 无 diff --git a/src/openmind_hub/plugins/openmind/_snapshot_download.py b/src/openmind_hub/plugins/openmind/_snapshot_download.py index 850aa28ce2a1814fdc03f0bef3014e1910c55745..1a8c7f5d46fe8d4a3bac126bb628d57e734a6273 100644 --- a/src/openmind_hub/plugins/openmind/_snapshot_download.py +++ b/src/openmind_hub/plugins/openmind/_snapshot_download.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. import os +import time +import random from pathlib import Path from typing import Dict, List, Literal, Optional, TypeVar, Union @@ -223,21 +225,33 @@ def snapshot_download( ref_path.write_text(commit_hash) def _inner_om_hub_download(repo_file: str): - return om_hub_download( - repo_id, - filename=repo_file, - repo_type=repo_type, - revision=revision, - endpoint=endpoint, - cache_dir=cache_dir, - local_dir=local_dir, - local_dir_use_symlinks=local_dir_use_symlinks, - user_agent=user_agent, - proxies=proxies, - resume_download=resume_download, - force_download=force_download, - token=token, - ) + retry_attempts = 0 + max_retries = 10 # 定义最大重试次数 + + while retry_attempts < max_retries: + try: + return om_hub_download( + repo_id, + filename=repo_file, + repo_type=repo_type, + revision=revision, + endpoint=endpoint, + cache_dir=cache_dir, + local_dir=local_dir, + local_dir_use_symlinks=local_dir_use_symlinks, + user_agent=user_agent, + proxies=proxies, + resume_download=resume_download, + force_download=force_download, + token=token, + ) + except Exception as e: # 捕获所有异常 + retry_attempts += 1 + if retry_attempts >= max_retries: + raise RuntimeError(f"Download failed after {max_retries} attempts") from e + + backoff_time = min(10, (2**retry_attempts) + random.uniform(0, 1)) + time.sleep(backoff_time) thread_map( _inner_om_hub_download,