The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.
Make default hash lib configurable without code changes via CLI argument (#3947)
Thomas Wardc5a48b15bdda
diff --git a/comfy/cli_args.py b/comfy/cli_args.pyindex 6251e3d28..2397de3d6 100644--- a/comfy/cli_args.py+++ b/comfy/cli_args.py@@ -112,6 +112,7 @@ vram_group.add_argument("--lowvram", action="store_true", help="Split the unet ivram_group.add_argument("--novram", action="store_true", help="When lowvram isn't enough.")vram_group.add_argument("--cpu", action="store_true", help="To use the CPU for everything (slow).")+parser.add_argument("--default-hashing-function", type=str, choices=['md5', 'sha1', 'sha256', 'sha512'], default='sha256', help="Allows you to choose the hash function to use for duplicate filename / contents comparison. Default is sha256.")parser.add_argument("--disable-smart-memory", action="store_true", help="Force ComfyUI to agressively offload to regular ram instead of keeping models in vram when it can.")parser.add_argument("--deterministic", action="store_true", help="Make pytorch use slower deterministic algorithms when it can. Note that this might not make images deterministic in all cases.")diff --git a/node_helpers.py b/node_helpers.pyindex 43b9e829f..fee628790 100644--- a/node_helpers.py+++ b/node_helpers.py@@ -1,3 +1,7 @@+import hashlib++from comfy.cli_args import args+from PIL import ImageFile, UnidentifiedImageErrordef conditioning_set_values(conditioning, values={}):@@ -22,3 +26,12 @@ def pillow(fn, arg):if prev_value is not None:ImageFile.LOAD_TRUNCATED_IMAGES = prev_valuereturn x++def hasher():+ hashfuncs = {+ "md5": hashlib.md5,+ "sha1": hashlib.sha1,+ "sha256": hashlib.sha256,+ "sha512": hashlib.sha512+ }+ return hashfuncs[args.default_hashing_function]diff --git a/server.py b/server.pyindex 03c4c4219..23ca2fd33 100644--- a/server.py+++ b/server.py@@ -25,6 +25,7 @@ import mimetypesfrom comfy.cli_args import argsimport comfy.utilsimport comfy.model_management+import node_helpersfrom app.frontend_management import FrontendManagerfrom app.user_manager import UserManager@@ -161,10 +162,12 @@ class PromptServer():return type_dir, dir_typedef compare_image_hash(filepath, image):+ hasher = node_helpers.hasher()+# function to compare hashes of two images to see if it already exists, fix to #3465if os.path.exists(filepath):- a = hashlib.sha256()- b = hashlib.sha256()+ a = hasher()+ b = hasher()with open(filepath, "rb") as f:a.update(f.read())b.update(image.file.read())