Skip to content

Commit da5bef7

Browse files
add INTRA_CLOUD_ACCELERATION for single model file downloading (modelscope#1529)
1 parent 3fd95b1 commit da5bef7

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

modelscope/hub/file_download.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
MODELSCOPE_PARALLEL_DOWNLOAD_THRESHOLD_MB, TEMPORARY_FOLDER_NAME)
2626
from modelscope.utils.constant import (DEFAULT_DATASET_REVISION,
2727
DEFAULT_MODEL_REVISION,
28+
INTRA_CLOUD_ACCELERATION,
2829
REPO_TYPE_DATASET, REPO_TYPE_MODEL,
2930
REPO_TYPE_SUPPORT)
3031
from modelscope.utils.file_utils import (get_dataset_cache_root,
@@ -194,9 +195,22 @@ def _repo_file_download(
194195
" online, set 'local_files_only' to False.")
195196

196197
_api = HubApi()
198+
197199
headers = {
198-
'user-agent': ModelScopeConfig.get_user_agent(user_agent=user_agent, )
200+
'user-agent': ModelScopeConfig.get_user_agent(user_agent=user_agent, ),
201+
'snapshot-identifier': str(uuid.uuid4()),
199202
}
203+
204+
if INTRA_CLOUD_ACCELERATION == 'true':
205+
region_id: str = (
206+
os.getenv('INTRA_CLOUD_ACCELERATION_REGION')
207+
or _api._get_internal_acceleration_domain())
208+
if region_id:
209+
logger.info(
210+
f'Intra-cloud acceleration enabled for downloading from {repo_id}'
211+
)
212+
headers['x-aliyun-region-id'] = region_id
213+
200214
if cookies is None:
201215
cookies = ModelScopeConfig.get_cookies()
202216
repo_files = []

0 commit comments

Comments
 (0)