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

Add converter method for ip adapters #6150

Merged
merged 4 commits into from
Dec 18, 2023

Conversation

fabiorigano
Copy link
Contributor

What does this PR do?

Fixes 5915 (comment)

Before submitting

  • Did you read the contributor guideline?
  • Did you read our philosophy doc (important for complex PRs)?
  • Was this discussed/approved via a GitHub issue or the forum? Please add a link to it if that's the case.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@patrickvonplaten

@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.

@yiyixuxu
Copy link
Collaborator

can we maybe keep this function on the same file?

@fabiorigano
Copy link
Contributor Author

can we maybe keep this function on the same file?

done

I was wondering if it wouldn't be better to merge the two if blocks in _load_ip_adapter_weights, at line 713 and line 768

@@ -664,6 +664,44 @@ def delete_adapters(self, adapter_names: Union[List[str], str]):
if hasattr(self, "peft_config"):
self.peft_config.pop(adapter_name, None)

def _convert_ip_adapter_to_diffusers(self, state_dict):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
def _convert_ip_adapter_to_diffusers(self, state_dict):
def _convert_ip_adapter_image_proj_to_diffusers(self, state_dict):

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should move this method to https://github.com/huggingface/diffusers/blob/main/src/diffusers/loaders/ip_adapter.py. This way the UNet loader stays cleaner.

else:
new_sd[k] = v

new_sd = self._convert_ip_adapter_to_diffusers(image_proj_state_dict)
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we have this function return the image_projection module instead?

@yiyixuxu yiyixuxu requested a review from sayakpaul December 15, 2023 20:21
Comment on lines 780 to 781
new_sd = self._convert_ip_adapter_to_diffusers(image_proj_state_dict)
image_projection.load_state_dict(new_sd)
Copy link
Member

Choose a reason for hiding this comment

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

Indeed better and cleaner!

)
image_projection.load_state_dict(image_proj_state_dict)
del image_proj_state_dict
new_sd = self._convert_ip_adapter_to_diffusers(image_proj_state_dict)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
new_sd = self._convert_ip_adapter_to_diffusers(image_proj_state_dict)
new_sd = self._convert_ip_adapter_image_proj_to_diffusers(image_proj_state_dict)

)
image_projection.load_state_dict(image_proj_state_dict)
del image_proj_state_dict
new_sd = self._convert_ip_adapter_to_diffusers(image_proj_state_dict)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
new_sd = self._convert_ip_adapter_to_diffusers(image_proj_state_dict)
new_sd = self._convert_ip_adapter_image_proj_to_diffusers(image_proj_state_dict)

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.

Really nice work!

@yiyixuxu can we also run the SLOW tests related to IP adapters with these changes before merging?

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.

Ok to merge for me once @yiyixuxu is happy with it

@yiyixuxu yiyixuxu merged commit 68e9623 into huggingface:main Dec 18, 2023
14 checks passed
@fabiorigano
Copy link
Contributor Author

@yiyixuxu @sayakpaul @patrickvonplaten thank you for your time and digging into the code :)

yoonseokjin pushed a commit to yoonseokjin/diffusers that referenced this pull request Dec 25, 2023
* Add converter method for ip adapters

* Move converter method

* Update to image proj converter

---------

Co-authored-by: Sayak Paul <[email protected]>
donhardman pushed a commit to donhardman/diffusers that referenced this pull request Dec 29, 2023
* Add converter method for ip adapters

* Move converter method

* Update to image proj converter

---------

Co-authored-by: Sayak Paul <[email protected]>
AmericanPresidentJimmyCarter pushed a commit to AmericanPresidentJimmyCarter/diffusers that referenced this pull request Apr 26, 2024
* Add converter method for ip adapters

* Move converter method

* Update to image proj converter

---------

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.

5 participants