Skip to content

Conversation

@sayakpaul
Copy link
Member

@sayakpaul sayakpaul commented Jan 1, 2024

What does this PR do?

Delegate the peft related methods residing under ModelMixin to a separate class called PeftAdapterMixin following what's done in transformers: https://github.com/huggingface/transformers/blob/main/src/transformers/integrations/peft.py#L43.

It also introduces a new module called integrations, again, following transformers. I see it playing to our advantage:

  • modeling_utils.py becomes cleaner.
  • Clear separation of concerns.
  • If we want to add new integrations (such as with bitsandbytes), we'd have a better structure.

I don't suspect anything introduced in this PR to be backwards-breaking but happy to be proven wrong and fix it.

@sayakpaul sayakpaul requested a review from DN6 January 1, 2024 09:40
Copy link
Collaborator

@DN6 DN6 left a comment

Choose a reason for hiding this comment

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

Makes sense to me. Think we could also do this for xformers.

@sayakpaul
Copy link
Member Author

Think we could also do this for xformers.

xformers -- I think not as it's dealt similarly as SDPA, by means of an attention processor.

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.

Nice idea to factor out PEFT into a Mixin!
Two questions:

  • 1.) It was already the case before, but do we really want to allow PEFT adaptors for all models. E.g. does it make sense that a VAE can also add LoRA layers?
  • 2.) Can we maybe move the Mixin to src/diffusers/loaders ?

@sayakpaul
Copy link
Member Author

It was already the case before, but do we really want to allow PEFT adaptors for all models. E.g. does it make sense that a VAE can also add LoRA layers?

This is what I think too. So, instead of adding the PEFT mixin to ModelMixin we can be selective and only add to the models that we know are used in LoRA training (from our official scripts). WDYT?

Can we maybe move the Mixin to src/diffusers/loaders ?

I am okay. I just followed what transformers did to have a unified structure. LMK.

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

@DN6
Copy link
Collaborator

DN6 commented Jan 2, 2024

This is what I think too. So, instead of adding the PEFT mixin to ModelMixin we can be selective and only add to the models that we know are used in LoRA training (from our official scripts). WDYT?

I like this idea. It also keeps ModelMixin from getting bloated.

_import_structure["textual_inversion"] = ["TextualInversionLoaderMixin"]
_import_structure["ip_adapter"] = ["IPAdapterMixin"]

_import_structure["peft"] = ["PeftAdapterMixin"]
Copy link
Member Author

Choose a reason for hiding this comment

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

This is out of the condition because:

  • It's gonna be directly used in the core models (wherever applicable).
  • In our core test environment, we don't install peft. So, if we add the above under is_peft_available(), we will run into import errors.

Can move it under is_torch_available(), though.

@DN6 let me know if you have a better way of handling this.

from .single_file import FromSingleFileMixin
from .textual_inversion import TextualInversionLoaderMixin

from .peft import PeftAdapterMixin
Copy link
Member Author

Choose a reason for hiding this comment

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

@sayakpaul
Copy link
Member Author

For the failing test: #6426 (comment).

@sayakpaul
Copy link
Member Author

@patrickvonplaten addressed your comments:

  • Moved PeftAdapterMixin to src/diffusers/loaders.
  • Added PeftAdapterMixin as an inheritance to only a few selected models that are used in our training scripts.
  • Added a doc.

This is my open question: #6416 (comment)

@DN6 LMK your thoughts too.

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.

Nice that works for me!

@sayakpaul sayakpaul changed the title [Core] introduce integrations module. [Core] introduce PeftAdapterMixin module. Jan 5, 2024
@sayakpaul
Copy link
Member Author

@stevhliu feel free to edit the docs introduced in this PR in a follow-up.

@sayakpaul sayakpaul merged commit 585f941 into main Jan 5, 2024
@sayakpaul sayakpaul deleted the introduce-intrgrations branch January 5, 2024 12:48
Copy link
Contributor

@younesbelkada younesbelkada 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 very clean thanks @sayakpaul and team!

@stevhliu stevhliu mentioned this pull request Jan 8, 2024
AmericanPresidentJimmyCarter pushed a commit to AmericanPresidentJimmyCarter/diffusers that referenced this pull request Apr 26, 2024
* introduce integrations module.

* remove duplicate methods.

* better imports.

* move to loaders.py

* remove peftadaptermixin from modelmixin.

* add: peftadaptermixin selectively.

* add: entry to _toctree

* Empty-Commit
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.

6 participants