#
PEFT

Diffusers supports working with adapters (such as LoRA) via the `peft` library. We provide a `PeftAdapterMixin` class to handle this for modeling classes in Diffusers (such as UNet2DConditionModel).

Refer to this doc to get an overview of how to work with `peft` in Diffusers for inference.

##
PeftAdapterMixin

###
class diffusers.loaders.PeftAdapterMixin

< source >

( )

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.

With this mixin, if the correct PEFT version is installed, it is possible to:

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

####
active_adapters

< source >

( )

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

####
add_adapter

< source >

( adapter_config adapter_name: str = 'default' )

Parameters

- adapter_config (`[~peft.PeftConfig]`) — The configuration of the adapter to add; supported adapters are non-prefix tuning and adaption prompt methods.
- adapter_name (`str`, optional, defaults to `"default"`) — The name of the adapter to add. If no name is passed, a default name is assigned to the adapter.

Adds a new adapter to the current model for training. If no adapter name is passed, a default name is assigned to the adapter to follow the convention of the PEFT library.

If you are not familiar with adapters and PEFT methods, we invite you to read more about them in the PEFT documentation.

####
disable_adapters

< source >

( )

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

####
enable_adapters

< source >

( )

Enable adapters that are attached to the model. The model will use `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

####
set_adapter

< source >

( adapter_name: typing.Union[str, typing.List[str]] )

Parameters

- adapter_name (Union[str, List[str]])) — The list of adapters to set or the adapter name in case of single adapter.

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