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] Fix SDXL text encoder LoRAs #4371

Merged
merged 27 commits into from
Aug 2, 2023
Merged

Conversation

sayakpaul
Copy link
Member

@sayakpaul sayakpaul commented Jul 30, 2023

This PR fixes the LoRA loading part for the text encoders, especially the ones we see for SDXL 0.9.

Additionally, it also refactors some of the loading logic to help make the state_dict parsing easier.

I tested with the following:

from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
import safetensors
import torch 

base_model_id = "stabilityai/stable-diffusion-xl-base-0.9"
pipeline = DiffusionPipeline.from_pretrained(base_model_id, torch_dtype=torch.float16).to("cuda:0")
pipeline.scheduler = DPMSolverMultistepScheduler.from_config(
    pipeline.scheduler.config, algorithm_type="sde-dpmsolver++"
)
pipeline.load_lora_weights(".", weight_name="daiton.safetensors")

prompt = "alien, monster, daiton, high resolution, 4k, photorealistic, in a spaceship, gloomy"
generator = torch.manual_seed(22)
num_inference_steps = 50
guidance_scale = 5

image = pipeline(
    prompt=prompt, num_inference_steps=num_inference_steps,
    generator=generator, guidance_scale=guidance_scale
).images[0]
image.save("image.png")

And got:

image

LoRA is from here: https://civitai.com/models/108448/daiton-sdxl-test

@patrickvonplaten I see we don't do SLOW tests for SDXL, probably because we run the SLOW tests on a V100, which might fall short of running SDXL. I am bringing it up because I wanted to add a couple of slow tests to test_lora_layers.py to test the SDXL LoRAs from CivitAI.

Some comments are in line.

Also, I have run the SLOW tests and they pass successfully.

src/diffusers/loaders.py Outdated Show resolved Hide resolved
src/diffusers/loaders.py Outdated Show resolved Hide resolved
Comment on lines +1417 to +1420
if is_network_alphas_populated and len(network_alphas) > 0:
raise ValueError(
f"The `network_alphas` has to be empty at this point but has the following keys \n\n {', '.join(network_alphas.keys())}"
)
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link

Choose a reason for hiding this comment

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

Can we show ValueError as warning log (non supported lora ) and move on instead of raise error?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think a ValueError is great here

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jul 30, 2023

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

@adhikjoshi
Copy link

Lycoris still not working for SDXL

https://civitai.com/models/108011/fcbodybuildingxl-10-for-sdxl

@sayakpaul
Copy link
Member Author

Lycoris still not working for SDXL

https://civitai.com/models/108011/fcbodybuildingxl-10-for-sdxl

I think we talked about it in the other thread too. It might be happening because LyCORIS adapters can contain LoHA modules too which we don't support yet.

Let's try not to duplicate these things :-)

Copy link
Contributor

@patrickvonplaten patrickvonplaten left a comment

Choose a reason for hiding this comment

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

Very nice! Only left a couple of minor suggestions

Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
@sayakpaul
Copy link
Member Author

Merging a potentially impactful one. Fingers crossed!

@sayakpaul sayakpaul merged commit 816ca00 into main Aug 2, 2023
10 checks passed
@sayakpaul sayakpaul deleted the fix/text-encoder-sdxl-lora branch August 2, 2023 11:31
yoonseokjin pushed a commit to yoonseokjin/diffusers that referenced this pull request Dec 25, 2023
* temporarily disable text encoder loras.

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debbuging.

* modify doc.

* rename tests.

* print slices.

* fix: assertions

* Apply suggestions from code review

Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>

---------

Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
AmericanPresidentJimmyCarter pushed a commit to AmericanPresidentJimmyCarter/diffusers that referenced this pull request Apr 26, 2024
* temporarily disable text encoder loras.

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debugging

* debbuging.

* modify doc.

* rename tests.

* print slices.

* fix: assertions

* Apply suggestions from code review

Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>

---------

Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
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.

None yet

4 participants