Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/source/en/api/loaders/peft.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ specific language governing permissions and limitations under the License.

# PEFT

Diffusers supports working with adapters (such as [LoRA](../../using-diffusers/loading_adapters)) via the [`peft` library](https://huggingface.co/docs/peft/index). We provide a `PeftAdapterMixin` class to handle this for modeling classes in Diffusers (such as [`UNet2DConditionModel`]).
Diffusers supports loading adapters such as [LoRA](../../using-diffusers/loading_adapters) with the [PEFT](https://huggingface.co/docs/peft/index) library with the [`~loaders.peft.PeftAdapterMixin`] class. This allows modeling classes in Diffusers like [`UNet2DConditionModel`] to load an adapter.

<Tip>

Refer to [this doc](../../tutorials/using_peft_for_inference.md) to get an overview of how to work with `peft` in Diffusers for inference.
Refer to the [Inference with PEFT](../../tutorials/using_peft_for_inference.md) tutorial for an overview of how to use PEFT in Diffusers for inference.

</Tip>

## PeftAdapterMixin

[[autodoc]] loaders.peft.PeftAdapterMixin
[[autodoc]] loaders.peft.PeftAdapterMixin
22 changes: 10 additions & 12 deletions src/diffusers/loaders/peft.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
class PeftAdapterMixin:
"""
A class containing all functions for loading and using adapters weights that are supported in PEFT library. For
more details about adapters and injecting them on a transformer-based model, check out the documentation of PEFT
library: https://huggingface.co/docs/peft/index.
more details about adapters and injecting them in a transformer-based model, check out the PEFT [documentation](https://huggingface.co/docs/peft/index).


With this mixin, if the correct PEFT version is installed, it is possible to:
Install the latest version of PEFT, and use this mixin to:

- Attach new adapters in the model.
- Attach multiple adapters and iteratively activate / deactivate them.
- Activate / deactivate all adapters from the model.
- Attach multiple adapters and iteratively activate/deactivate them.
- Activate/deactivate all adapters from the model.
- Get a list of the active adapters.
"""

Expand Down Expand Up @@ -77,11 +75,11 @@ def set_adapter(self, adapter_name: Union[str, List[str]]) -> None:
Sets a specific adapter by forcing the model to only use that adapter and disables the other adapters.

If you are not familiar with adapters and PEFT methods, we invite you to read more about them on the PEFT
official documentation: https://huggingface.co/docs/peft
[documentation](https://huggingface.co/docs/peft).

Args:
adapter_name (Union[str, List[str]])):
The list of adapters to set or the adapter name in case of single adapter.
The list of adapters to set or the adapter name in the case of a single adapter.
"""
check_peft_version(min_version=MIN_PEFT_VERSION)

Expand Down Expand Up @@ -126,7 +124,7 @@ def disable_adapters(self) -> None:
Disable all adapters attached to the model and fallback to inference with the base model only.

If you are not familiar with adapters and PEFT methods, we invite you to read more about them on the PEFT
official documentation: https://huggingface.co/docs/peft
[documentation](https://huggingface.co/docs/peft).
"""
check_peft_version(min_version=MIN_PEFT_VERSION)

Expand All @@ -145,11 +143,11 @@ def disable_adapters(self) -> None:

def enable_adapters(self) -> None:
"""
Enable adapters that are attached to the model. The model will use `self.active_adapters()` to retrieve the
Enable adapters that are attached to the model. The model uses `self.active_adapters()` to retrieve the
list of adapters to enable.

If you are not familiar with adapters and PEFT methods, we invite you to read more about them on the PEFT
official documentation: https://huggingface.co/docs/peft
[documentation](https://huggingface.co/docs/peft).
"""
check_peft_version(min_version=MIN_PEFT_VERSION)

Expand All @@ -171,7 +169,7 @@ def active_adapters(self) -> List[str]:
Gets the current list of active adapters of the model.

If you are not familiar with adapters and PEFT methods, we invite you to read more about them on the PEFT
official documentation: https://huggingface.co/docs/peft
[documentation](https://huggingface.co/docs/peft).
"""
check_peft_version(min_version=MIN_PEFT_VERSION)

Expand Down