Works great after corrected the lora keys for ComfyUI

#7
by pmulefan - opened

In order for this LoRA to work in ComfyUI, you need to prefix "diffusion_model." to all the lora keys names.

Using the suggested prompt, and a strength of 1.4 gives a very good result, much better than the Qwen GS repair lora, it preserves the source image details much better.

This prompt really does something "The camera has moved by: {"x":0,"y":0,"z":0,"pitch":0,"yaw":0,"roll":0}",it is like a trigger, without it, the generation will conform to the reference perspective image.

pmulefan changed discussion title from Works great after corrected the lora key for ComfyUI to Works great after corrected the lora keys for ComfyUI

what do you mean by you need to prefix "diffusion_model." to all the lora keys names ? Is it something to do outside Comfy ? or is it something to do within prompt ? could you elaborate ? thank you !

I got this in the console of Comfy : lora key not loaded: double_blocks.0.img_attn.proj.lora_A.weight
lora key not loaded: double_blocks.0.img_attn.proj.lora_B.weight
lora key not loaded: double_blocks.0.img_attn.qkv.lora_A.weight
lora key not loaded: double_blocks.0.img_attn.qkv.lora_B.weight
lora key not loaded: double_blocks.0.img_mlp.0.lora_A.weight
lora key not loaded: double_blocks.0.img_mlp.0.lora_B.weight
lora key not loaded: double_blocks.0.img_mlp.2.lora_A.weight
lora key not loaded: double_blocks.0.img_mlp.2.lora_B.weight is it what you are referring to ?

Python code to fix that :

import torch
from safetensors.torch import load_file, save_file

--- CONFIGURATION ---

input_file = "input_path/lora.safetensors" # Change this to your filename
output_file = "output_path/fixed_lora.safetensors"

---------------------

def fix_keys():
print(f"Loading {input_file}...")
try:
state_dict = load_file(input_file)
except Exception as e:
print(f"Error loading file: {e}")
return

new_dict = {}
for key, value in state_dict.items():
    # Only add prefix if it's not already there
    if not key.startswith("diffusion_model."):
        new_key = f"diffusion_model.{key}"
    else:
        new_key = key
    new_dict[new_key] = value

print(f"Saving fixed LoRA to {output_file}...")
save_file(new_dict, output_file)
print("Done! Move the fixed file to your ComfyUI loras folder.")

if name == "main":
fix_keys()

This LORA doesn't work. Or give me a working diagram for Comfyui

Sign up or log in to comment