Skip to content

Commit

Permalink
Merge pull request #154 from huggingface/main
Browse files Browse the repository at this point in the history
Merge changes
  • Loading branch information
Skquark authored Apr 2, 2024
2 parents ff1b117 + 2b04ec2 commit 3a94596
Show file tree
Hide file tree
Showing 165 changed files with 8,546 additions and 508 deletions.
376 changes: 304 additions & 72 deletions .github/workflows/nightly_tests.yml

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions .github/workflows/pr_test_peft_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ jobs:
run: |
ruff check examples tests src utils scripts
ruff format examples tests src utils scripts --check
- name: Check if failure
if: ${{ failure() }}
run: |
echo "Quality check failed. Please ensure the right dependency versions are installed with 'pip install -e .[quality]' and run 'make style && make quality'" >> $GITHUB_STEP_SUMMARY
check_repository_consistency:
needs: check_code_quality
Expand All @@ -54,6 +58,10 @@ jobs:
python utils/check_copies.py
python utils/check_dummies.py
make deps_table_check_updated
- name: Check if failure
if: ${{ failure() }}
run: |
echo "Repo consistency check failed. Please ensure the right dependency versions are installed with 'pip install -e .[quality]' and run 'make fix-copies'" >> $GITHUB_STEP_SUMMARY
run_fast_tests:
needs: [check_code_quality, check_repository_consistency]
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/pr_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ jobs:
run: |
ruff check examples tests src utils scripts
ruff format examples tests src utils scripts --check
- name: Check if failure
if: ${{ failure() }}
run: |
echo "Quality check failed. Please ensure the right dependency versions are installed with 'pip install -e .[quality]' and run 'make style && make quality'" >> $GITHUB_STEP_SUMMARY
check_repository_consistency:
needs: check_code_quality
Expand All @@ -62,6 +66,10 @@ jobs:
python utils/check_copies.py
python utils/check_dummies.py
make deps_table_check_updated
- name: Check if failure
if: ${{ failure() }}
run: |
echo "Repo consistency check failed. Please ensure the right dependency versions are installed with 'pip install -e .[quality]' and run 'make fix-copies'" >> $GITHUB_STEP_SUMMARY
run_fast_tests:
needs: [check_code_quality, check_repository_consistency]
Expand Down
2 changes: 1 addition & 1 deletion docs/source/en/training/controlnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ accelerate config default

Or if your environment doesn't support an interactive shell, like a notebook, you can use:

```bash
```py
from accelerate.utils import write_basic_config

write_basic_config()
Expand Down
4 changes: 2 additions & 2 deletions docs/source/en/training/custom_diffusion.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ accelerate config default

Or if your environment doesn't support an interactive shell, like a notebook, you can use:

```bash
```py
from accelerate.utils import write_basic_config

write_basic_config()
Expand Down Expand Up @@ -84,7 +84,7 @@ Many of the basic parameters are described in the [DreamBooth](dreambooth#script
- `--freeze_model`: freezes the key and value parameters in the cross-attention layer; the default is `crossattn_kv`, but you can set it to `crossattn` to train all the parameters in the cross-attention layer
- `--concepts_list`: to learn multiple concepts, provide a path to a JSON file containing the concepts
- `--modifier_token`: a special word used to represent the learned concept
- `--initializer_token`:
- `--initializer_token`: a special word used to initialize the embeddings of the `modifier_token`

### Prior preservation loss

Expand Down
4 changes: 2 additions & 2 deletions docs/source/en/training/dreambooth.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ accelerate config default

Or if your environment doesn't support an interactive shell, like a notebook, you can use:

```bash
```py
from accelerate.utils import write_basic_config

write_basic_config()
Expand Down Expand Up @@ -180,7 +180,7 @@ elif args.pretrained_model_name_or_path:
revision=args.revision,
use_fast=False,
)

# Load scheduler and models
noise_scheduler = DDPMScheduler.from_pretrained(args.pretrained_model_name_or_path, subfolder="scheduler")
text_encoder = text_encoder_cls.from_pretrained(
Expand Down
4 changes: 2 additions & 2 deletions docs/source/en/training/instructpix2pix.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ accelerate config default

Or if your environment doesn't support an interactive shell, like a notebook, you can use:

```bash
```py
from accelerate.utils import write_basic_config

write_basic_config()
Expand Down Expand Up @@ -89,7 +89,7 @@ The dataset preprocessing code and training loop are found in the [`main()`](htt

As with the script parameters, a walkthrough of the training script is provided in the [Text-to-image](text2image#training-script) training guide. Instead, this guide takes a look at the InstructPix2Pix relevant parts of the script.

The script begins by modifing the [number of input channels](https://github.com/huggingface/diffusers/blob/64603389da01082055a901f2883c4810d1144edb/examples/instruct_pix2pix/train_instruct_pix2pix.py#L445) in the first convolutional layer of the UNet to account for InstructPix2Pix's additional conditioning image:
The script begins by modifying the [number of input channels](https://github.com/huggingface/diffusers/blob/64603389da01082055a901f2883c4810d1144edb/examples/instruct_pix2pix/train_instruct_pix2pix.py#L445) in the first convolutional layer of the UNet to account for InstructPix2Pix's additional conditioning image:

```py
in_channels = 8
Expand Down
6 changes: 3 additions & 3 deletions docs/source/en/training/kandinsky.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ accelerate config default

Or if your environment doesn't support an interactive shell, like a notebook, you can use:

```bash
```py
from accelerate.utils import write_basic_config

write_basic_config()
Expand Down Expand Up @@ -235,7 +235,7 @@ accelerate launch --mixed_precision="fp16" train_text_to_image_prior.py \
--validation_prompts="A robot pokemon, 4k photo" \
--report_to="wandb" \
--push_to_hub \
--output_dir="kandi2-prior-pokemon-model"
--output_dir="kandi2-prior-pokemon-model"
```

</hfoption>
Expand All @@ -259,7 +259,7 @@ accelerate launch --mixed_precision="fp16" train_text_to_image_decoder.py \
--validation_prompts="A robot pokemon, 4k photo" \
--report_to="wandb" \
--push_to_hub \
--output_dir="kandi2-decoder-pokemon-model"
--output_dir="kandi2-decoder-pokemon-model"
```

</hfoption>
Expand Down
4 changes: 2 additions & 2 deletions docs/source/en/training/lcm_distill.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ accelerate config default

Or if your environment doesn't support an interactive shell, like a notebook, you can use:

```bash
```py
from accelerate.utils import write_basic_config

write_basic_config()
Expand Down Expand Up @@ -252,4 +252,4 @@ The SDXL training script is discussed in more detail in the [SDXL training](sdxl
Congratulations on distilling a LCM model! To learn more about LCM, the following may be helpful:

- Learn how to use [LCMs for inference](../using-diffusers/lcm) for text-to-image, image-to-image, and with LoRA checkpoints.
- Read the [SDXL in 4 steps with Latent Consistency LoRAs](https://huggingface.co/blog/lcm_lora) blog post to learn more about SDXL LCM-LoRA's for super fast inference, quality comparisons, benchmarks, and more.
- Read the [SDXL in 4 steps with Latent Consistency LoRAs](https://huggingface.co/blog/lcm_lora) blog post to learn more about SDXL LCM-LoRA's for super fast inference, quality comparisons, benchmarks, and more.
2 changes: 1 addition & 1 deletion docs/source/en/training/sdxl.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ accelerate config default

Or if your environment doesn't support an interactive shell, like a notebook, you can use:

```bash
```py
from accelerate.utils import write_basic_config

write_basic_config()
Expand Down
2 changes: 1 addition & 1 deletion docs/source/en/training/t2i_adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ accelerate config default

Or if your environment doesn't support an interactive shell, like a notebook, you can use:

```bash
```py
from accelerate.utils import write_basic_config

write_basic_config()
Expand Down
2 changes: 1 addition & 1 deletion docs/source/en/training/text2image.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ accelerate config default

Or if your environment doesn't support an interactive shell, like a notebook, you can use:

```bash
```py
from accelerate.utils import write_basic_config

write_basic_config()
Expand Down
2 changes: 1 addition & 1 deletion docs/source/en/training/text_inversion.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ accelerate config default

Or if your environment doesn't support an interactive shell, like a notebook, you can use:

```bash
```py
from accelerate.utils import write_basic_config

write_basic_config()
Expand Down
2 changes: 1 addition & 1 deletion docs/source/en/training/unconditional_training.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ accelerate config default

Or if your environment doesn't support an interactive shell like a notebook, you can use:

```bash
```py
from accelerate.utils import write_basic_config

write_basic_config()
Expand Down
4 changes: 2 additions & 2 deletions docs/source/en/training/wuerstchen.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ accelerate config default

Or if your environment doesn't support an interactive shell, like a notebook, you can use:

```bash
```py
from accelerate.utils import write_basic_config

write_basic_config()
Expand Down Expand Up @@ -173,7 +173,7 @@ pipeline = AutoPipelineForText2Image.from_pretrained("path/to/saved/model", torc

caption = "A cute bird pokemon holding a shield"
images = pipeline(
caption,
caption,
width=1024,
height=1536,
prior_timesteps=DEFAULT_STAGE_C_TIMESTEPS,
Expand Down
56 changes: 56 additions & 0 deletions docs/source/en/tutorials/using_peft_for_inference.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,62 @@ image

![no-lora](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/peft_integration/diffusers_peft_lora_inference_20_1.png)

### Customize adapters strength
For even more customization, you can control how strongly the adapter affects each part of the pipeline. For this, pass a dictionary with the control strengths (called "scales") to [`~diffusers.loaders.UNet2DConditionLoadersMixin.set_adapters`].

For example, here's how you can turn on the adapter for the `down` parts, but turn it off for the `mid` and `up` parts:
```python
pipe.enable_lora() # enable lora again, after we disabled it above
prompt = "toy_face of a hacker with a hoodie, pixel art"
adapter_weight_scales = { "unet": { "down": 1, "mid": 0, "up": 0} }
pipe.set_adapters("pixel", adapter_weight_scales)
image = pipe(prompt, num_inference_steps=30, generator=torch.manual_seed(0)).images[0]
image
```

![block-lora-text-and-down](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/peft_integration/diffusers_peft_lora_inference_block_down.png)

Let's see how turning off the `down` part and turning on the `mid` and `up` part respectively changes the image.
```python
adapter_weight_scales = { "unet": { "down": 0, "mid": 1, "up": 0} }
pipe.set_adapters("pixel", adapter_weight_scales)
image = pipe(prompt, num_inference_steps=30, generator=torch.manual_seed(0)).images[0]
image
```

![block-lora-text-and-mid](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/peft_integration/diffusers_peft_lora_inference_block_mid.png)

```python
adapter_weight_scales = { "unet": { "down": 0, "mid": 0, "up": 1} }
pipe.set_adapters("pixel", adapter_weight_scales)
image = pipe(prompt, num_inference_steps=30, generator=torch.manual_seed(0)).images[0]
image
```

![block-lora-text-and-up](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/peft_integration/diffusers_peft_lora_inference_block_up.png)

Looks cool!

This is a really powerful feature. You can use it to control the adapter strengths down to per-transformer level. And you can even use it for multiple adapters.
```python
adapter_weight_scales_toy = 0.5
adapter_weight_scales_pixel = {
"unet": {
"down": 0.9, # all transformers in the down-part will use scale 0.9
# "mid" # because, in this example, "mid" is not given, all transformers in the mid part will use the default scale 1.0
"up": {
"block_0": 0.6, # all 3 transformers in the 0th block in the up-part will use scale 0.6
"block_1": [0.4, 0.8, 1.0], # the 3 transformers in the 1st block in the up-part will use scales 0.4, 0.8 and 1.0 respectively
}
}
}
pipe.set_adapters(["toy", "pixel"], [adapter_weight_scales_toy, adapter_weight_scales_pixel])
image = pipe(prompt, num_inference_steps=30, generator=torch.manual_seed(0)).images[0]
image
```

![block-lora-mixed](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/peft_integration/diffusers_peft_lora_inference_block_mixed.png)

## Manage active adapters

You have attached multiple adapters in this tutorial, and if you're feeling a bit lost on what adapters have been attached to the pipeline's components, use the [`~diffusers.loaders.LoraLoaderMixin.get_active_adapters`] method to check the list of active adapters:
Expand Down
Loading

0 comments on commit 3a94596

Please sign in to comment.