diff --git a/modules/async_worker.py b/modules/async_worker.py index 237d7ce6..f58ab79f 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -195,15 +195,15 @@ def worker(): # TODO move hashing to metadata mapper as this slows down the generation process base_model_path = os.path.join(modules.config.path_checkpoints, base_model_name) - base_model_hash = calculate_sha256(base_model_path)[0:10] + base_model_hash = calculate_sha256(base_model_path) refiner_model_path = os.path.join(modules.config.path_checkpoints, refiner_model_name) - refiner_model_hash = calculate_sha256(refiner_model_path)[0:10] if refiner_model_name != 'None' else '' + refiner_model_hash = calculate_sha256(refiner_model_path) if refiner_model_name != 'None' else '' lora_hashes = [] for (n, w) in loras: lora_path = os.path.join(modules.config.path_loras, n) if n != 'None' else '' - lora_hashes.append(calculate_sha256(lora_path)[0:10] if n != 'None' else '') + lora_hashes.append(calculate_sha256(lora_path) if n != 'None' else '') modules.patch.adaptive_cfg = advanced_parameters.adaptive_cfg print(f'[Parameters] Adaptive CFG = {modules.patch.adaptive_cfg}') diff --git a/modules/util.py b/modules/util.py index 21a00ef6..046ac5e7 100644 --- a/modules/util.py +++ b/modules/util.py @@ -14,7 +14,7 @@ from hashlib import sha256 import modules.sdxl_styles LANCZOS = (Image.Resampling.LANCZOS if hasattr(Image, 'Resampling') else Image.LANCZOS) - +HASH_SHA256_LENGTH = 10 def erode_or_dilate(x, k): k = int(k) @@ -182,7 +182,7 @@ def get_files_from_folder(folder_path, exensions=None, name_filter=None): return sorted(filenames, key=lambda x: -1 if os.sep in x else 1) -def calculate_sha256(filename): +def calculate_sha256(filename, length=HASH_SHA256_LENGTH): hash_sha256 = sha256() blksize = 1024 * 1024 @@ -190,7 +190,8 @@ def calculate_sha256(filename): for chunk in iter(lambda: f.read(blksize), b""): hash_sha256.update(chunk) - return hash_sha256.hexdigest() + res = hash_sha256.hexdigest() + return res[:length] if length else res def quote(text):