Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion scripts/gen_hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os

import civitai.lib as civitai
from modules import script_callbacks, sd_vae, shared
from modules import script_callbacks, sd_vae, shared, hashes

additional_network_type_map = {
'lora': 'LORA',
Expand Down Expand Up @@ -62,6 +62,30 @@ def add_resource_hashes(params):
short_hash = matching_resource[0]['hash'][:10]
resource_hashes[f'{network_type}:{network_name}'] = short_hash

# check loaded_loras
loaded = []
try:
import lora
loaded = lora.loaded_lora
except Exception:
pass
for item in loaded:
name = item.name
if f'lora:{name}' in resource_hashes.keys():
continue

lora_on_disk = item.lora_on_disk if hasattr(item, "lora_on_disk") else item.network_on_disk if hasattr(item, "network_on_disk") else None
if lora_on_disk is None:
continue

hash = hashes.sha256(lora_on_disk.filename, "lora/" + lora_on_disk.name)
if not hash:
continue
short_hash = hash[0:10]

name = name.replace(":", "").replace(",", "")
resource_hashes[f'lora:{name}'] = short_hash

# Check for model hash in generation parameters
model_match = re.search(model_hash_pattern, generation_params)
if hashify_resources and model_match:
Expand Down