Unverified Commit 98730c5d authored by Tolga Cangöz's avatar Tolga Cangöz Committed by GitHub
Browse files

Errata (#8322)

* Fix typos

* Trim trailing whitespaces

* Remove a trailing whitespace

* chore: Update MarigoldDepthPipeline checkpoint to prs-eth/marigold-lcm-v1-0

* Revert "chore: Update MarigoldDepthPipeline checkpoint to prs-eth/marigold-lcm-v1-0"

This reverts commit fd742b30b4258106008a6af4d0dd4664904f8595.

* pokemon -> naruto

* `DPMSolverMultistep` -> `DPMSolverMultistepScheduler`

* Improve Markdown stylization

* Improve style

* Improve style

* Refactor pipeline variable names for consistency

* up style
parent 7ebd3594
...@@ -113,9 +113,9 @@ accelerate launch train_lcm_distill_lora_sdxl_wds.py \ ...@@ -113,9 +113,9 @@ accelerate launch train_lcm_distill_lora_sdxl_wds.py \
--push_to_hub \ --push_to_hub \
``` ```
We provide another version for LCM LoRA SDXL that follows best practices of `peft` and leverages the `datasets` library for quick experimentation. The script doesn't load two UNets unlike `train_lcm_distill_lora_sdxl_wds.py` which reduces the memory requirements quite a bit. We provide another version for LCM LoRA SDXL that follows best practices of `peft` and leverages the `datasets` library for quick experimentation. The script doesn't load two UNets unlike `train_lcm_distill_lora_sdxl_wds.py` which reduces the memory requirements quite a bit.
Below is an example training command that trains an LCM LoRA on the [Pokemons dataset](https://huggingface.co/datasets/lambdalabs/naruto-blip-captions): Below is an example training command that trains an LCM LoRA on the [Narutos dataset](https://huggingface.co/datasets/lambdalabs/naruto-blip-captions):
```bash ```bash
export MODEL_NAME="stabilityai/stable-diffusion-xl-base-1.0" export MODEL_NAME="stabilityai/stable-diffusion-xl-base-1.0"
...@@ -125,7 +125,7 @@ export VAE_PATH="madebyollin/sdxl-vae-fp16-fix" ...@@ -125,7 +125,7 @@ export VAE_PATH="madebyollin/sdxl-vae-fp16-fix"
accelerate launch train_lcm_distill_lora_sdxl.py \ accelerate launch train_lcm_distill_lora_sdxl.py \
--pretrained_teacher_model=${MODEL_NAME} \ --pretrained_teacher_model=${MODEL_NAME} \
--pretrained_vae_model_name_or_path=${VAE_PATH} \ --pretrained_vae_model_name_or_path=${VAE_PATH} \
--output_dir="pokemons-lora-lcm-sdxl" \ --output_dir="narutos-lora-lcm-sdxl" \
--mixed_precision="fp16" \ --mixed_precision="fp16" \
--dataset_name=$DATASET_NAME \ --dataset_name=$DATASET_NAME \
--resolution=1024 \ --resolution=1024 \
......
...@@ -101,7 +101,7 @@ accelerate launch train_controlnet.py \ ...@@ -101,7 +101,7 @@ accelerate launch train_controlnet.py \
`accelerate` allows for seamless multi-GPU training. Follow the instructions [here](https://huggingface.co/docs/accelerate/basic_tutorials/launch) `accelerate` allows for seamless multi-GPU training. Follow the instructions [here](https://huggingface.co/docs/accelerate/basic_tutorials/launch)
for running distributed training with `accelerate`. Here is an example command: for running distributed training with `accelerate`. Here is an example command:
```bash ```bash
export MODEL_DIR="runwayml/stable-diffusion-v1-5" export MODEL_DIR="runwayml/stable-diffusion-v1-5"
export OUTPUT_DIR="path to save model" export OUTPUT_DIR="path to save model"
...@@ -123,21 +123,21 @@ accelerate launch --mixed_precision="fp16" --multi_gpu train_controlnet.py \ ...@@ -123,21 +123,21 @@ accelerate launch --mixed_precision="fp16" --multi_gpu train_controlnet.py \
#### After 300 steps with batch size 8 #### After 300 steps with batch size 8
| | | | | |
|-------------------|:-------------------------:| |-------------------|:-------------------------:|
| | red circle with blue background | | | red circle with blue background |
![conditioning image](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/controlnet_training/conditioning_image_1.png) | ![red circle with blue background](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/controlnet_training/red_circle_with_blue_background_300_steps.png) | ![conditioning image](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/controlnet_training/conditioning_image_1.png) | ![red circle with blue background](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/controlnet_training/red_circle_with_blue_background_300_steps.png) |
| | cyan circle with brown floral background | | | cyan circle with brown floral background |
![conditioning image](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/controlnet_training/conditioning_image_2.png) | ![cyan circle with brown floral background](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/controlnet_training/cyan_circle_with_brown_floral_background_300_steps.png) | ![conditioning image](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/controlnet_training/conditioning_image_2.png) | ![cyan circle with brown floral background](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/controlnet_training/cyan_circle_with_brown_floral_background_300_steps.png) |
#### After 6000 steps with batch size 8: #### After 6000 steps with batch size 8:
| | | | | |
|-------------------|:-------------------------:| |-------------------|:-------------------------:|
| | red circle with blue background | | | red circle with blue background |
![conditioning image](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/controlnet_training/conditioning_image_1.png) | ![red circle with blue background](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/controlnet_training/red_circle_with_blue_background_6000_steps.png) | ![conditioning image](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/controlnet_training/conditioning_image_1.png) | ![red circle with blue background](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/controlnet_training/red_circle_with_blue_background_6000_steps.png) |
| | cyan circle with brown floral background | | | cyan circle with brown floral background |
![conditioning image](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/controlnet_training/conditioning_image_2.png) | ![cyan circle with brown floral background](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/controlnet_training/cyan_circle_with_brown_floral_background_6000_steps.png) | ![conditioning image](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/controlnet_training/conditioning_image_2.png) | ![cyan circle with brown floral background](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/controlnet_training/cyan_circle_with_brown_floral_background_6000_steps.png) |
## Training on a 16 GB GPU ## Training on a 16 GB GPU
...@@ -194,7 +194,7 @@ accelerate launch train_controlnet.py \ ...@@ -194,7 +194,7 @@ accelerate launch train_controlnet.py \
--set_grads_to_none --set_grads_to_none
``` ```
When using `enable_xformers_memory_efficient_attention`, please make sure to install `xformers` by `pip install xformers`. When using `enable_xformers_memory_efficient_attention`, please make sure to install `xformers` by `pip install xformers`.
## Training on an 8 GB GPU ## Training on an 8 GB GPU
...@@ -209,7 +209,7 @@ Optimizations: ...@@ -209,7 +209,7 @@ Optimizations:
- DeepSpeed stage 2 with parameter and optimizer offloading - DeepSpeed stage 2 with parameter and optimizer offloading
- fp16 mixed precision - fp16 mixed precision
[DeepSpeed](https://www.deepspeed.ai/) can offload tensors from VRAM to either [DeepSpeed](https://www.deepspeed.ai/) can offload tensors from VRAM to either
CPU or NVME. This requires significantly more RAM (about 25 GB). CPU or NVME. This requires significantly more RAM (about 25 GB).
Use `accelerate config` to enable DeepSpeed stage 2. Use `accelerate config` to enable DeepSpeed stage 2.
...@@ -256,7 +256,7 @@ accelerate launch train_controlnet.py \ ...@@ -256,7 +256,7 @@ accelerate launch train_controlnet.py \
## Performing inference with the trained ControlNet ## Performing inference with the trained ControlNet
The trained model can be run the same as the original ControlNet pipeline with the newly trained ControlNet. The trained model can be run the same as the original ControlNet pipeline with the newly trained ControlNet.
Set `base_model_path` and `controlnet_path` to the values `--pretrained_model_name_or_path` and Set `base_model_path` and `controlnet_path` to the values `--pretrained_model_name_or_path` and
`--output_dir` were respectively set to in the training script. `--output_dir` were respectively set to in the training script.
```py ```py
...@@ -315,13 +315,13 @@ gcloud alpha compute tpus tpu-vm ssh $VM_NAME --zone $ZONE -- \ ...@@ -315,13 +315,13 @@ gcloud alpha compute tpus tpu-vm ssh $VM_NAME --zone $ZONE -- \
When connected install JAX `0.4.5`: When connected install JAX `0.4.5`:
``` ```sh
pip install "jax[tpu]==0.4.5" -f https://storage.googleapis.com/jax-releases/libtpu_releases.html pip install "jax[tpu]==0.4.5" -f https://storage.googleapis.com/jax-releases/libtpu_releases.html
``` ```
To verify that JAX was correctly installed, you can run the following command: To verify that JAX was correctly installed, you can run the following command:
``` ```py
import jax import jax
jax.device_count() jax.device_count()
``` ```
...@@ -351,14 +351,14 @@ pip install wandb ...@@ -351,14 +351,14 @@ pip install wandb
Now let's downloading two conditioning images that we will use to run validation during the training in order to track our progress Now let's downloading two conditioning images that we will use to run validation during the training in order to track our progress
``` ```sh
wget https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/controlnet_training/conditioning_image_1.png wget https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/controlnet_training/conditioning_image_1.png
wget https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/controlnet_training/conditioning_image_2.png wget https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/controlnet_training/conditioning_image_2.png
``` ```
We encourage you to store or share your model with the community. To use huggingface hub, please login to your Hugging Face account, or ([create one](https://huggingface.co/docs/diffusers/main/en/training/hf.co/join) if you don’t have one already): We encourage you to store or share your model with the community. To use huggingface hub, please login to your Hugging Face account, or ([create one](https://huggingface.co/docs/diffusers/main/en/training/hf.co/join) if you don’t have one already):
``` ```sh
huggingface-cli login huggingface-cli login
``` ```
...@@ -429,12 +429,12 @@ When work with a larger dataset, you may need to run training process for a long ...@@ -429,12 +429,12 @@ When work with a larger dataset, you may need to run training process for a long
```bash ```bash
--checkpointing_steps=500 --checkpointing_steps=500
``` ```
This will save the trained model in subfolders of your output_dir. Subfolder names is the number of steps performed so far; for example: a checkpoint saved after 500 training steps would be saved in a subfolder named 500 This will save the trained model in subfolders of your output_dir. Subfolder names is the number of steps performed so far; for example: a checkpoint saved after 500 training steps would be saved in a subfolder named 500
You can then start your training from this saved checkpoint with You can then start your training from this saved checkpoint with
```bash ```bash
--controlnet_model_name_or_path="./control_out/500" --controlnet_model_name_or_path="./control_out/500"
``` ```
We support training with the Min-SNR weighting strategy proposed in [Efficient Diffusion Training via Min-SNR Weighting Strategy](https://arxiv.org/abs/2303.09556) which helps to achieve faster convergence by rebalancing the loss. To use it, one needs to set the `--snr_gamma` argument. The recommended value when using it is `5.0`. We support training with the Min-SNR weighting strategy proposed in [Efficient Diffusion Training via Min-SNR Weighting Strategy](https://arxiv.org/abs/2303.09556) which helps to achieve faster convergence by rebalancing the loss. To use it, one needs to set the `--snr_gamma` argument. The recommended value when using it is `5.0`.
......
...@@ -43,7 +43,7 @@ from accelerate.utils import write_basic_config ...@@ -43,7 +43,7 @@ from accelerate.utils import write_basic_config
write_basic_config() write_basic_config()
``` ```
When running `accelerate config`, if we specify torch compile mode to True there can be dramatic speedups. When running `accelerate config`, if we specify torch compile mode to True there can be dramatic speedups.
Note also that we use PEFT library as backend for LoRA training, make sure to have `peft>=0.6.0` installed in your environment. Note also that we use PEFT library as backend for LoRA training, make sure to have `peft>=0.6.0` installed in your environment.
### Dog toy example ### Dog toy example
...@@ -231,7 +231,7 @@ accelerate launch --mixed_precision="fp16" train_dreambooth.py \ ...@@ -231,7 +231,7 @@ accelerate launch --mixed_precision="fp16" train_dreambooth.py \
### Fine-tune text encoder with the UNet. ### Fine-tune text encoder with the UNet.
The script also allows to fine-tune the `text_encoder` along with the `unet`. It's been observed experimentally that fine-tuning `text_encoder` gives much better results especially on faces. The script also allows to fine-tune the `text_encoder` along with the `unet`. It's been observed experimentally that fine-tuning `text_encoder` gives much better results especially on faces.
Pass the `--train_text_encoder` argument to the script to enable training `text_encoder`. Pass the `--train_text_encoder` argument to the script to enable training `text_encoder`.
___Note: Training text encoder requires more memory, with this option the training won't fit on 16GB GPU. It needs at least 24GB VRAM.___ ___Note: Training text encoder requires more memory, with this option the training won't fit on 16GB GPU. It needs at least 24GB VRAM.___
...@@ -303,7 +303,7 @@ In a nutshell, LoRA allows to adapt pretrained models by adding pairs of rank-de ...@@ -303,7 +303,7 @@ In a nutshell, LoRA allows to adapt pretrained models by adding pairs of rank-de
- Rank-decomposition matrices have significantly fewer parameters than the original model, which means that trained LoRA weights are easily portable. - Rank-decomposition matrices have significantly fewer parameters than the original model, which means that trained LoRA weights are easily portable.
- LoRA attention layers allow to control to which extent the model is adapted towards new training images via a `scale` parameter. - LoRA attention layers allow to control to which extent the model is adapted towards new training images via a `scale` parameter.
[cloneofsimo](https://github.com/cloneofsimo) was the first to try out LoRA training for Stable Diffusion in [cloneofsimo](https://github.com/cloneofsimo) was the first to try out LoRA training for Stable Diffusion in
the popular [lora](https://github.com/cloneofsimo/lora) GitHub repository. the popular [lora](https://github.com/cloneofsimo/lora) GitHub repository.
### Training ### Training
...@@ -326,7 +326,7 @@ export INSTANCE_DIR="dog" ...@@ -326,7 +326,7 @@ export INSTANCE_DIR="dog"
export OUTPUT_DIR="path-to-save-model" export OUTPUT_DIR="path-to-save-model"
``` ```
For this example we want to directly store the trained LoRA embeddings on the Hub, so For this example we want to directly store the trained LoRA embeddings on the Hub, so
we need to be logged in and add the `--push_to_hub` flag. we need to be logged in and add the `--push_to_hub` flag.
```bash ```bash
...@@ -356,7 +356,7 @@ accelerate launch train_dreambooth_lora.py \ ...@@ -356,7 +356,7 @@ accelerate launch train_dreambooth_lora.py \
--push_to_hub --push_to_hub
``` ```
**___Note: When using LoRA we can use a much higher learning rate compared to vanilla dreambooth. Here we **___Note: When using LoRA we can use a much higher learning rate compared to vanilla dreambooth. Here we
use *1e-4* instead of the usual *2e-6*.___** use *1e-4* instead of the usual *2e-6*.___**
The final LoRA embedding weights have been uploaded to [patrickvonplaten/lora_dreambooth_dog_example](https://huggingface.co/patrickvonplaten/lora_dreambooth_dog_example). **___Note: [The final weights](https://huggingface.co/patrickvonplaten/lora/blob/main/pytorch_attn_procs.bin) are only 3 MB in size which is orders of magnitudes smaller than the original model.** The final LoRA embedding weights have been uploaded to [patrickvonplaten/lora_dreambooth_dog_example](https://huggingface.co/patrickvonplaten/lora_dreambooth_dog_example). **___Note: [The final weights](https://huggingface.co/patrickvonplaten/lora/blob/main/pytorch_attn_procs.bin) are only 3 MB in size which is orders of magnitudes smaller than the original model.**
...@@ -365,14 +365,14 @@ The training results are summarized [here](https://api.wandb.ai/report/patrickvo ...@@ -365,14 +365,14 @@ The training results are summarized [here](https://api.wandb.ai/report/patrickvo
You can use the `Step` slider to see how the model learned the features of our subject while the model trained. You can use the `Step` slider to see how the model learned the features of our subject while the model trained.
Optionally, we can also train additional LoRA layers for the text encoder. Specify the `--train_text_encoder` argument above for that. If you're interested to know more about how we Optionally, we can also train additional LoRA layers for the text encoder. Specify the `--train_text_encoder` argument above for that. If you're interested to know more about how we
enable this support, check out this [PR](https://github.com/huggingface/diffusers/pull/2918). enable this support, check out this [PR](https://github.com/huggingface/diffusers/pull/2918).
With the default hyperparameters from the above, the training seems to go in a positive direction. Check out [this panel](https://wandb.ai/sayakpaul/dreambooth-lora/reports/test-23-04-17-17-00-13---Vmlldzo0MDkwNjMy). The trained LoRA layers are available [here](https://huggingface.co/sayakpaul/dreambooth). With the default hyperparameters from the above, the training seems to go in a positive direction. Check out [this panel](https://wandb.ai/sayakpaul/dreambooth-lora/reports/test-23-04-17-17-00-13---Vmlldzo0MDkwNjMy). The trained LoRA layers are available [here](https://huggingface.co/sayakpaul/dreambooth).
### Inference ### Inference
After training, LoRA weights can be loaded very easily into the original pipeline. First, you need to After training, LoRA weights can be loaded very easily into the original pipeline. First, you need to
load the original pipeline: load the original pipeline:
```python ```python
...@@ -394,9 +394,9 @@ image = pipe("A picture of a sks dog in a bucket", num_inference_steps=25).image ...@@ -394,9 +394,9 @@ image = pipe("A picture of a sks dog in a bucket", num_inference_steps=25).image
If you are loading the LoRA parameters from the Hub and if the Hub repository has If you are loading the LoRA parameters from the Hub and if the Hub repository has
a `base_model` tag (such as [this](https://huggingface.co/patrickvonplaten/lora_dreambooth_dog_example/blob/main/README.md?code=true#L4)), then a `base_model` tag (such as [this](https://huggingface.co/patrickvonplaten/lora_dreambooth_dog_example/blob/main/README.md?code=true#L4)), then
you can do: you can do:
```py ```py
from huggingface_hub.repocard import RepoCard from huggingface_hub.repocard import RepoCard
lora_model_id = "patrickvonplaten/lora_dreambooth_dog_example" lora_model_id = "patrickvonplaten/lora_dreambooth_dog_example"
...@@ -413,7 +413,7 @@ weights. For example: ...@@ -413,7 +413,7 @@ weights. For example:
```python ```python
from huggingface_hub.repocard import RepoCard from huggingface_hub.repocard import RepoCard
from diffusers import StableDiffusionPipeline from diffusers import StableDiffusionPipeline
import torch import torch
lora_model_id = "sayakpaul/dreambooth-text-encoder-test" lora_model_id = "sayakpaul/dreambooth-text-encoder-test"
card = RepoCard.load(lora_model_id) card = RepoCard.load(lora_model_id)
...@@ -430,7 +430,7 @@ Note that the use of [`LoraLoaderMixin.load_lora_weights`](https://huggingface.c ...@@ -430,7 +430,7 @@ Note that the use of [`LoraLoaderMixin.load_lora_weights`](https://huggingface.c
* LoRA parameters that don't have separate identifiers for the UNet and the text encoder (such as [`"patrickvonplaten/lora_dreambooth_dog_example"`](https://huggingface.co/patrickvonplaten/lora_dreambooth_dog_example)). So, you can just do: * LoRA parameters that don't have separate identifiers for the UNet and the text encoder (such as [`"patrickvonplaten/lora_dreambooth_dog_example"`](https://huggingface.co/patrickvonplaten/lora_dreambooth_dog_example)). So, you can just do:
```py ```py
pipe.load_lora_weights(lora_model_path) pipe.load_lora_weights(lora_model_path)
``` ```
...@@ -529,11 +529,11 @@ To save even more memory, pass the `--set_grads_to_none` argument to the script. ...@@ -529,11 +529,11 @@ To save even more memory, pass the `--set_grads_to_none` argument to the script.
More info: https://pytorch.org/docs/stable/generated/torch.optim.Optimizer.zero_grad.html More info: https://pytorch.org/docs/stable/generated/torch.optim.Optimizer.zero_grad.html
### Experimental results ### Experimental results
You can refer to [this blog post](https://huggingface.co/blog/dreambooth) that discusses some of DreamBooth experiments in detail. Specifically, it recommends a set of DreamBooth-specific tips and tricks that we have found to work well for a variety of subjects. You can refer to [this blog post](https://huggingface.co/blog/dreambooth) that discusses some of DreamBooth experiments in detail. Specifically, it recommends a set of DreamBooth-specific tips and tricks that we have found to work well for a variety of subjects.
## IF ## IF
You can use the lora and full dreambooth scripts to train the text to image [IF model](https://huggingface.co/DeepFloyd/IF-I-XL-v1.0) and the stage II upscaler You can use the lora and full dreambooth scripts to train the text to image [IF model](https://huggingface.co/DeepFloyd/IF-I-XL-v1.0) and the stage II upscaler
[IF model](https://huggingface.co/DeepFloyd/IF-II-L-v1.0). [IF model](https://huggingface.co/DeepFloyd/IF-II-L-v1.0).
Note that IF has a predicted variance, and our finetuning scripts only train the models predicted error, so for finetuned IF models we switch to a fixed Note that IF has a predicted variance, and our finetuning scripts only train the models predicted error, so for finetuned IF models we switch to a fixed
...@@ -553,7 +553,7 @@ pipe.scheduler = pipe.scheduler.__class__.from_config(pipe.scheduler.config, var ...@@ -553,7 +553,7 @@ pipe.scheduler = pipe.scheduler.__class__.from_config(pipe.scheduler.config, var
Additionally, a few alternative cli flags are needed for IF. Additionally, a few alternative cli flags are needed for IF.
`--resolution=64`: IF is a pixel space diffusion model. In order to operate on un-compressed pixels, the input images are of a much smaller resolution. `--resolution=64`: IF is a pixel space diffusion model. In order to operate on un-compressed pixels, the input images are of a much smaller resolution.
`--pre_compute_text_embeddings`: IF uses [T5](https://huggingface.co/docs/transformers/model_doc/t5) for its text encoder. In order to save GPU memory, we pre compute all text embeddings and then de-allocate `--pre_compute_text_embeddings`: IF uses [T5](https://huggingface.co/docs/transformers/model_doc/t5) for its text encoder. In order to save GPU memory, we pre compute all text embeddings and then de-allocate
T5. T5.
...@@ -568,7 +568,7 @@ We find LoRA to be sufficient for finetuning the stage I model as the low resolu ...@@ -568,7 +568,7 @@ We find LoRA to be sufficient for finetuning the stage I model as the low resolu
For common and/or not-visually complex object concepts, you can get away with not-finetuning the upscaler. Just be sure to adjust the prompt passed to the For common and/or not-visually complex object concepts, you can get away with not-finetuning the upscaler. Just be sure to adjust the prompt passed to the
upscaler to remove the new token from the instance prompt. I.e. if your stage I prompt is "a sks dog", use "a dog" for your stage II prompt. upscaler to remove the new token from the instance prompt. I.e. if your stage I prompt is "a sks dog", use "a dog" for your stage II prompt.
For finegrained detail like faces that aren't present in the original training set, we find that full finetuning of the stage II upscaler is better than For finegrained detail like faces that aren't present in the original training set, we find that full finetuning of the stage II upscaler is better than
LoRA finetuning stage II. LoRA finetuning stage II.
For finegrained detail like faces, we find that lower learning rates along with larger batch sizes work best. For finegrained detail like faces, we find that lower learning rates along with larger batch sizes work best.
...@@ -647,7 +647,7 @@ python train_dreambooth_lora.py \ ...@@ -647,7 +647,7 @@ python train_dreambooth_lora.py \
--resolution=256 \ --resolution=256 \
--train_batch_size=4 \ --train_batch_size=4 \
--gradient_accumulation_steps=1 \ --gradient_accumulation_steps=1 \
--learning_rate=1e-6 \ --learning_rate=1e-6 \
--max_train_steps=2000 \ --max_train_steps=2000 \
--validation_prompt="a sks dog" \ --validation_prompt="a sks dog" \
--validation_epochs=100 \ --validation_epochs=100 \
...@@ -663,9 +663,9 @@ python train_dreambooth_lora.py \ ...@@ -663,9 +663,9 @@ python train_dreambooth_lora.py \
`--skip_save_text_encoder`: When training the full model, this will skip saving the entire T5 with the finetuned model. You can still load the pipeline `--skip_save_text_encoder`: When training the full model, this will skip saving the entire T5 with the finetuned model. You can still load the pipeline
with a T5 loaded from the original model. with a T5 loaded from the original model.
`use_8bit_adam`: Due to the size of the optimizer states, we recommend training the full XL IF model with 8bit adam. `use_8bit_adam`: Due to the size of the optimizer states, we recommend training the full XL IF model with 8bit adam.
`--learning_rate=1e-7`: For full dreambooth, IF requires very low learning rates. With higher learning rates model quality will degrade. Note that it is `--learning_rate=1e-7`: For full dreambooth, IF requires very low learning rates. With higher learning rates model quality will degrade. Note that it is
likely the learning rate can be increased with larger batch sizes. likely the learning rate can be increased with larger batch sizes.
Using 8bit adam and a batch size of 4, the model can be trained in ~48 GB VRAM. Using 8bit adam and a batch size of 4, the model can be trained in ~48 GB VRAM.
...@@ -741,4 +741,4 @@ accelerate launch train_dreambooth.py \ ...@@ -741,4 +741,4 @@ accelerate launch train_dreambooth.py \
## Stable Diffusion XL ## Stable Diffusion XL
We support fine-tuning of the UNet shipped in [Stable Diffusion XL](https://huggingface.co/papers/2307.01952) with DreamBooth and LoRA via the `train_dreambooth_lora_sdxl.py` script. Please refer to the docs [here](./README_sdxl.md). We support fine-tuning of the UNet shipped in [Stable Diffusion XL](https://huggingface.co/papers/2307.01952) with DreamBooth and LoRA via the `train_dreambooth_lora_sdxl.py` script. Please refer to the docs [here](./README_sdxl.md).
...@@ -34,7 +34,7 @@ For this example we want to directly store the trained LoRA embeddings on the Hu ...@@ -34,7 +34,7 @@ For this example we want to directly store the trained LoRA embeddings on the Hu
___ ___
### Pokemon example ### Naruto example
For all our examples, we will directly store the trained weights on the Hub, so we need to be logged in and add the `--push_to_hub` flag. In order to do that, you have to be a registered user on the 🤗 Hugging Face Hub, and you'll also need to use an access token for the code to work. For more information on access tokens, please refer to the [User Access Tokens](https://huggingface.co/docs/hub/security-tokens) guide. For all our examples, we will directly store the trained weights on the Hub, so we need to be logged in and add the `--push_to_hub` flag. In order to do that, you have to be a registered user on the 🤗 Hugging Face Hub, and you'll also need to use an access token for the code to work. For more information on access tokens, please refer to the [User Access Tokens](https://huggingface.co/docs/hub/security-tokens) guide.
...@@ -44,13 +44,13 @@ Run the following command to authenticate your token ...@@ -44,13 +44,13 @@ Run the following command to authenticate your token
huggingface-cli login huggingface-cli login
``` ```
We also use [Weights and Biases](https://docs.wandb.ai/quickstart) logging by default, because it is really useful to monitor the training progress by regularly generating sample images during training. To install wandb, run We also use [Weights and Biases](https://docs.wandb.ai/quickstart) logging by default, because it is really useful to monitor the training progress by regularly generating sample images during training. To install wandb, run
```bash ```bash
pip install wandb pip install wandb
``` ```
To disable wandb logging, remove the `--report_to=="wandb"` and `--validation_prompts="A robot pokemon, 4k photo"` flags from below examples To disable wandb logging, remove the `--report_to=="wandb"` and `--validation_prompts="A robot naruto, 4k photo"` flags from below examples
#### Fine-tune decoder #### Fine-tune decoder
<br> <br>
...@@ -70,10 +70,10 @@ accelerate launch --mixed_precision="fp16" train_text_to_image_decoder.py \ ...@@ -70,10 +70,10 @@ accelerate launch --mixed_precision="fp16" train_text_to_image_decoder.py \
--max_grad_norm=1 \ --max_grad_norm=1 \
--checkpoints_total_limit=3 \ --checkpoints_total_limit=3 \
--lr_scheduler="constant" --lr_warmup_steps=0 \ --lr_scheduler="constant" --lr_warmup_steps=0 \
--validation_prompts="A robot pokemon, 4k photo" \ --validation_prompts="A robot naruto, 4k photo" \
--report_to="wandb" \ --report_to="wandb" \
--push_to_hub \ --push_to_hub \
--output_dir="kandi2-decoder-pokemon-model" --output_dir="kandi2-decoder-naruto-model"
``` ```
<!-- accelerate_snippet_end --> <!-- accelerate_snippet_end -->
...@@ -95,14 +95,14 @@ accelerate launch --mixed_precision="fp16" train_text_to_image_decoder.py \ ...@@ -95,14 +95,14 @@ accelerate launch --mixed_precision="fp16" train_text_to_image_decoder.py \
--max_grad_norm=1 \ --max_grad_norm=1 \
--checkpoints_total_limit=3 \ --checkpoints_total_limit=3 \
--lr_scheduler="constant" --lr_warmup_steps=0 \ --lr_scheduler="constant" --lr_warmup_steps=0 \
--validation_prompts="A robot pokemon, 4k photo" \ --validation_prompts="A robot naruto, 4k photo" \
--report_to="wandb" \ --report_to="wandb" \
--push_to_hub \ --push_to_hub \
--output_dir="kandi22-decoder-pokemon-model" --output_dir="kandi22-decoder-naruto-model"
``` ```
Once the training is finished the model will be saved in the `output_dir` specified in the command. In this example it's `kandi22-decoder-pokemon-model`. To load the fine-tuned model for inference just pass that path to `AutoPipelineForText2Image` Once the training is finished the model will be saved in the `output_dir` specified in the command. In this example it's `kandi22-decoder-naruto-model`. To load the fine-tuned model for inference just pass that path to `AutoPipelineForText2Image`
```python ```python
from diffusers import AutoPipelineForText2Image from diffusers import AutoPipelineForText2Image
...@@ -111,9 +111,9 @@ import torch ...@@ -111,9 +111,9 @@ import torch
pipe = AutoPipelineForText2Image.from_pretrained(output_dir, torch_dtype=torch.float16) pipe = AutoPipelineForText2Image.from_pretrained(output_dir, torch_dtype=torch.float16)
pipe.enable_model_cpu_offload() pipe.enable_model_cpu_offload()
prompt='A robot pokemon, 4k photo' prompt='A robot naruto, 4k photo'
images = pipe(prompt=prompt).images images = pipe(prompt=prompt).images
images[0].save("robot-pokemon.png") images[0].save("robot-naruto.png")
``` ```
Checkpoints only save the unet, so to run inference from a checkpoint, just load the unet Checkpoints only save the unet, so to run inference from a checkpoint, just load the unet
...@@ -127,11 +127,11 @@ unet = UNet2DConditionModel.from_pretrained(model_path + "/checkpoint-<N>/unet") ...@@ -127,11 +127,11 @@ unet = UNet2DConditionModel.from_pretrained(model_path + "/checkpoint-<N>/unet")
pipe = AutoPipelineForText2Image.from_pretrained("kandinsky-community/kandinsky-2-2-decoder", unet=unet, torch_dtype=torch.float16) pipe = AutoPipelineForText2Image.from_pretrained("kandinsky-community/kandinsky-2-2-decoder", unet=unet, torch_dtype=torch.float16)
pipe.enable_model_cpu_offload() pipe.enable_model_cpu_offload()
image = pipe(prompt="A robot pokemon, 4k photo").images[0] image = pipe(prompt="A robot naruto, 4k photo").images[0]
image.save("robot-pokemon.png") image.save("robot-naruto.png")
``` ```
#### Fine-tune prior #### Fine-tune prior
You can fine-tune the Kandinsky prior model with `train_text_to_image_prior.py` script. Note that we currently do not support `--gradient_checkpointing` for prior model fine-tuning. You can fine-tune the Kandinsky prior model with `train_text_to_image_prior.py` script. Note that we currently do not support `--gradient_checkpointing` for prior model fine-tuning.
...@@ -151,15 +151,15 @@ accelerate launch --mixed_precision="fp16" train_text_to_image_prior.py \ ...@@ -151,15 +151,15 @@ accelerate launch --mixed_precision="fp16" train_text_to_image_prior.py \
--max_grad_norm=1 \ --max_grad_norm=1 \
--checkpoints_total_limit=3 \ --checkpoints_total_limit=3 \
--lr_scheduler="constant" --lr_warmup_steps=0 \ --lr_scheduler="constant" --lr_warmup_steps=0 \
--validation_prompts="A robot pokemon, 4k photo" \ --validation_prompts="A robot naruto, 4k photo" \
--report_to="wandb" \ --report_to="wandb" \
--push_to_hub \ --push_to_hub \
--output_dir="kandi2-prior-pokemon-model" --output_dir="kandi2-prior-naruto-model"
``` ```
<!-- accelerate_snippet_end --> <!-- accelerate_snippet_end -->
To perform inference with the fine-tuned prior model, you will need to first create a prior pipeline by passing the `output_dir` to `DiffusionPipeline`. Then create a `KandinskyV22CombinedPipeline` from a pretrained or fine-tuned decoder checkpoint along with all the modules of the prior pipeline you just created. To perform inference with the fine-tuned prior model, you will need to first create a prior pipeline by passing the `output_dir` to `DiffusionPipeline`. Then create a `KandinskyV22CombinedPipeline` from a pretrained or fine-tuned decoder checkpoint along with all the modules of the prior pipeline you just created.
```python ```python
from diffusers import AutoPipelineForText2Image, DiffusionPipeline from diffusers import AutoPipelineForText2Image, DiffusionPipeline
...@@ -170,12 +170,12 @@ prior_components = {"prior_" + k: v for k,v in pipe_prior.components.items()} ...@@ -170,12 +170,12 @@ prior_components = {"prior_" + k: v for k,v in pipe_prior.components.items()}
pipe = AutoPipelineForText2Image.from_pretrained("kandinsky-community/kandinsky-2-2-decoder", **prior_components, torch_dtype=torch.float16) pipe = AutoPipelineForText2Image.from_pretrained("kandinsky-community/kandinsky-2-2-decoder", **prior_components, torch_dtype=torch.float16)
pipe.enable_model_cpu_offload() pipe.enable_model_cpu_offload()
prompt='A robot pokemon, 4k photo' prompt='A robot naruto, 4k photo'
images = pipe(prompt=prompt, negative_prompt=negative_prompt).images images = pipe(prompt=prompt, negative_prompt=negative_prompt).images
images[0] images[0]
``` ```
If you want to use a fine-tuned decoder checkpoint along with your fine-tuned prior checkpoint, you can simply replace the "kandinsky-community/kandinsky-2-2-decoder" in above code with your custom model repo name. Note that in order to be able to create a `KandinskyV22CombinedPipeline`, your model repository need to have a prior tag. If you have created your model repo using our training script, the prior tag is automatically included. If you want to use a fine-tuned decoder checkpoint along with your fine-tuned prior checkpoint, you can simply replace the "kandinsky-community/kandinsky-2-2-decoder" in above code with your custom model repo name. Note that in order to be able to create a `KandinskyV22CombinedPipeline`, your model repository need to have a prior tag. If you have created your model repo using our training script, the prior tag is automatically included.
#### Training with multiple GPUs #### Training with multiple GPUs
...@@ -196,10 +196,10 @@ accelerate launch --mixed_precision="fp16" --multi_gpu train_text_to_image_deco ...@@ -196,10 +196,10 @@ accelerate launch --mixed_precision="fp16" --multi_gpu train_text_to_image_deco
--max_grad_norm=1 \ --max_grad_norm=1 \
--checkpoints_total_limit=3 \ --checkpoints_total_limit=3 \
--lr_scheduler="constant" --lr_warmup_steps=0 \ --lr_scheduler="constant" --lr_warmup_steps=0 \
--validation_prompts="A robot pokemon, 4k photo" \ --validation_prompts="A robot naruto, 4k photo" \
--report_to="wandb" \ --report_to="wandb" \
--push_to_hub \ --push_to_hub \
--output_dir="kandi2-decoder-pokemon-model" --output_dir="kandi2-decoder-naruto-model"
``` ```
...@@ -227,10 +227,10 @@ on consumer GPUs like Tesla T4, Tesla V100. ...@@ -227,10 +227,10 @@ on consumer GPUs like Tesla T4, Tesla V100.
### Training ### Training
First, you need to set up your development environment as explained in the [installation](#installing-the-dependencies). Make sure to set the `MODEL_NAME` and `DATASET_NAME` environment variables. Here, we will use [Kandinsky 2.2](https://huggingface.co/kandinsky-community/kandinsky-2-2-decoder) and the [Pokemons dataset](https://huggingface.co/datasets/lambdalabs/naruto-blip-captions). First, you need to set up your development environment as explained in the [installation](#installing-the-dependencies). Make sure to set the `MODEL_NAME` and `DATASET_NAME` environment variables. Here, we will use [Kandinsky 2.2](https://huggingface.co/kandinsky-community/kandinsky-2-2-decoder) and the [Narutos dataset](https://huggingface.co/datasets/lambdalabs/naruto-blip-captions).
#### Train decoder #### Train decoder
```bash ```bash
export DATASET_NAME="lambdalabs/naruto-blip-captions" export DATASET_NAME="lambdalabs/naruto-blip-captions"
...@@ -244,7 +244,7 @@ accelerate launch --mixed_precision="fp16" train_text_to_image_decoder_lora.py \ ...@@ -244,7 +244,7 @@ accelerate launch --mixed_precision="fp16" train_text_to_image_decoder_lora.py \
--seed=42 \ --seed=42 \
--rank=4 \ --rank=4 \
--gradient_checkpointing \ --gradient_checkpointing \
--output_dir="kandi22-decoder-pokemon-lora" \ --output_dir="kandi22-decoder-naruto-lora" \
--validation_prompt="cute dragon creature" --report_to="wandb" \ --validation_prompt="cute dragon creature" --report_to="wandb" \
--push_to_hub \ --push_to_hub \
``` ```
...@@ -262,7 +262,7 @@ accelerate launch --mixed_precision="fp16" train_text_to_image_prior_lora.py \ ...@@ -262,7 +262,7 @@ accelerate launch --mixed_precision="fp16" train_text_to_image_prior_lora.py \
--learning_rate=1e-04 --lr_scheduler="constant" --lr_warmup_steps=0 \ --learning_rate=1e-04 --lr_scheduler="constant" --lr_warmup_steps=0 \
--seed=42 \ --seed=42 \
--rank=4 \ --rank=4 \
--output_dir="kandi22-prior-pokemon-lora" \ --output_dir="kandi22-prior-naruto-lora" \
--validation_prompt="cute dragon creature" --report_to="wandb" \ --validation_prompt="cute dragon creature" --report_to="wandb" \
--push_to_hub \ --push_to_hub \
``` ```
...@@ -274,7 +274,7 @@ accelerate launch --mixed_precision="fp16" train_text_to_image_prior_lora.py \ ...@@ -274,7 +274,7 @@ accelerate launch --mixed_precision="fp16" train_text_to_image_prior_lora.py \
#### Inference using fine-tuned LoRA checkpoint for decoder #### Inference using fine-tuned LoRA checkpoint for decoder
Once you have trained a Kandinsky decoder model using the above command, inference can be done with the `AutoPipelineForText2Image` after loading the trained LoRA weights. You need to pass the `output_dir` for loading the LoRA weights, which in this case is `kandi22-decoder-pokemon-lora`. Once you have trained a Kandinsky decoder model using the above command, inference can be done with the `AutoPipelineForText2Image` after loading the trained LoRA weights. You need to pass the `output_dir` for loading the LoRA weights, which in this case is `kandi22-decoder-naruto-lora`.
```python ```python
...@@ -285,9 +285,9 @@ pipe = AutoPipelineForText2Image.from_pretrained("kandinsky-community/kandinsky- ...@@ -285,9 +285,9 @@ pipe = AutoPipelineForText2Image.from_pretrained("kandinsky-community/kandinsky-
pipe.unet.load_attn_procs(output_dir) pipe.unet.load_attn_procs(output_dir)
pipe.enable_model_cpu_offload() pipe.enable_model_cpu_offload()
prompt='A robot pokemon, 4k photo' prompt='A robot naruto, 4k photo'
image = pipe(prompt=prompt).images[0] image = pipe(prompt=prompt).images[0]
image.save("robot_pokemon.png") image.save("robot_naruto.png")
``` ```
#### Inference using fine-tuned LoRA checkpoint for prior #### Inference using fine-tuned LoRA checkpoint for prior
...@@ -300,9 +300,9 @@ pipe = AutoPipelineForText2Image.from_pretrained("kandinsky-community/kandinsky- ...@@ -300,9 +300,9 @@ pipe = AutoPipelineForText2Image.from_pretrained("kandinsky-community/kandinsky-
pipe.prior_prior.load_attn_procs(output_dir) pipe.prior_prior.load_attn_procs(output_dir)
pipe.enable_model_cpu_offload() pipe.enable_model_cpu_offload()
prompt='A robot pokemon, 4k photo' prompt='A robot naruto, 4k photo'
image = pipe(prompt=prompt).images[0] image = pipe(prompt=prompt).images[0]
image.save("robot_pokemon.png") image.save("robot_naruto.png")
image image
``` ```
......
# Overview # Overview
These examples show how to run [Diffuser](https://arxiv.org/abs/2205.09991) in Diffusers. These examples show how to run [Diffuser](https://arxiv.org/abs/2205.09991) in Diffusers.
There are two ways to use the script, `run_diffuser_locomotion.py`. There are two ways to use the script, `run_diffuser_locomotion.py`.
The key option is a change of the variable `n_guide_steps`. The key option is a change of the variable `n_guide_steps`.
When `n_guide_steps=0`, the trajectories are sampled from the diffusion model, but not fine-tuned to maximize reward in the environment. When `n_guide_steps=0`, the trajectories are sampled from the diffusion model, but not fine-tuned to maximize reward in the environment.
By default, `n_guide_steps=2` to match the original implementation. By default, `n_guide_steps=2` to match the original implementation.
You will need some RL specific requirements to run the examples: You will need some RL specific requirements to run the examples:
``` ```sh
pip install -f https://download.pytorch.org/whl/torch_stable.html \ pip install -f https://download.pytorch.org/whl/torch_stable.html \
free-mujoco-py \ free-mujoco-py \
einops \ einops \
......
...@@ -6,7 +6,7 @@ Updating them to the most recent version of the library will require some work. ...@@ -6,7 +6,7 @@ Updating them to the most recent version of the library will require some work.
To use any of them, just run the command To use any of them, just run the command
``` ```sh
pip install -r requirements.txt pip install -r requirements.txt
``` ```
inside the folder of your choice. inside the folder of your choice.
......
...@@ -19,7 +19,7 @@ on consumer GPUs like Tesla T4, Tesla V100. ...@@ -19,7 +19,7 @@ on consumer GPUs like Tesla T4, Tesla V100.
### Training ### Training
First, you need to set up your development environment as is explained in the [installation section](#installing-the-dependencies). Make sure to set the `MODEL_NAME` and `DATASET_NAME` environment variables. Here, we will use [Stable Diffusion v1-4](https://hf.co/CompVis/stable-diffusion-v1-4) and the [Pokemons dataset](https://huggingface.co/datasets/lambdalabs/naruto-blip-captions). First, you need to set up your development environment as is explained in the [installation section](#installing-the-dependencies). Make sure to set the `MODEL_NAME` and `DATASET_NAME` environment variables. Here, we will use [Stable Diffusion v1-4](https://hf.co/CompVis/stable-diffusion-v1-4) and the [Narutos dataset](https://huggingface.co/datasets/lambdalabs/naruto-blip-captions).
**___Note: Change the `resolution` to 768 if you are using the [stable-diffusion-2](https://huggingface.co/stabilityai/stable-diffusion-2) 768x768 model.___** **___Note: Change the `resolution` to 768 if you are using the [stable-diffusion-2](https://huggingface.co/stabilityai/stable-diffusion-2) 768x768 model.___**
...@@ -30,7 +30,7 @@ export MODEL_NAME="CompVis/stable-diffusion-v1-4" ...@@ -30,7 +30,7 @@ export MODEL_NAME="CompVis/stable-diffusion-v1-4"
export DATASET_NAME="lambdalabs/naruto-blip-captions" export DATASET_NAME="lambdalabs/naruto-blip-captions"
``` ```
For this example we want to directly store the trained LoRA embeddings on the Hub, so For this example we want to directly store the trained LoRA embeddings on the Hub, so
we need to be logged in and add the `--push_to_hub` flag. we need to be logged in and add the `--push_to_hub` flag.
```bash ```bash
...@@ -48,7 +48,7 @@ accelerate launch --mixed_precision="fp16" train_text_to_image_lora.py \ ...@@ -48,7 +48,7 @@ accelerate launch --mixed_precision="fp16" train_text_to_image_lora.py \
--num_train_epochs=100 --checkpointing_steps=5000 \ --num_train_epochs=100 --checkpointing_steps=5000 \
--learning_rate=1e-04 --lr_scheduler="constant" --lr_warmup_steps=0 \ --learning_rate=1e-04 --lr_scheduler="constant" --lr_warmup_steps=0 \
--seed=42 \ --seed=42 \
--output_dir="sd-pokemon-model-lora" \ --output_dir="sd-naruto-model-lora" \
--validation_prompt="cute dragon creature" --report_to="wandb" --validation_prompt="cute dragon creature" --report_to="wandb"
--use_peft \ --use_peft \
--lora_r=4 --lora_alpha=32 \ --lora_r=4 --lora_alpha=32 \
...@@ -61,12 +61,12 @@ The above command will also run inference as fine-tuning progresses and log the ...@@ -61,12 +61,12 @@ The above command will also run inference as fine-tuning progresses and log the
The final LoRA embedding weights have been uploaded to [sayakpaul/sd-model-finetuned-lora-t4](https://huggingface.co/sayakpaul/sd-model-finetuned-lora-t4). **___Note: [The final weights](https://huggingface.co/sayakpaul/sd-model-finetuned-lora-t4/blob/main/pytorch_lora_weights.bin) are only 3 MB in size, which is orders of magnitudes smaller than the original model.___** The final LoRA embedding weights have been uploaded to [sayakpaul/sd-model-finetuned-lora-t4](https://huggingface.co/sayakpaul/sd-model-finetuned-lora-t4). **___Note: [The final weights](https://huggingface.co/sayakpaul/sd-model-finetuned-lora-t4/blob/main/pytorch_lora_weights.bin) are only 3 MB in size, which is orders of magnitudes smaller than the original model.___**
You can check some inference samples that were logged during the course of the fine-tuning process [here](https://wandb.ai/sayakpaul/text2image-fine-tune/runs/q4lc0xsw). You can check some inference samples that were logged during the course of the fine-tuning process [here](https://wandb.ai/sayakpaul/text2image-fine-tune/runs/q4lc0xsw).
### Inference ### Inference
Once you have trained a model using above command, the inference can be done simply using the `StableDiffusionPipeline` after loading the trained LoRA weights. You Once you have trained a model using above command, the inference can be done simply using the `StableDiffusionPipeline` after loading the trained LoRA weights. You
need to pass the `output_dir` for loading the LoRA weights which, in this case, is `sd-pokemon-model-lora`. need to pass the `output_dir` for loading the LoRA weights which, in this case, is `sd-naruto-model-lora`.
```python ```python
from diffusers import StableDiffusionPipeline from diffusers import StableDiffusionPipeline
...@@ -77,7 +77,7 @@ pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", ...@@ -77,7 +77,7 @@ pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4",
pipe.unet.load_attn_procs(model_path) pipe.unet.load_attn_procs(model_path)
pipe.to("cuda") pipe.to("cuda")
prompt = "A pokemon with green eyes and red legs." prompt = "A naruto with green eyes and red legs."
image = pipe(prompt, num_inference_steps=30, guidance_scale=7.5).images[0] image = pipe(prompt, num_inference_steps=30, guidance_scale=7.5).images[0]
image.save("pokemon.png") image.save("naruto.png")
``` ```
\ No newline at end of file
...@@ -32,7 +32,7 @@ And initialize an [🤗Accelerate](https://github.com/huggingface/accelerate/) e ...@@ -32,7 +32,7 @@ And initialize an [🤗Accelerate](https://github.com/huggingface/accelerate/) e
accelerate config accelerate config
``` ```
### Pokemon example ### Naruto example
You need to accept the model license before downloading or using the weights. In this example we'll use model version `v1-4`, so you'll need to visit [its card](https://huggingface.co/CompVis/stable-diffusion-v1-4), read the license and tick the checkbox if you agree. You need to accept the model license before downloading or using the weights. In this example we'll use model version `v1-4`, so you'll need to visit [its card](https://huggingface.co/CompVis/stable-diffusion-v1-4), read the license and tick the checkbox if you agree.
...@@ -51,7 +51,7 @@ If you have already cloned the repo, then you won't need to go through these ste ...@@ -51,7 +51,7 @@ If you have already cloned the repo, then you won't need to go through these ste
## Use ONNXRuntime to accelerate training ## Use ONNXRuntime to accelerate training
In order to leverage onnxruntime to accelerate training, please use train_text_to_image.py In order to leverage onnxruntime to accelerate training, please use train_text_to_image.py
The command to train a DDPM UNetCondition model on the Pokemon dataset with onnxruntime: The command to train a DDPM UNetCondition model on the Naruto dataset with onnxruntime:
```bash ```bash
export MODEL_NAME="CompVis/stable-diffusion-v1-4" export MODEL_NAME="CompVis/stable-diffusion-v1-4"
...@@ -68,7 +68,7 @@ accelerate launch --mixed_precision="fp16" train_text_to_image.py \ ...@@ -68,7 +68,7 @@ accelerate launch --mixed_precision="fp16" train_text_to_image.py \
--learning_rate=1e-05 \ --learning_rate=1e-05 \
--max_grad_norm=1 \ --max_grad_norm=1 \
--lr_scheduler="constant" --lr_warmup_steps=0 \ --lr_scheduler="constant" --lr_warmup_steps=0 \
--output_dir="sd-pokemon-model" --output_dir="sd-naruto-model"
``` ```
Please contact Prathik Rao (prathikr), Sunghoon Choi (hanbitmyths), Ashwini Khade (askhade), or Peng Wang (pengwa) on github with any questions. Please contact Prathik Rao (prathikr), Sunghoon Choi (hanbitmyths), Ashwini Khade (askhade), or Peng Wang (pengwa) on github with any questions.
\ No newline at end of file
...@@ -18,13 +18,13 @@ ...@@ -18,13 +18,13 @@
Upon having access to a TPU VM (TPUs higher than version 3), you should first install Upon having access to a TPU VM (TPUs higher than version 3), you should first install
a TPU-compatible version of JAX: a TPU-compatible version of JAX:
``` ```sh
pip install jax[tpu] -f https://storage.googleapis.com/jax-releases/libtpu_releases.html pip install jax[tpu] -f https://storage.googleapis.com/jax-releases/libtpu_releases.html
``` ```
Next, we can install [flax](https://github.com/google/flax) and the diffusers library: Next, we can install [flax](https://github.com/google/flax) and the diffusers library:
``` ```sh
pip install flax diffusers transformers pip install flax diffusers transformers
``` ```
......
...@@ -34,7 +34,7 @@ accelerate config ...@@ -34,7 +34,7 @@ accelerate config
Note also that we use PEFT library as backend for LoRA training, make sure to have `peft>=0.6.0` installed in your environment. Note also that we use PEFT library as backend for LoRA training, make sure to have `peft>=0.6.0` installed in your environment.
### Pokemon example ### Naruto example
You need to accept the model license before downloading or using the weights. In this example we'll use model version `v1-4`, so you'll need to visit [its card](https://huggingface.co/CompVis/stable-diffusion-v1-4), read the license and tick the checkbox if you agree. You need to accept the model license before downloading or using the weights. In this example we'll use model version `v1-4`, so you'll need to visit [its card](https://huggingface.co/CompVis/stable-diffusion-v1-4), read the license and tick the checkbox if you agree.
...@@ -71,7 +71,7 @@ accelerate launch --mixed_precision="fp16" train_text_to_image.py \ ...@@ -71,7 +71,7 @@ accelerate launch --mixed_precision="fp16" train_text_to_image.py \
--learning_rate=1e-05 \ --learning_rate=1e-05 \
--max_grad_norm=1 \ --max_grad_norm=1 \
--lr_scheduler="constant" --lr_warmup_steps=0 \ --lr_scheduler="constant" --lr_warmup_steps=0 \
--output_dir="sd-pokemon-model" --output_dir="sd-naruto-model"
``` ```
<!-- accelerate_snippet_end --> <!-- accelerate_snippet_end -->
...@@ -95,11 +95,11 @@ accelerate launch --mixed_precision="fp16" train_text_to_image.py \ ...@@ -95,11 +95,11 @@ accelerate launch --mixed_precision="fp16" train_text_to_image.py \
--learning_rate=1e-05 \ --learning_rate=1e-05 \
--max_grad_norm=1 \ --max_grad_norm=1 \
--lr_scheduler="constant" --lr_warmup_steps=0 \ --lr_scheduler="constant" --lr_warmup_steps=0 \
--output_dir="sd-pokemon-model" --output_dir="sd-naruto-model"
``` ```
Once the training is finished the model will be saved in the `output_dir` specified in the command. In this example it's `sd-pokemon-model`. To load the fine-tuned model for inference just pass that path to `StableDiffusionPipeline` Once the training is finished the model will be saved in the `output_dir` specified in the command. In this example it's `sd-naruto-model`. To load the fine-tuned model for inference just pass that path to `StableDiffusionPipeline`
```python ```python
import torch import torch
...@@ -110,7 +110,7 @@ pipe = StableDiffusionPipeline.from_pretrained(model_path, torch_dtype=torch.flo ...@@ -110,7 +110,7 @@ pipe = StableDiffusionPipeline.from_pretrained(model_path, torch_dtype=torch.flo
pipe.to("cuda") pipe.to("cuda")
image = pipe(prompt="yoda").images[0] image = pipe(prompt="yoda").images[0]
image.save("yoda-pokemon.png") image.save("yoda-naruto.png")
``` ```
Checkpoints only save the unet, so to run inference from a checkpoint, just load the unet Checkpoints only save the unet, so to run inference from a checkpoint, just load the unet
...@@ -126,7 +126,7 @@ pipe = StableDiffusionPipeline.from_pretrained("<initial model>", unet=unet, tor ...@@ -126,7 +126,7 @@ pipe = StableDiffusionPipeline.from_pretrained("<initial model>", unet=unet, tor
pipe.to("cuda") pipe.to("cuda")
image = pipe(prompt="yoda").images[0] image = pipe(prompt="yoda").images[0]
image.save("yoda-pokemon.png") image.save("yoda-naruto.png")
``` ```
#### Training with multiple GPUs #### Training with multiple GPUs
...@@ -150,7 +150,7 @@ accelerate launch --mixed_precision="fp16" --multi_gpu train_text_to_image.py \ ...@@ -150,7 +150,7 @@ accelerate launch --mixed_precision="fp16" --multi_gpu train_text_to_image.py \
--learning_rate=1e-05 \ --learning_rate=1e-05 \
--max_grad_norm=1 \ --max_grad_norm=1 \
--lr_scheduler="constant" --lr_warmup_steps=0 \ --lr_scheduler="constant" --lr_warmup_steps=0 \
--output_dir="sd-pokemon-model" --output_dir="sd-naruto-model"
``` ```
...@@ -166,7 +166,7 @@ You can find [this project on Weights and Biases](https://wandb.ai/sayakpaul/tex ...@@ -166,7 +166,7 @@ You can find [this project on Weights and Biases](https://wandb.ai/sayakpaul/tex
* Training with the Min-SNR weighting strategy (`snr_gamma` set to 5.0) * Training with the Min-SNR weighting strategy (`snr_gamma` set to 5.0)
* Training with the Min-SNR weighting strategy (`snr_gamma` set to 1.0) * Training with the Min-SNR weighting strategy (`snr_gamma` set to 1.0)
For our small Pokemons dataset, the effects of Min-SNR weighting strategy might not appear to be pronounced, but for larger datasets, we believe the effects will be more pronounced. For our small Narutos dataset, the effects of Min-SNR weighting strategy might not appear to be pronounced, but for larger datasets, we believe the effects will be more pronounced.
Also, note that in this example, we either predict `epsilon` (i.e., the noise) or the `v_prediction`. For both of these cases, the formulation of the Min-SNR weighting strategy that we have used holds. Also, note that in this example, we either predict `epsilon` (i.e., the noise) or the `v_prediction`. For both of these cases, the formulation of the Min-SNR weighting strategy that we have used holds.
...@@ -192,7 +192,7 @@ on consumer GPUs like Tesla T4, Tesla V100. ...@@ -192,7 +192,7 @@ on consumer GPUs like Tesla T4, Tesla V100.
### Training ### Training
First, you need to set up your development environment as is explained in the [installation section](#installing-the-dependencies). Make sure to set the `MODEL_NAME` and `DATASET_NAME` environment variables. Here, we will use [Stable Diffusion v1-4](https://hf.co/CompVis/stable-diffusion-v1-4) and the [Pokemons dataset](https://huggingface.co/datasets/lambdalabs/naruto-blip-captions). First, you need to set up your development environment as is explained in the [installation section](#installing-the-dependencies). Make sure to set the `MODEL_NAME` and `DATASET_NAME` environment variables. Here, we will use [Stable Diffusion v1-4](https://hf.co/CompVis/stable-diffusion-v1-4) and the [Narutos dataset](https://huggingface.co/datasets/lambdalabs/naruto-blip-captions).
**___Note: Change the `resolution` to 768 if you are using the [stable-diffusion-2](https://huggingface.co/stabilityai/stable-diffusion-2) 768x768 model.___** **___Note: Change the `resolution` to 768 if you are using the [stable-diffusion-2](https://huggingface.co/stabilityai/stable-diffusion-2) 768x768 model.___**
...@@ -221,7 +221,7 @@ accelerate launch --mixed_precision="fp16" train_text_to_image_lora.py \ ...@@ -221,7 +221,7 @@ accelerate launch --mixed_precision="fp16" train_text_to_image_lora.py \
--num_train_epochs=100 --checkpointing_steps=5000 \ --num_train_epochs=100 --checkpointing_steps=5000 \
--learning_rate=1e-04 --lr_scheduler="constant" --lr_warmup_steps=0 \ --learning_rate=1e-04 --lr_scheduler="constant" --lr_warmup_steps=0 \
--seed=42 \ --seed=42 \
--output_dir="sd-pokemon-model-lora" \ --output_dir="sd-naruto-model-lora" \
--validation_prompt="cute dragon creature" --report_to="wandb" --validation_prompt="cute dragon creature" --report_to="wandb"
``` ```
...@@ -236,7 +236,7 @@ You can check some inference samples that were logged during the course of the f ...@@ -236,7 +236,7 @@ You can check some inference samples that were logged during the course of the f
### Inference ### Inference
Once you have trained a model using above command, the inference can be done simply using the `StableDiffusionPipeline` after loading the trained LoRA weights. You Once you have trained a model using above command, the inference can be done simply using the `StableDiffusionPipeline` after loading the trained LoRA weights. You
need to pass the `output_dir` for loading the LoRA weights which, in this case, is `sd-pokemon-model-lora`. need to pass the `output_dir` for loading the LoRA weights which, in this case, is `sd-naruto-model-lora`.
```python ```python
from diffusers import StableDiffusionPipeline from diffusers import StableDiffusionPipeline
...@@ -247,9 +247,9 @@ pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", ...@@ -247,9 +247,9 @@ pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4",
pipe.unet.load_attn_procs(model_path) pipe.unet.load_attn_procs(model_path)
pipe.to("cuda") pipe.to("cuda")
prompt = "A pokemon with green eyes and red legs." prompt = "A naruto with green eyes and red legs."
image = pipe(prompt, num_inference_steps=30, guidance_scale=7.5).images[0] image = pipe(prompt, num_inference_steps=30, guidance_scale=7.5).images[0]
image.save("pokemon.png") image.save("naruto.png")
``` ```
If you are loading the LoRA parameters from the Hub and if the Hub repository has If you are loading the LoRA parameters from the Hub and if the Hub repository has
...@@ -293,7 +293,7 @@ python train_text_to_image_flax.py \ ...@@ -293,7 +293,7 @@ python train_text_to_image_flax.py \
--max_train_steps=15000 \ --max_train_steps=15000 \
--learning_rate=1e-05 \ --learning_rate=1e-05 \
--max_grad_norm=1 \ --max_grad_norm=1 \
--output_dir="sd-pokemon-model" --output_dir="sd-naruto-model"
``` ```
To run on your own training files prepare the dataset according to the format required by `datasets`, you can find the instructions for how to do that in this [document](https://huggingface.co/docs/datasets/v2.4.0/en/image_load#imagefolder-with-metadata). To run on your own training files prepare the dataset according to the format required by `datasets`, you can find the instructions for how to do that in this [document](https://huggingface.co/docs/datasets/v2.4.0/en/image_load#imagefolder-with-metadata).
...@@ -312,7 +312,7 @@ python train_text_to_image_flax.py \ ...@@ -312,7 +312,7 @@ python train_text_to_image_flax.py \
--max_train_steps=15000 \ --max_train_steps=15000 \
--learning_rate=1e-05 \ --learning_rate=1e-05 \
--max_grad_norm=1 \ --max_grad_norm=1 \
--output_dir="sd-pokemon-model" --output_dir="sd-naruto-model"
``` ```
### Training with xFormers: ### Training with xFormers:
......
...@@ -70,7 +70,7 @@ accelerate launch train_text_to_image_sdxl.py \ ...@@ -70,7 +70,7 @@ accelerate launch train_text_to_image_sdxl.py \
--report_to="wandb" \ --report_to="wandb" \
--validation_prompt="a cute Sundar Pichai creature" --validation_epochs 5 \ --validation_prompt="a cute Sundar Pichai creature" --validation_epochs 5 \
--checkpointing_steps=5000 \ --checkpointing_steps=5000 \
--output_dir="sdxl-pokemon-model" \ --output_dir="sdxl-naruto-model" \
--push_to_hub --push_to_hub
``` ```
...@@ -91,9 +91,9 @@ model_path = "you-model-id-goes-here" # <-- change this ...@@ -91,9 +91,9 @@ model_path = "you-model-id-goes-here" # <-- change this
pipe = DiffusionPipeline.from_pretrained(model_path, torch_dtype=torch.float16) pipe = DiffusionPipeline.from_pretrained(model_path, torch_dtype=torch.float16)
pipe.to("cuda") pipe.to("cuda")
prompt = "A pokemon with green eyes and red legs." prompt = "A naruto with green eyes and red legs."
image = pipe(prompt, num_inference_steps=30, guidance_scale=7.5).images[0] image = pipe(prompt, num_inference_steps=30, guidance_scale=7.5).images[0]
image.save("pokemon.png") image.save("naruto.png")
``` ```
### Inference in Pytorch XLA ### Inference in Pytorch XLA
...@@ -108,11 +108,11 @@ pipe = DiffusionPipeline.from_pretrained(model_id) ...@@ -108,11 +108,11 @@ pipe = DiffusionPipeline.from_pretrained(model_id)
device = xm.xla_device() device = xm.xla_device()
pipe.to(device) pipe.to(device)
prompt = "A pokemon with green eyes and red legs." prompt = "A naruto with green eyes and red legs."
start = time() start = time()
image = pipe(prompt, num_inference_steps=inference_steps).images[0] image = pipe(prompt, num_inference_steps=inference_steps).images[0]
print(f'Compilation time is {time()-start} sec') print(f'Compilation time is {time()-start} sec')
image.save("pokemon.png") image.save("naruto.png")
start = time() start = time()
image = pipe(prompt, num_inference_steps=inference_steps).images[0] image = pipe(prompt, num_inference_steps=inference_steps).images[0]
...@@ -142,7 +142,7 @@ on consumer GPUs like Tesla T4, Tesla V100. ...@@ -142,7 +142,7 @@ on consumer GPUs like Tesla T4, Tesla V100.
### Training ### Training
First, you need to set up your development environment as is explained in the [installation section](#installing-the-dependencies). Make sure to set the `MODEL_NAME` and `DATASET_NAME` environment variables and, optionally, the `VAE_NAME` variable. Here, we will use [Stable Diffusion XL 1.0-base](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0) and the [Pokemons dataset](https://huggingface.co/datasets/lambdalabs/naruto-blip-captions). First, you need to set up your development environment as is explained in the [installation section](#installing-the-dependencies). Make sure to set the `MODEL_NAME` and `DATASET_NAME` environment variables and, optionally, the `VAE_NAME` variable. Here, we will use [Stable Diffusion XL 1.0-base](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0) and the [Narutos dataset](https://huggingface.co/datasets/lambdalabs/naruto-blip-captions).
**___Note: It is quite useful to monitor the training progress by regularly generating sample images during training. [Weights and Biases](https://docs.wandb.ai/quickstart) is a nice solution to easily see generating images during training. All you need to do is to run `pip install wandb` before training to automatically log images.___** **___Note: It is quite useful to monitor the training progress by regularly generating sample images during training. [Weights and Biases](https://docs.wandb.ai/quickstart) is a nice solution to easily see generating images during training. All you need to do is to run `pip install wandb` before training to automatically log images.___**
...@@ -172,7 +172,7 @@ accelerate launch train_text_to_image_lora_sdxl.py \ ...@@ -172,7 +172,7 @@ accelerate launch train_text_to_image_lora_sdxl.py \
--learning_rate=1e-04 --lr_scheduler="constant" --lr_warmup_steps=0 \ --learning_rate=1e-04 --lr_scheduler="constant" --lr_warmup_steps=0 \
--mixed_precision="fp16" \ --mixed_precision="fp16" \
--seed=42 \ --seed=42 \
--output_dir="sd-pokemon-model-lora-sdxl" \ --output_dir="sd-naruto-model-lora-sdxl" \
--validation_prompt="cute dragon creature" --report_to="wandb" \ --validation_prompt="cute dragon creature" --report_to="wandb" \
--push_to_hub --push_to_hub
``` ```
...@@ -237,7 +237,7 @@ accelerate launch --config_file $ACCELERATE_CONFIG_FILE train_text_to_image_lor ...@@ -237,7 +237,7 @@ accelerate launch --config_file $ACCELERATE_CONFIG_FILE train_text_to_image_lor
--max_train_steps=20 \ --max_train_steps=20 \
--validation_epochs=20 \ --validation_epochs=20 \
--seed=1234 \ --seed=1234 \
--output_dir="sd-pokemon-model-lora-sdxl" \ --output_dir="sd-naruto-model-lora-sdxl" \
--validation_prompt="cute dragon creature" --validation_prompt="cute dragon creature"
``` ```
...@@ -260,7 +260,7 @@ accelerate launch train_text_to_image_lora_sdxl.py \ ...@@ -260,7 +260,7 @@ accelerate launch train_text_to_image_lora_sdxl.py \
--num_train_epochs=2 --checkpointing_steps=500 \ --num_train_epochs=2 --checkpointing_steps=500 \
--learning_rate=1e-04 --lr_scheduler="constant" --lr_warmup_steps=0 \ --learning_rate=1e-04 --lr_scheduler="constant" --lr_warmup_steps=0 \
--seed=42 \ --seed=42 \
--output_dir="sd-pokemon-model-lora-sdxl-txt" \ --output_dir="sd-naruto-model-lora-sdxl-txt" \
--train_text_encoder \ --train_text_encoder \
--validation_prompt="cute dragon creature" --report_to="wandb" \ --validation_prompt="cute dragon creature" --report_to="wandb" \
--push_to_hub --push_to_hub
...@@ -269,18 +269,18 @@ accelerate launch train_text_to_image_lora_sdxl.py \ ...@@ -269,18 +269,18 @@ accelerate launch train_text_to_image_lora_sdxl.py \
### Inference ### Inference
Once you have trained a model using above command, the inference can be done simply using the `DiffusionPipeline` after loading the trained LoRA weights. You Once you have trained a model using above command, the inference can be done simply using the `DiffusionPipeline` after loading the trained LoRA weights. You
need to pass the `output_dir` for loading the LoRA weights which, in this case, is `sd-pokemon-model-lora-sdxl`. need to pass the `output_dir` for loading the LoRA weights which, in this case, is `sd-naruto-model-lora-sdxl`.
```python ```python
from diffusers import DiffusionPipeline from diffusers import DiffusionPipeline
import torch import torch
model_path = "takuoko/sd-pokemon-model-lora-sdxl" model_path = "takuoko/sd-naruto-model-lora-sdxl"
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16) pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16)
pipe.to("cuda") pipe.to("cuda")
pipe.load_lora_weights(model_path) pipe.load_lora_weights(model_path)
prompt = "A pokemon with green eyes and red legs." prompt = "A naruto with green eyes and red legs."
image = pipe(prompt, num_inference_steps=30, guidance_scale=7.5).images[0] image = pipe(prompt, num_inference_steps=30, guidance_scale=7.5).images[0]
image.save("pokemon.png") image.save("naruto.png")
``` ```
## Textual Inversion fine-tuning example for SDXL ## Textual Inversion fine-tuning example for SDXL
``` ```sh
export MODEL_NAME="stabilityai/stable-diffusion-xl-base-1.0" export MODEL_NAME="stabilityai/stable-diffusion-xl-base-1.0"
export DATA_DIR="./cat" export DATA_DIR="./cat"
...@@ -23,4 +23,4 @@ accelerate launch textual_inversion_sdxl.py \ ...@@ -23,4 +23,4 @@ accelerate launch textual_inversion_sdxl.py \
--output_dir="./textual_inversion_cat_sdxl" --output_dir="./textual_inversion_cat_sdxl"
``` ```
For now, only training of the first text encoder is supported. For now, only training of the first text encoder is supported.
\ No newline at end of file \ No newline at end of file
...@@ -52,10 +52,10 @@ accelerate launch train_text_to_image_prior.py \ ...@@ -52,10 +52,10 @@ accelerate launch train_text_to_image_prior.py \
--max_grad_norm=1 \ --max_grad_norm=1 \
--checkpoints_total_limit=3 \ --checkpoints_total_limit=3 \
--lr_scheduler="constant" --lr_warmup_steps=0 \ --lr_scheduler="constant" --lr_warmup_steps=0 \
--validation_prompts="A robot pokemon, 4k photo" \ --validation_prompts="A robot naruto, 4k photo" \
--report_to="wandb" \ --report_to="wandb" \
--push_to_hub \ --push_to_hub \
--output_dir="wuerstchen-prior-pokemon-model" --output_dir="wuerstchen-prior-naruto-model"
``` ```
<!-- accelerate_snippet_end --> <!-- accelerate_snippet_end -->
...@@ -72,7 +72,7 @@ In a nutshell, LoRA allows adapting pretrained models by adding pairs of rank-de ...@@ -72,7 +72,7 @@ In a nutshell, LoRA allows adapting pretrained models by adding pairs of rank-de
### Prior Training ### Prior Training
First, you need to set up your development environment as explained in the [installation](#Running-locally-with-PyTorch) section. Make sure to set the `DATASET_NAME` environment variable. Here, we will use the [Pokemon captions dataset](https://huggingface.co/datasets/lambdalabs/naruto-blip-captions). First, you need to set up your development environment as explained in the [installation](#Running-locally-with-PyTorch) section. Make sure to set the `DATASET_NAME` environment variable. Here, we will use the [Naruto captions dataset](https://huggingface.co/datasets/lambdalabs/naruto-blip-captions).
```bash ```bash
export DATASET_NAME="lambdalabs/naruto-blip-captions" export DATASET_NAME="lambdalabs/naruto-blip-captions"
...@@ -89,5 +89,5 @@ accelerate launch train_text_to_image_lora_prior.py \ ...@@ -89,5 +89,5 @@ accelerate launch train_text_to_image_lora_prior.py \
--validation_prompt="cute dragon creature" \ --validation_prompt="cute dragon creature" \
--report_to="wandb" \ --report_to="wandb" \
--push_to_hub \ --push_to_hub \
--output_dir="wuerstchen-prior-pokemon-lora" --output_dir="wuerstchen-prior-naruto-lora"
``` ```
...@@ -85,10 +85,9 @@ EXAMPLE_DOC_STRING = """ ...@@ -85,10 +85,9 @@ EXAMPLE_DOC_STRING = """
>>> init_image = download_image(img_url).resize((768, 768)) >>> init_image = download_image(img_url).resize((768, 768))
>>> pipe = StableDiffusionDiffEditPipeline.from_pretrained( >>> pipeline = StableDiffusionDiffEditPipeline.from_pretrained(
... "stabilityai/stable-diffusion-2-1", torch_dtype=torch.float16 ... "stabilityai/stable-diffusion-2-1", torch_dtype=torch.float16
... ) ... )
>>> pipe = pipe.to("cuda")
>>> pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config) >>> pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config)
>>> pipeline.inverse_scheduler = DDIMInverseScheduler.from_config(pipeline.scheduler.config) >>> pipeline.inverse_scheduler = DDIMInverseScheduler.from_config(pipeline.scheduler.config)
...@@ -97,9 +96,9 @@ EXAMPLE_DOC_STRING = """ ...@@ -97,9 +96,9 @@ EXAMPLE_DOC_STRING = """
>>> mask_prompt = "A bowl of fruits" >>> mask_prompt = "A bowl of fruits"
>>> prompt = "A bowl of pears" >>> prompt = "A bowl of pears"
>>> mask_image = pipe.generate_mask(image=init_image, source_prompt=prompt, target_prompt=mask_prompt) >>> mask_image = pipeline.generate_mask(image=init_image, source_prompt=prompt, target_prompt=mask_prompt)
>>> image_latents = pipe.invert(image=init_image, prompt=mask_prompt).latents >>> image_latents = pipeline.invert(image=init_image, prompt=mask_prompt).latents
>>> image = pipe(prompt=prompt, mask_image=mask_image, image_latents=image_latents).images[0] >>> image = pipeline(prompt=prompt, mask_image=mask_image, image_latents=image_latents).images[0]
``` ```
""" """
...@@ -122,10 +121,9 @@ EXAMPLE_INVERT_DOC_STRING = """ ...@@ -122,10 +121,9 @@ EXAMPLE_INVERT_DOC_STRING = """
>>> init_image = download_image(img_url).resize((768, 768)) >>> init_image = download_image(img_url).resize((768, 768))
>>> pipe = StableDiffusionDiffEditPipeline.from_pretrained( >>> pipeline = StableDiffusionDiffEditPipeline.from_pretrained(
... "stabilityai/stable-diffusion-2-1", torch_dtype=torch.float16 ... "stabilityai/stable-diffusion-2-1", torch_dtype=torch.float16
... ) ... )
>>> pipe = pipe.to("cuda")
>>> pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config) >>> pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config)
>>> pipeline.inverse_scheduler = DDIMInverseScheduler.from_config(pipeline.scheduler.config) >>> pipeline.inverse_scheduler = DDIMInverseScheduler.from_config(pipeline.scheduler.config)
...@@ -133,7 +131,7 @@ EXAMPLE_INVERT_DOC_STRING = """ ...@@ -133,7 +131,7 @@ EXAMPLE_INVERT_DOC_STRING = """
>>> prompt = "A bowl of fruits" >>> prompt = "A bowl of fruits"
>>> inverted_latents = pipe.invert(image=init_image, prompt=prompt).latents >>> inverted_latents = pipeline.invert(image=init_image, prompt=prompt).latents
``` ```
""" """
......
...@@ -692,7 +692,7 @@ def print_tree_deps_of(module, all_edges=None): ...@@ -692,7 +692,7 @@ def print_tree_deps_of(module, all_edges=None):
def init_test_examples_dependencies() -> Tuple[Dict[str, List[str]], List[str]]: def init_test_examples_dependencies() -> Tuple[Dict[str, List[str]], List[str]]:
""" """
The test examples do not import from the examples (which are just scripts, not modules) so we need som extra The test examples do not import from the examples (which are just scripts, not modules) so we need some extra
care initializing the dependency map, which is the goal of this function. It initializes the dependency map for care initializing the dependency map, which is the goal of this function. It initializes the dependency map for
example files by linking each example to the example test file for the example framework. example files by linking each example to the example test file for the example framework.
......
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