lora tags
This commit is contained in:
@@ -24,6 +24,11 @@ Merge two checkpoint models by dare ties (https://github.com/yule-BUAA/MergeLM).
|
||||
|mask|Mask Operations|`MODEL_MASK`, `MODEL_MASK`|`MODEL_MASK`|Allows set operations to be performed on masks|
|
||||
|mask|Mask Edit|`MODEL_MASK`|`MODEL_MASK`|Allows the direct editing of mask layers|
|
||||
|
||||
## LoRA
|
||||
|category|node name|input type|output type|desc.|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|lora|LoRA Loader (Tags)|`MODEL`, `CLIP`|`MODEL`, `CLIP`, `STRING`|Loads a LoRA model, returning the tags from the metadata|
|
||||
|
||||
## Utilities
|
||||
|category|node name|input type|output type|desc.|
|
||||
| --- | --- | --- | --- | --- |
|
||||
|
||||
@@ -5,6 +5,7 @@ from .components.block import BlockUnetMerger
|
||||
from .components.normalize import NormalizeUnet
|
||||
from .components.mask_model import MagnitudeMasker, MaskOperations, MaskEdit, SimpleMasker, QuadMasker
|
||||
from .components.reports import MaskReporting, ModelReporting, LoRAReporting
|
||||
from .components.lora import LoraLoaderTags
|
||||
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
@@ -21,6 +22,8 @@ NODE_CLASS_MAPPINGS = {
|
||||
"DM_MaskReporting": MaskReporting,
|
||||
"DM_LoRAReporting": LoRAReporting,
|
||||
"DM_NormalizeModel": NormalizeUnet,
|
||||
"DM_LoRALoaderTags": LoraLoaderTags,
|
||||
|
||||
}
|
||||
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
@@ -37,6 +40,7 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"DM_MaskReporting": "Mask Reporting",
|
||||
"DM_LoRAReporting": "LoRA Reporting",
|
||||
"DM_NormalizeModel": "Normalize Model",
|
||||
"DM_LoRALoaderTags": "LoRA Loader (Tags)",
|
||||
}
|
||||
|
||||
__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS']
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
# components/lora.py
|
||||
import folder_paths
|
||||
from comfy.sd import load_lora_for_models
|
||||
from comfy.sd import CLIP
|
||||
from comfy.model_patcher import ModelPatcher
|
||||
|
||||
from ..ddare.lora import DoctorLora
|
||||
from ..ddare.const import LORA_CATEGORY
|
||||
|
||||
class LoraLoaderTags:
|
||||
def __init__(self):
|
||||
self.loaded_lora = None
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": { "model": ("MODEL",),
|
||||
"clip": ("CLIP", ),
|
||||
"lora_name": (folder_paths.get_filename_list("loras"), ),
|
||||
"strength_model": ("FLOAT", {"default": 1.0, "min": -20.0, "max": 20.0, "step": 0.01}),
|
||||
"strength_clip": ("FLOAT", {"default": 1.0, "min": -20.0, "max": 20.0, "step": 0.01}),
|
||||
"tag_limit": ("INT", {"default": 10, "min": 1, "max": 100}),
|
||||
}}
|
||||
RETURN_TYPES = ("MODEL", "CLIP", "STRING")
|
||||
FUNCTION = "load_lora"
|
||||
|
||||
CATEGORY = LORA_CATEGORY
|
||||
|
||||
def load_lora(self, model : ModelPatcher, clip : CLIP, lora_name : str, strength_model : float, strength_clip : float, tag_limit : int = 10, **kwargs):
|
||||
tags = ""
|
||||
if strength_model == 0 and strength_clip == 0:
|
||||
return (model, clip, tags)
|
||||
|
||||
lora_path = folder_paths.get_full_path("loras", lora_name)
|
||||
lora = None
|
||||
if self.loaded_lora is not None:
|
||||
if self.loaded_lora[0] == lora_path:
|
||||
lora = self.loaded_lora[1]
|
||||
else:
|
||||
temp = self.loaded_lora
|
||||
self.loaded_lora = None
|
||||
del temp
|
||||
|
||||
if lora is None:
|
||||
drlora = DoctorLora.load(lora_path)
|
||||
|
||||
tags = drlora.tags
|
||||
if tags is not None:
|
||||
tags = ", ".join(tags[:tag_limit])
|
||||
|
||||
lora = drlora.lora
|
||||
|
||||
model_lora, clip_lora = load_lora_for_models(model, clip, lora, strength_model, strength_clip)
|
||||
return (model_lora, clip_lora, tags)
|
||||
|
||||
Reference in New Issue
Block a user