Skip to content

Commit d15c129

Browse files
committed
use lora.loaded_loras if available
1 parent 2dfc03c commit d15c129

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

scripts/gen_hashing.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import os
44

55
import civitai.lib as civitai
6-
from modules import script_callbacks, sd_vae, shared
6+
from modules import script_callbacks, sd_vae, shared, hashes
7+
import lora
78

89
additional_network_type_map = {
910
'lora': 'LORA',
@@ -62,6 +63,24 @@ def add_resource_hashes(params):
6263
short_hash = matching_resource[0]['hash'][:10]
6364
resource_hashes[f'{network_type}:{network_name}'] = short_hash
6465

66+
# check loaded_loras
67+
for item in lora.loaded_loras:
68+
name = item.name
69+
if f'lora:{name}' in resource_hashes.keys():
70+
continue
71+
72+
lora_on_disk = item.lora_on_disk if item.lora_on_disk is not None else None
73+
if not lora_on_disk:
74+
continue
75+
76+
hash = hashes.sha256(lora_on_disk.filename, "lora/" + lora_on_disk.name)
77+
if not hash:
78+
continue
79+
short_hash = hash[0:10]
80+
81+
name = name.replace(":", "").replace(",", "")
82+
resource_hashes[f'lora:{name}'] = short_hash
83+
6584
# Check for model hash in generation parameters
6685
model_match = re.search(model_hash_pattern, generation_params)
6786
if hashify_resources and model_match:

0 commit comments

Comments
 (0)