-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Add converter method for ip adapters #6150
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
Conversation
|
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. |
|
can we maybe keep this function on the same file? |
src/diffusers/loaders/unet.py
Outdated
| if hasattr(self, "peft_config"): | ||
| self.peft_config.pop(adapter_name, None) | ||
|
|
||
| def _convert_ip_adapter_to_diffusers(self, state_dict): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| def _convert_ip_adapter_to_diffusers(self, state_dict): | |
| def _convert_ip_adapter_image_proj_to_diffusers(self, state_dict): |
There was a problem hiding this comment.
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.
src/diffusers/loaders/unet.py
Outdated
| else: | ||
| new_sd[k] = v | ||
|
|
||
| new_sd = self._convert_ip_adapter_to_diffusers(image_proj_state_dict) |
There was a problem hiding this comment.
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?
src/diffusers/loaders/unet.py
Outdated
| new_sd = self._convert_ip_adapter_to_diffusers(image_proj_state_dict) | ||
| image_projection.load_state_dict(new_sd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed better and cleaner!
src/diffusers/loaders/unet.py
Outdated
| ) | ||
| 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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) |
src/diffusers/loaders/unet.py
Outdated
| ) | ||
| 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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) |
sayakpaul
left a comment
There was a problem hiding this 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?
patrickvonplaten
left a comment
There was a problem hiding this 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 @sayakpaul @patrickvonplaten thank you for your time and digging into the code :) |
* Add converter method for ip adapters * Move converter method * Update to image proj converter --------- Co-authored-by: Sayak Paul <[email protected]>
* Add converter method for ip adapters * Move converter method * Update to image proj converter --------- Co-authored-by: Sayak Paul <[email protected]>
* Add converter method for ip adapters * Move converter method * Update to image proj converter --------- Co-authored-by: Sayak Paul <[email protected]>
What does this PR do?
Fixes 5915 (comment)
Before submitting
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