aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorAUTOMATIC <16777216c@gmail.com>2023-05-19 19:59:29 +0000
committerAUTOMATIC <16777216c@gmail.com>2023-05-19 19:59:29 +0000
commit39ec4f06ffb2c26e1298b2c5d80874dc3fd693ac (patch)
tree7edd9b81f43b07826844e951241a4b4a15620257 /modules
parent87702febe08bddb9e8b952204c459927532ec6e6 (diff)
downloadstable-diffusion-webui-gfx803-39ec4f06ffb2c26e1298b2c5d80874dc3fd693ac.tar.gz
stable-diffusion-webui-gfx803-39ec4f06ffb2c26e1298b2c5d80874dc3fd693ac.tar.bz2
stable-diffusion-webui-gfx803-39ec4f06ffb2c26e1298b2c5d80874dc3fd693ac.zip
calculate hashes for Lora
add lora hashes to infotext when pasting infotext, use infotext's lora hashes to find local loras for <lora:xxx:1> entries whose hashes match loras the user has
Diffstat (limited to 'modules')
-rw-r--r--modules/extra_networks.py9
-rw-r--r--modules/hashes.py29
2 files changed, 32 insertions, 6 deletions
diff --git a/modules/extra_networks.py b/modules/extra_networks.py
index f9db41bc..54982009 100644
--- a/modules/extra_networks.py
+++ b/modules/extra_networks.py
@@ -17,6 +17,15 @@ def register_extra_network(extra_network):
class ExtraNetworkParams:
def __init__(self, items=None):
self.items = items or []
+ self.positional = []
+ self.named = {}
+
+ for item in self.items:
+ parts = item.split('=', 2)
+ if len(parts) == 2:
+ self.named[parts[0]] = parts[1]
+ else:
+ self.positional.append(item)
class ExtraNetwork:
diff --git a/modules/hashes.py b/modules/hashes.py
index 032120f4..8b7ea0ac 100644
--- a/modules/hashes.py
+++ b/modules/hashes.py
@@ -46,8 +46,8 @@ def calculate_sha256(filename):
return hash_sha256.hexdigest()
-def sha256_from_cache(filename, title):
- hashes = cache("hashes")
+def sha256_from_cache(filename, title, use_addnet_hash=False):
+ hashes = cache("hashes-addnet") if use_addnet_hash else cache("hashes")
ondisk_mtime = os.path.getmtime(filename)
if title not in hashes:
@@ -62,10 +62,10 @@ def sha256_from_cache(filename, title):
return cached_sha256
-def sha256(filename, title):
- hashes = cache("hashes")
+def sha256(filename, title, use_addnet_hash=False):
+ hashes = cache("hashes-addnet") if use_addnet_hash else cache("hashes")
- sha256_value = sha256_from_cache(filename, title)
+ sha256_value = sha256_from_cache(filename, title, use_addnet_hash)
if sha256_value is not None:
return sha256_value
@@ -73,7 +73,11 @@ def sha256(filename, title):
return None
print(f"Calculating sha256 for {filename}: ", end='')
- sha256_value = calculate_sha256(filename)
+ if use_addnet_hash:
+ with open(filename, "rb") as file:
+ sha256_value = addnet_hash_safetensors(file)
+ else:
+ sha256_value = calculate_sha256(filename)
print(f"{sha256_value}")
hashes[title] = {
@@ -86,6 +90,19 @@ def sha256(filename, title):
return sha256_value
+def addnet_hash_safetensors(b):
+ """kohya-ss hash for safetensors from https://github.com/kohya-ss/sd-scripts/blob/main/library/train_util.py"""
+ hash_sha256 = hashlib.sha256()
+ blksize = 1024 * 1024
+ b.seek(0)
+ header = b.read(8)
+ n = int.from_bytes(header, "little")
+ offset = n + 8
+ b.seek(offset)
+ for chunk in iter(lambda: b.read(blksize), b""):
+ hash_sha256.update(chunk)
+
+ return hash_sha256.hexdigest()