From ed616bd8a8740927770eebe017aedb6204c6105f Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Wed, 18 Jan 2023 18:05:51 +0100 Subject: [PATCH] [LoRA] Add LoRA training script (#1884) * [Lora] first upload * add first lora version * upload * more * first training * up * correct * improve * finish loaders and inference * up * up * fix more * up * finish more * finish more * up * up * change year * revert year change * Change lines * Add cloneofsimo as co-author. Co-authored-by: Simo Ryu * finish * fix docs * Apply suggestions from code review Co-authored-by: Pedro Cuenca Co-authored-by: Suraj Patil * upload * finish Co-authored-by: Simo Ryu Co-authored-by: Pedro Cuenca Co-authored-by: Suraj Patil --- docs/source/en/_toctree.yml | 2 + docs/source/en/api/loaders.mdx | 30 + docs/source/en/api/logging.mdx | 2 +- examples/dreambooth/README.md | 97 ++ examples/dreambooth/train_dreambooth.py | 15 + examples/dreambooth/train_dreambooth_lora.py | 950 ++++++++++++++++++ examples/text_to_image/train_text_to_image.py | 15 + .../textual_inversion/textual_inversion.py | 15 + src/diffusers/dependency_versions_check.py | 2 +- src/diffusers/loaders.py | 243 +++++ src/diffusers/models/cross_attention.py | 97 ++ src/diffusers/models/modeling_utils.py | 96 +- src/diffusers/models/unet_2d_condition.py | 59 +- .../versatile_diffusion/modeling_text_unet.py | 56 +- src/diffusers/utils/__init__.py | 1 + src/diffusers/utils/import_utils.py | 18 + src/diffusers/utils/logging.py | 2 +- tests/models/test_models_unet_2d.py | 552 +--------- tests/models/test_models_unet_2d_condition.py | 688 +++++++++++++ utils/check_inits.py | 2 +- utils/check_repo.py | 2 +- utils/check_table.py | 2 +- utils/custom_init_isort.py | 2 +- utils/get_modified_files.py | 2 +- 24 files changed, 2287 insertions(+), 663 deletions(-) create mode 100644 docs/source/en/api/loaders.mdx create mode 100644 examples/dreambooth/train_dreambooth_lora.py create mode 100644 src/diffusers/loaders.py create mode 100644 tests/models/test_models_unet_2d_condition.py diff --git a/docs/source/en/_toctree.yml b/docs/source/en/_toctree.yml index 2c0d94fcc1..eb1ed412e2 100644 --- a/docs/source/en/_toctree.yml +++ b/docs/source/en/_toctree.yml @@ -90,6 +90,8 @@ title: Configuration - local: api/outputs title: Outputs + - local: api/loaders + title: Loaders title: Main Classes - sections: - local: api/pipelines/overview diff --git a/docs/source/en/api/loaders.mdx b/docs/source/en/api/loaders.mdx new file mode 100644 index 0000000000..c850cdfe47 --- /dev/null +++ b/docs/source/en/api/loaders.mdx @@ -0,0 +1,30 @@ + + +# Loaders + +There are many weights to train adapter neural networks for diffusion models, such as +- [Textual Inversion](./training/text_inversion.mdx) +- [LoRA](https://github.com/cloneofsimo/lora) +- [Hypernetworks](https://arxiv.org/abs/1609.09106) + +Such adapter neural networks often only consist of a fraction of the number of weights compared +to the pretrained model and as such are very portable. The Diffusers library offers an easy-to-use +API to load such adapter neural networks via the [`loaders.py` module](https://github.com/huggingface/diffusers/blob/main/src/diffusers/loaders.py). + +**Note**: This module is still highly experimental and prone to future changes. + +## LoaderMixins + +### UNet2DConditionLoadersMixin + +[[autodoc]] loaders.UNet2DConditionLoadersMixin diff --git a/docs/source/en/api/logging.mdx b/docs/source/en/api/logging.mdx index 5d75ec8e01..b726d46d92 100644 --- a/docs/source/en/api/logging.mdx +++ b/docs/source/en/api/logging.mdx @@ -1,4 +1,4 @@ -