Skip to content

Commit

Permalink
use lora.loaded_loras if available
Browse files Browse the repository at this point in the history
  • Loading branch information
wkpark committed Jul 3, 2023
1 parent 2dfc03c commit d15c129
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion scripts/gen_hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import os

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

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

# check loaded_loras
for item in lora.loaded_loras:
name = item.name
if f'lora:{name}' in resource_hashes.keys():
continue

lora_on_disk = item.lora_on_disk if item.lora_on_disk is not None else None
if not lora_on_disk:
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

0 comments on commit d15c129

Please sign in to comment.