mirror of
https://github.com/finegrain-ai/refiners.git
synced 2024-11-09 23:12:02 +00:00
fix sorting method for LoRA keys
- support _out_0 - sort _in before _out - avoid false positives by only considering suffixes
This commit is contained in:
parent
ce22c8f51b
commit
83c95fcf44
|
@ -44,7 +44,7 @@ class SDLoraManager:
|
||||||
loras = {key: loras[key] for key in sorted(loras.keys(), key=SDLoraManager.sort_keys)}
|
loras = {key: loras[key] for key in sorted(loras.keys(), key=SDLoraManager.sort_keys)}
|
||||||
|
|
||||||
# if no key contains "unet" or "text", assume all keys are for the unet
|
# if no key contains "unet" or "text", assume all keys are for the unet
|
||||||
if all(["unet" not in key and "text" not in key for key in loras.keys()]):
|
if all("unet" not in key and "text" not in key for key in loras.keys()):
|
||||||
loras = {f"unet_{key}": value for key, value in loras.items()}
|
loras = {f"unet_{key}": value for key, value in loras.items()}
|
||||||
|
|
||||||
self.add_loras_to_unet(loras)
|
self.add_loras_to_unet(loras)
|
||||||
|
@ -141,15 +141,12 @@ class SDLoraManager:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def sort_keys(key: str, /) -> tuple[str, int]:
|
def sort_keys(key: str, /) -> tuple[str, int]:
|
||||||
# out0 happens sometimes as an alias for out ; this dict might not be exhaustive
|
# this dict might not be exhaustive
|
||||||
key_char_order = {"q": 1, "k": 2, "v": 3, "out": 4, "out0": 4}
|
suffix_scores = {"q": 1, "k": 2, "v": 3, "in": 3, "out": 4, "out0": 4, "out_0": 4}
|
||||||
|
patterns = ["_{}", "_{}_lora"]
|
||||||
for i, s in enumerate(key.split("_")):
|
key_char_order = {f.format(k): v for k, v in suffix_scores.items() for f in patterns}
|
||||||
if s in key_char_order:
|
(sfx, score) = next(((k, v) for k, v in key_char_order.items() if key.endswith(k)), ("", 5))
|
||||||
prefix = SDLoraManager.pad("_".join(key.split("_")[:i]))
|
return (SDLoraManager.pad(key.removesuffix(sfx)), score)
|
||||||
return (prefix, key_char_order[s])
|
|
||||||
|
|
||||||
return (SDLoraManager.pad(key), 5)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def auto_attach(
|
def auto_attach(
|
||||||
|
|
Loading…
Reference in a new issue