mirror of
https://github.com/modelscope/modelscope.git
synced 2025-12-16 16:27:45 +01:00
fix download retry bug, add get_cache_dir to hut/util
This commit is contained in:
@@ -224,10 +224,10 @@ def download_part_with_retry(params):
|
||||
with open(part_file_name, 'rb') as f:
|
||||
partial_length = f.seek(0, io.SEEK_END)
|
||||
progress.update(partial_length)
|
||||
start = start + partial_length
|
||||
if start > end:
|
||||
download_start = start + partial_length
|
||||
if download_start > end:
|
||||
break # this part is download completed.
|
||||
get_headers['Range'] = 'bytes=%s-%s' % (start, end)
|
||||
get_headers['Range'] = 'bytes=%s-%s' % (download_start, end)
|
||||
with open(part_file_name, 'ab+') as f:
|
||||
r = requests.get(
|
||||
url,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import hashlib
|
||||
import os
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
import requests
|
||||
@@ -28,6 +29,21 @@ def model_id_to_group_owner_name(model_id):
|
||||
return group_or_owner, name
|
||||
|
||||
|
||||
def get_cache_dir(model_id: Optional[str] = None):
|
||||
"""cache dir precedence:
|
||||
function parameter > environment > ~/.cache/modelscope/hub
|
||||
Args:
|
||||
model_id (str, optional): The model id.
|
||||
Returns:
|
||||
str: the model_id dir if model_id not None, otherwise cache root dir.
|
||||
"""
|
||||
default_cache_dir = Path.home().joinpath('.cache', 'modelscope')
|
||||
base_path = os.getenv('MODELSCOPE_CACHE',
|
||||
os.path.join(default_cache_dir, 'hub'))
|
||||
return base_path if model_id is None else os.path.join(
|
||||
base_path, model_id + '/')
|
||||
|
||||
|
||||
def get_release_datetime():
|
||||
if MODELSCOPE_SDK_DEBUG in os.environ:
|
||||
rt = int(round(datetime.now().timestamp()))
|
||||
|
||||
Reference in New Issue
Block a user