Skip to content

Commit edd7880

Browse files
linoytsabansayakpaulgithub-actions[bot]
authored
[HiDream LoRA] optimizations + small updates (#11381)
* 1. add pre-computation of prompt embeddings when custom prompts are used as well 2. save model card even if model is not pushed to hub 3. remove scheduler initialization from code example - not necessary anymore (it's now if the base model's config) 4. add skip_final_inference - to allow to run with validation, but skip the final loading of the pipeline with the lora weights to reduce memory reqs * pre encode validation prompt as well * Update examples/dreambooth/train_dreambooth_lora_hidream.py Co-authored-by: Sayak Paul <[email protected]> * Update examples/dreambooth/train_dreambooth_lora_hidream.py Co-authored-by: Sayak Paul <[email protected]> * Update examples/dreambooth/train_dreambooth_lora_hidream.py Co-authored-by: Sayak Paul <[email protected]> * pre encode validation prompt as well * Apply style fixes * empty commit * change default trained modules * empty commit * address comments + change encoding of validation prompt (before it was only pre-encoded if custom prompts are provided, but should be pre-encoded either way) * Apply style fixes * empty commit * fix validation_embeddings definition * fix final inference condition * fix pipeline deletion in last inference * Apply style fixes * empty commit * layers * remove readme remarks on only pre-computing when instance prompt is provided and change example to 3d icons * smol fix * empty commit --------- Co-authored-by: Sayak Paul <[email protected]> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent b4be422 commit edd7880

File tree

2 files changed

+159
-123
lines changed

2 files changed

+159
-123
lines changed

examples/dreambooth/README_hidream.md

+13-27
Original file line numberDiff line numberDiff line change
@@ -51,54 +51,41 @@ When running `accelerate config`, if we specify torch compile mode to True there
5151
Note also that we use PEFT library as backend for LoRA training, make sure to have `peft>=0.14.0` installed in your environment.
5252

5353

54-
### Dog toy example
54+
### 3d icon example
5555

56-
Now let's get our dataset. For this example we will use some dog images: https://huggingface.co/datasets/diffusers/dog-example.
57-
58-
Let's first download it locally:
59-
60-
```python
61-
from huggingface_hub import snapshot_download
62-
63-
local_dir = "./dog"
64-
snapshot_download(
65-
"diffusers/dog-example",
66-
local_dir=local_dir, repo_type="dataset",
67-
ignore_patterns=".gitattributes",
68-
)
69-
```
56+
For this example we will use some 3d icon images: https://huggingface.co/datasets/linoyts/3d_icon.
7057

7158
This will also allow us to push the trained LoRA parameters to the Hugging Face Hub platform.
7259

7360
Now, we can launch training using:
7461
> [!NOTE]
7562
> The following training configuration prioritizes lower memory consumption by using gradient checkpointing,
76-
> 8-bit Adam optimizer, latent caching, offloading, no validation.
77-
> Additionally, when provided with 'instance_prompt' only and no 'caption_column' (used for custom prompts for each image)
78-
> text embeddings are pre-computed to save memory.
79-
63+
> 8-bit Adam optimizer, latent caching, offloading, no validation.
64+
> all text embeddings are pre-computed to save memory.
8065
```bash
8166
export MODEL_NAME="HiDream-ai/HiDream-I1-Dev"
82-
export INSTANCE_DIR="dog"
67+
export INSTANCE_DIR="linoyts/3d_icon"
8368
export OUTPUT_DIR="trained-hidream-lora"
8469

8570
accelerate launch train_dreambooth_lora_hidream.py \
8671
--pretrained_model_name_or_path=$MODEL_NAME \
87-
--instance_data_dir=$INSTANCE_DIR \
72+
--dataset_name=$INSTANCE_DIR \
8873
--output_dir=$OUTPUT_DIR \
8974
--mixed_precision="bf16" \
90-
--instance_prompt="a photo of sks dog" \
75+
--instance_prompt="3d icon" \
76+
--caption_column="prompt"\
77+
--validation_prompt="a 3dicon, a llama eating ramen" \
9178
--resolution=1024 \
9279
--train_batch_size=1 \
9380
--gradient_accumulation_steps=4 \
9481
--use_8bit_adam \
95-
--rank=16 \
82+
--rank=8 \
9683
--learning_rate=2e-4 \
9784
--report_to="wandb" \
98-
--lr_scheduler="constant" \
99-
--lr_warmup_steps=0 \
85+
--lr_scheduler="constant_with_warmup" \
86+
--lr_warmup_steps=100 \
10087
--max_train_steps=1000 \
101-
--cache_latents \
88+
--cache_latents\
10289
--gradient_checkpointing \
10390
--validation_epochs=25 \
10491
--seed="0" \
@@ -128,6 +115,5 @@ We provide several options for optimizing memory optimization:
128115
* `--offload`: When enabled, we will offload the text encoder and VAE to CPU, when they are not used.
129116
* `cache_latents`: When enabled, we will pre-compute the latents from the input images with the VAE and remove the VAE from memory once done.
130117
* `--use_8bit_adam`: When enabled, we will use the 8bit version of AdamW provided by the `bitsandbytes` library.
131-
* `--instance_prompt` and no `--caption_column`: when only an instance prompt is provided, we will pre-compute the text embeddings and remove the text encoders from memory once done.
132118

133119
Refer to the [official documentation](https://huggingface.co/docs/diffusers/main/en/api/pipelines/) of the `HiDreamImagePipeline` to know more about the model.

0 commit comments

Comments
 (0)