Unverified Commit 3c79dd9d authored by Steven Liu's avatar Steven Liu Committed by GitHub
Browse files

[docs] PEFT adapter API (#6499)

follow up
parent 9d767916
...@@ -12,14 +12,14 @@ specific language governing permissions and limitations under the License. ...@@ -12,14 +12,14 @@ specific language governing permissions and limitations under the License.
# PEFT # 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> <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> </Tip>
## PeftAdapterMixin ## PeftAdapterMixin
[[autodoc]] loaders.peft.PeftAdapterMixin [[autodoc]] loaders.peft.PeftAdapterMixin
\ No newline at end of file
...@@ -20,15 +20,13 @@ from ..utils import MIN_PEFT_VERSION, check_peft_version, is_peft_available ...@@ -20,15 +20,13 @@ from ..utils import MIN_PEFT_VERSION, check_peft_version, is_peft_available
class PeftAdapterMixin: class PeftAdapterMixin:
""" """
A class containing all functions for loading and using adapters weights that are supported in PEFT library. For 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 more details about adapters and injecting them in a transformer-based model, check out the PEFT [documentation](https://huggingface.co/docs/peft/index).
library: https://huggingface.co/docs/peft/index.
Install the latest version of PEFT, and use this mixin to:
With this mixin, if the correct PEFT version is installed, it is possible to:
- Attach new adapters in the model. - Attach new adapters in the model.
- Attach multiple adapters and iteratively activate / deactivate them. - Attach multiple adapters and iteratively activate/deactivate them.
- Activate / deactivate all adapters from the model. - Activate/deactivate all adapters from the model.
- Get a list of the active adapters. - Get a list of the active adapters.
""" """
...@@ -77,11 +75,11 @@ class PeftAdapterMixin: ...@@ -77,11 +75,11 @@ class PeftAdapterMixin:
Sets a specific adapter by forcing the model to only use that adapter and disables the other adapters. 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 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: Args:
adapter_name (Union[str, List[str]])): 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) check_peft_version(min_version=MIN_PEFT_VERSION)
...@@ -126,7 +124,7 @@ class PeftAdapterMixin: ...@@ -126,7 +124,7 @@ class PeftAdapterMixin:
Disable all adapters attached to the model and fallback to inference with the base model only. 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 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) check_peft_version(min_version=MIN_PEFT_VERSION)
...@@ -145,11 +143,11 @@ class PeftAdapterMixin: ...@@ -145,11 +143,11 @@ class PeftAdapterMixin:
def enable_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. 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 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) check_peft_version(min_version=MIN_PEFT_VERSION)
...@@ -171,7 +169,7 @@ class PeftAdapterMixin: ...@@ -171,7 +169,7 @@ class PeftAdapterMixin:
Gets the current list of active adapters of the model. 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 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) check_peft_version(min_version=MIN_PEFT_VERSION)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment