Skip to content

Conversation

@asomoza
Copy link
Member

@asomoza asomoza commented May 7, 2024

What does this PR do?

When using some LoRAs, for example sd_xl_offset_example-lora_1.0.safetensors with blockwise scales we get this error:

RuntimeError: No LoRA weight found for module down_blocks.0.resnets.0.conv1

This PR makes it so if the layer is not found, it returns the weight (scale) of the block enabling the use of these LoRAs with blockwise scales.

e.g.,

offset_scales = {
    "unet": {
        "down": {"block_1": [0.0, 0.5], "block_2": [1.0, 1.0]},
        "mid": 1.0,
        "up": {"block_0": [1.0, 1.0, 1.0], "block_1": [1.0, 1.0, 1.0]},
    },
    "text_encoder": 1.0,
    "text_encoder_2": 1.0,
}
  • If down_blocks.0.resnets.0.conv1 is not found, returns the scale of 1.0 as a default.
  • If down_blocks.1.resnets.0.conv1 is not found, returns the scale of 0.0
  • If down_blocks.1.resnets.1.conv1 is not found, returns the scale of 0.5
  • If down_blocks.2.resnets.0.conv1 is not found, returns the scale of 1.0

Fixes #7871

Who can review?

@sayakpaul @yiyixuxu @DN6

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.

Thank you!

If it's not too much could we maybe add a SLOW test for this too?

It should go here: https://github.com/huggingface/diffusers/blob/main/tests/lora/test_lora_layers_sdxl.py

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@asomoza
Copy link
Member Author

asomoza commented May 7, 2024

sure, I just noticed that I can make it better so I'll do the test and fix it a little more.

@asomoza
Copy link
Member Author

asomoza commented May 7, 2024

@sayakpaul is this test enough?

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.

This is perfect. Thank you!

@asomoza asomoza requested a review from sayakpaul May 7, 2024 09:06
@sayakpaul sayakpaul merged commit 23e0915 into huggingface:main May 7, 2024
@sayakpaul
Copy link
Member

Thanks much @asomoza!

lawrence-cj pushed a commit to lawrence-cj/diffusers that referenced this pull request May 8, 2024
* return layer weight if not found

* better system and test

* key example and typo
sayakpaul pushed a commit that referenced this pull request Dec 23, 2024
* return layer weight if not found

* better system and test

* key example and typo
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.

Error when using blockwise scales with sd_xl_offset_example-lora_1.0.safetensors

3 participants