Skip to content

[SD3 LoRA] Fix list index out of range #8584

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

Merged
merged 12 commits into from
Jun 21, 2024

Conversation

asomoza
Copy link
Member

@asomoza asomoza commented Jun 16, 2024

What does this PR do?

For some reason, the LoRA state_dict gets saved with both formats, PEFT and Diffusers, this PR add the convert_unet_state_dict_to_peft to the loading function so it works with both.

Fixes #8579 #8565

Who can review?

Anyone in the community is free to review

@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 asomoza changed the title [SD3] Fix lora list index out of range [SD3 LoRA] Fix list index out of range Jun 16, 2024
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! Left a single comment.

@asomoza
Copy link
Member Author

asomoza commented Jun 20, 2024

@sayakpaul is this test case good enough? if it is, I can upload the loras to the internal testing repo. I ran the test locally and it passes with the PR and fails without it.

Comment on lines 291 to 305
def test_sd3_lora(self):
components = self.get_dummy_components()

pipe = self.pipeline_class(**components)
pipe = pipe.to(torch_device)
pipe.set_progress_bar_config(disable=None)

lora_model_id = "OzzyGT/lora_test"
lora_filename = "lora_diffusers_format.safetensors"
pipe.load_lora_weights(lora_model_id, weight_name=lora_filename)
pipe.unload_lora_weights()

lora_model_id = "OzzyGT/lora_test"
lora_filename = "lora_peft_format.safetensors"
pipe.load_lora_weights(lora_model_id, weight_name=lora_filename)
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for adding the tests.

We should perhaps make this a SLOW one or require this test to have a GPU (@require_torch_gpu). And also add a comment to explain why we had to add this test. I think adding a mention of this PR is just fine.

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 a ton for this. I have left one minor comment but it's not a blocker.

@vladmandic
Copy link
Contributor

any reason why this was not merged and included in diffusers==0.29.1?

@sayakpaul
Copy link
Member

It left some crucial checks and tests.

@asomoza
Copy link
Member Author

asomoza commented Jun 21, 2024

@sayakpaul I don't have write permissions in hf-internal-testing. Can you please upload the loras somewhere there.

Just in case, these are tiny loras (2kb) that I made using the tiny-sd3-pipe

https://huggingface.co/OzzyGT/lora_test/tree/main

"vae": vae,
}

def test_sd3_lora(self):
Copy link
Member

Choose a reason for hiding this comment

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

@asomoza I think just this test could be marked with "require_torch_gpu" and be made a part of this class:

class SD3LoRATests(unittest.TestCase):

I think that will be good enough.

Once this is done, feel free to merge the PR :)

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.

@sayakpaul sayakpaul merged commit e7b9a07 into huggingface:main Jun 21, 2024
15 checks passed
sayakpaul added a commit that referenced this pull request Dec 23, 2024
* fix

* add check

* key present is checked before

* test case draft

* aply suggestions

* changed testing repo, back to old class

* forgot docstring

---------

Co-authored-by: YiYi Xu <[email protected]>
Co-authored-by: Sayak Paul <[email protected]>
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.

SD3 lora support non functional
5 participants