[LoRA] Fix SDXL text encoder LoRAs by sayakpaul · Pull Request #4371 · huggingface/diffusers · GitHub
Skip to content

[LoRA] Fix SDXL text encoder LoRAs - #4371

Merged
sayakpaul merged 27 commits into
mainfrom
fix/text-encoder-sdxl-lora
Aug 2, 2023
Merged

sayakpaul merged 27 commits into
mainfrom
fix/text-encoder-sdxl-lora

Conversation

@sayakpaul

@sayakpaul sayakpaul commented Jul 30, 2023 •

Copy link
Copy Markdown
Member

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.

Comment thread src/diffusers/loaders.py Outdated
Comment thread src/diffusers/loaders.py
Comment thread src/diffusers/loaders.py
Comment thread src/diffusers/loaders.py
Comment thread src/diffusers/loaders.py
Comment on lines +1417 to +1420

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@adhikjoshi adhikjoshi Jul 31, 2023 •

Copy link
Copy Markdown

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
Copy Markdown
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

HuggingFaceDocBuilderDev commented Jul 30, 2023 •

Copy link
Copy Markdown

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

@adhikjoshi

Copy link
Copy Markdown

Lycoris still not working for SDXL

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

@sayakpaul

Copy link
Copy Markdown
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 :-)

Comment thread src/diffusers/loaders.py Outdated

@patrickvonplaten patrickvonplaten left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Member Author

@sayakpaul
sayakpaul merged commit 816ca00 into main Aug 2, 2023
@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.

4 participants