-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support convert LoRA safetensors into diffusers format #2403
Conversation
The documentation is not available anymore as the PR was closed or merged. |
I have run quality checker on locally, it should be fine to merge. |
@haofanwang Hi, master. If I would like to bake 2 LoRA into model, can I just run the script two times?: |
@garyhxfang Yes, I did try this using two different LoRA (as style insertion), it would work. |
@haofanwang This is awesome. This is kind of a loaded question, and not really related to the PR, but how did you "know" what to code for this PR? How can I learn more about the structure of pytorch, safetensors, and diffusers binaries and use them effectively? |
@haofanwang Hi, I try the script, and it work well currently. Thanks a lot for your great work! |
@garyhxfang I'm glad to know it is helpful to you! I have fixed this typo, thanks. @patrickvonplaten Could you take a look for this PR so that we merge it ASAP. It seems that many users are waiting for it. |
if len(state_dict[pair_keys[0]].shape) == 4: | ||
weight_up = state_dict[pair_keys[0]].squeeze(3).squeeze(2).to(torch.float32) | ||
weight_down = state_dict[pair_keys[1]].squeeze(3).squeeze(2).to(torch.float32) | ||
curr_layer.weight.data += alpha * torch.mm(weight_up, weight_down).unsqueeze(2).unsqueeze(3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't fully understand this - why do are we updating the layer weight here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see! Smart! Ok cool, let's go for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
excuse,me. when i run curr_layer.weight.data
+= alpha * torch.mm(weight_up, weight_down).unsqueeze(2).unsqueeze(3)` it shows error like "'Modulist' object has no attribute 'weight'",May I ask if you know how to solve it?
@haofanwang Hi! os.environ["CUDA_VISIBLE_DEVICES"] = "0" model_id = r".\sd_model\stable-diffusion-v1-5" # local sd model pipe = StableDiffusionPipeline.from_pretrained(model_id) lora_model_path = r'D:\sd310\lora_model\diffusers_format\one_piece_diffusers_model' pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config) pipe = pipe.to("cuda") prompt = "1boy, wanostyle, monkey d luffy, smiling" image = pipe(prompt, height=504, width=680).images[0] but there is an error: then i use this code:https://github.com/haofanwang/Lora-for-Diffusers/blob/main/format_convert.py but still not work how can i fix it? |
excuse,me. when i run |
This PR hanldes #2363 and part of #2326.
In summary, given a LoRA weight in safetensors format, we can merge it into a stable diffusion model in diffusers. It is quite easy to use as below. I have tested it with civitai models.
python convert_lora_safetensor_to_diffusers.py --base_model_path runwayml/stable-diffusion-v1-5 --checkpoint_path xxx.safetensors --dump_path ./outputs