Vorrei implementare e adattare il "CODICE 2" al "CODICE 1". [CODICE 2] ''' Get Content…
- User
Vorrei implementare e adattare il "CODICE 2" al "CODICE 1".
[CODICE 2] '''
Get Content B-LoRA SD
#content_B_LoRA_sd, _ = pipeline.lora_state_dict(args.content_B_LoRA) #content_B_LoRA = filter_lora(content_B_LoRA_sd, BLOCKS['content']) #content_B_LoRA = scale_lora(content_B_LoRA, args.content_alpha)
content_B_LoRA = {}
Get Style B-LoRA SD
style_B_LoRA_sd, _ = pipeline.lora_state_dict('/kaggle/working/Output/pytorch_lora_weights.safetensors') style_B_LoRA = filter_lora(style_B_LoRA_sd, BLOCKS['style']) style_B_LoRA = scale_lora(style_B_LoRA, 1.0)
#style_B_LoRA = {}
Merge B-LoRAs SD
res_lora = {**content_B_LoRA, **style_B_LoRA}
Load
pipeline.load_lora_into_unet(res_lora, None, pipeline.unet) '''
[CODICE 1] ''' class LoraLoader: 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}), }} RETURN_TYPES = ("MODEL", "CLIP") FUNCTION = "load_lora" CATEGORY = "loaders" def load_lora(self, model, clip, lora_name, strength_model, strength_clip): if strength_model == 0 and strength_clip == 0: return (model, clip) 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: lora = comfy.utils.load_torch_file(lora_path, safe_load=True) self.loaded_lora = (lora_path, lora) model_lora, clip_lora = comfy.sd.load_lora_for_models(model, clip, lora, strength_model, strength_clip) return (model_lora, clip_lora)'''
- Assistant