Skip to content

Commit c25c461

Browse files
authored
[Examples] Add madebyollin VAE to SDXL LoRA example, along with an explanation (#4762)
Add madebyollin VAE to LoRA example, along with an explenation
1 parent 3105c71 commit c25c461

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

examples/text_to_image/README_sdxl.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ When running `accelerate config`, if we specify torch compile mode to True there
5050

5151
```bash
5252
export MODEL_NAME="stabilityai/stable-diffusion-xl-base-1.0"
53-
export VAE="madebyollin/sdxl-vae-fp16-fix"
53+
export VAE_NAME="madebyollin/sdxl-vae-fp16-fix"
5454
export DATASET_NAME="lambdalabs/pokemon-blip-captions"
5555

5656
accelerate launch train_text_to_image_sdxl.py \
5757
--pretrained_model_name_or_path=$MODEL_NAME \
58-
--pretrained_vae_model_name_or_path=$VAE \
58+
--pretrained_vae_model_name_or_path=$VAE_NAME \
5959
--dataset_name=$DATASET_NAME \
6060
--enable_xformers_memory_efficient_attention \
6161
--resolution=512 --center_crop --random_flip \
@@ -78,6 +78,7 @@ accelerate launch train_text_to_image_sdxl.py \
7878
* The `train_text_to_image_sdxl.py` script pre-computes text embeddings and the VAE encodings and keeps them in memory. While for smaller datasets like [`lambdalabs/pokemon-blip-captions`](https://hf.co/datasets/lambdalabs/pokemon-blip-captions), it might not be a problem, it can definitely lead to memory problems when the script is used on a larger dataset. For those purposes, you would want to serialize these pre-computed representations to disk separately and load them during the fine-tuning process. Refer to [this PR](https://github.com/huggingface/diffusers/pull/4505) for a more in-depth discussion.
7979
* The training script is compute-intensive and may not run on a consumer GPU like Tesla T4.
8080
* The training command shown above performs intermediate quality validation in between the training epochs and logs the results to Weights and Biases. `--report_to`, `--validation_prompt`, and `--validation_epochs` are the relevant CLI arguments here.
81+
* SDXL's VAE is known to suffer from numerical instability issues. This is why we also expose a CLI argument namely `--pretrained_vae_model_name_or_path` that lets you specify the location of a better VAE (such as [this one](https://huggingface.co/madebyollin/sdxl-vae-fp16-fix)).
8182

8283
### Inference
8384

@@ -111,12 +112,13 @@ on consumer GPUs like Tesla T4, Tesla V100.
111112

112113
### Training
113114

114-
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 XL 1.0-base](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0) and the [Pokemons dataset](https://huggingface.co/datasets/lambdalabs/pokemon-blip-captions).
115+
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/pokemon-blip-captions).
115116

116117
**___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.___**
117118

118119
```bash
119120
export MODEL_NAME="stabilityai/stable-diffusion-xl-base-1.0"
121+
export VAE_NAME="madebyollin/sdxl-vae-fp16-fix"
120122
export DATASET_NAME="lambdalabs/pokemon-blip-captions"
121123
```
122124

@@ -132,11 +134,13 @@ Now we can start training!
132134
```bash
133135
accelerate launch train_text_to_image_lora_sdxl.py \
134136
--pretrained_model_name_or_path=$MODEL_NAME \
137+
--pretrained_vae_model_name_or_path=$VAE_NAME \
135138
--dataset_name=$DATASET_NAME --caption_column="text" \
136139
--resolution=1024 --random_flip \
137140
--train_batch_size=1 \
138141
--num_train_epochs=2 --checkpointing_steps=500 \
139142
--learning_rate=1e-04 --lr_scheduler="constant" --lr_warmup_steps=0 \
143+
--mixed_precision="fp16" \
140144
--seed=42 \
141145
--output_dir="sd-pokemon-model-lora-sdxl" \
142146
--validation_prompt="cute dragon creature" --report_to="wandb" \
@@ -145,6 +149,10 @@ accelerate launch train_text_to_image_lora_sdxl.py \
145149

146150
The above command will also run inference as fine-tuning progresses and log the results to Weights and Biases.
147151

152+
**Notes**:
153+
154+
* SDXL's VAE is known to suffer from numerical instability issues. This is why we also expose a CLI argument namely `--pretrained_vae_model_name_or_path` that lets you specify the location of a better VAE (such as [this one](https://huggingface.co/madebyollin/sdxl-vae-fp16-fix)).
155+
148156
### Finetuning the text encoder and UNet
149157

150158
The script also allows you to finetune the `text_encoder` along with the `unet`.

0 commit comments

Comments
 (0)