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 4, 2023
1 parent 2dfc03c commit a7c90d0
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 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 All @@ -14,6 +14,8 @@

# Automatically pull model with corresponding hash from Civitai
def add_resource_hashes(params):
import lora

if 'parameters' not in params.pnginfo: return

hashify_resources = shared.opts.data.get('civitai_hashify_resources', True)
Expand Down Expand Up @@ -62,6 +64,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 a7c90d0

Please sign in to comment.