optional hash

This commit is contained in:
Yingda Chen
2024-12-04 18:27:42 +08:00
parent 0411beeb05
commit 58437a10da
2 changed files with 10 additions and 1 deletions

View File

@@ -29,6 +29,7 @@ API_RESPONSE_FIELD_MESSAGE = 'Message'
MODELSCOPE_CLOUD_ENVIRONMENT = 'MODELSCOPE_ENVIRONMENT'
MODELSCOPE_CLOUD_USERNAME = 'MODELSCOPE_USERNAME'
MODELSCOPE_SDK_DEBUG = 'MODELSCOPE_SDK_DEBUG'
MODELSCOPE_ENABLE_DEFAULT_HASH_VALIDATION = 'MODELSCOPE_ENABLE_DEFAULT_HASH_VALIDATION'
ONE_YEAR_SECONDS = 24 * 365 * 60 * 60
MODELSCOPE_REQUEST_ID = 'X-Request-ID'
TEMPORARY_FOLDER_NAME = '._____temp'

View File

@@ -12,6 +12,10 @@ from modelscope.hub.utils.utils import compute_hash
from modelscope.utils.logger import get_logger
logger = get_logger()
enable_default_hash_validation = \
os.getenv(MODELSCOPE_ENABLE_DEFAULT_HASH_VALIDATION, 'False').strip().lower() == 'true'
"""Implements caching functionality, used internally only
"""
@@ -274,7 +278,11 @@ class ModelFileSystemCache(FileSystemCache):
expected_hash = model_file_info[FILE_HASH]
if expected_hash is not None and os.path.exists(
cache_file_path):
cache_file_sha256 = compute_hash(cache_file_path)
# compute hash only when enabled, otherwise just meet expectation by default
if enable_default_hash_validation:
cache_file_sha256 = compute_hash(cache_file_path)
else:
cache_file_sha256 = expected_hash
if expected_hash == cache_file_sha256:
is_exists = True
break