Skip to content
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

[Lora] correct lora saving & loading #2655

Merged
merged 3 commits into from
Mar 14, 2023

Conversation

patrickvonplaten
Copy link
Contributor

@patrickvonplaten patrickvonplaten commented Mar 13, 2023

Should correct: #2616

@@ -265,15 +262,6 @@ def save_function(weights, filename):
# Save the model
state_dict = model_to_save.state_dict()

# Clean the folder from a previous save
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was a bad copy-paste and is not needed

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Mar 13, 2023

The documentation is not available anymore as the PR was closed or merged.

@patrickvonplaten
Copy link
Contributor Author

The following code now works without problems:

from diffusers import StableDiffusionPipeline
import torch

pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
pipe.unet.load_attn_procs("PhanAnh/sd-model-finetuned-lora", weight_name="pytorch_model.bin")

pipe.unet.save_attn_procs("./temp")
pipe.unet.load_attn_procs("./temp")

pipe.unet.save_attn_procs("./temp", safe_serialization=True)
pipe.unet.load_attn_procs("./temp")

pipe.unet.save_attn_procs("./temp", weight_name="lora.bin")
pipe.unet.load_attn_procs("./temp", weight_name="lora.bin")

pipe.unet.save_attn_procs("./temp", weight_name="lora.safetensors", safe_serialization=True)
pipe.unet.load_attn_procs("./temp", weight_name="lora.safetensors")

Comment on lines +153 to +155
if (is_safetensors_available() and weight_name is None) or (
weight_name is not None and weight_name.endswith(".safetensors")
):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to add a small comment highlighting that we always look for safetensors first just for easy readability?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point

"`weights_name` is deprecated, please use `weight_name` instead.",
take_from=kwargs,
)
print(weight_name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be removed?

Copy link
Member

@sayakpaul sayakpaul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks much!

Left minor nits.

@patrickvonplaten patrickvonplaten merged commit d185c0d into main Mar 14, 2023
@patrickvonplaten patrickvonplaten deleted the correct_lora_saving_loading branch March 14, 2023 16:55
w4ffl35 pushed a commit to w4ffl35/diffusers that referenced this pull request Apr 14, 2023
* [Lora] correct lora saving & loading

* fix final

* Apply suggestions from code review
yoonseokjin pushed a commit to yoonseokjin/diffusers that referenced this pull request Dec 25, 2023
* [Lora] correct lora saving & loading

* fix final

* Apply suggestions from code review
AmericanPresidentJimmyCarter pushed a commit to AmericanPresidentJimmyCarter/diffusers that referenced this pull request Apr 26, 2024
* [Lora] correct lora saving & loading

* fix final

* Apply suggestions from code review
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants