Skip to content

Commit f7aa3b9

Browse files
authored
Merge branch 'main' into docker-build-workflow
2 parents 7dacfcb + 869bad3 commit f7aa3b9

File tree

4 files changed

+55
-6
lines changed

4 files changed

+55
-6
lines changed

docker/diffusers-onnxruntime-cuda/Dockerfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM nvidia/cuda:11.6.2-cudnn8-devel-ubuntu20.04
1+
FROM nvidia/cuda:12.1.0-runtime-ubuntu20.04
22
LABEL maintainer="Hugging Face"
33
LABEL repository="diffusers"
44

@@ -24,9 +24,9 @@ ENV PATH="/opt/venv/bin:$PATH"
2424
# pre-install the heavy dependencies (these can later be overridden by the deps from setup.py)
2525
RUN python3 -m pip install --no-cache-dir --upgrade pip uv==0.1.11 && \
2626
python3 -m uv pip install --no-cache-dir \
27-
torch==2.1.2 \
28-
torchvision==0.16.2 \
29-
torchaudio==2.1.2 \
27+
torch \
28+
torchvision \
29+
torchaudio \
3030
"onnxruntime-gpu>=1.13.1" \
3131
--extra-index-url https://download.pytorch.org/whl/cu117 && \
3232
python3 -m uv pip install --no-cache-dir \

examples/advanced_diffusion_training/README.md

+27-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ To do so, just specify `--train_text_encoder_ti` while launching training (for r
8080
Please keep the following points in mind:
8181

8282
* SDXL has two text encoders. So, we fine-tune both using LoRA.
83-
* When not fine-tuning the text encoders, we ALWAYS precompute the text embeddings to save memoםהקרry.
84-
83+
* When not fine-tuning the text encoders, we ALWAYS precompute the text embeddings to save memory.
8584

8685
### 3D icon example
8786

@@ -234,6 +233,32 @@ In ComfyUI we will load a LoRA and a textual embedding at the same time.
234233

235234
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)).
236235

236+
### DoRA training
237+
The advanced script now supports DoRA training too!
238+
> Proposed in [DoRA: Weight-Decomposed Low-Rank Adaptation](https://arxiv.org/abs/2402.09353),
239+
**DoRA** is very similar to LoRA, except it decomposes the pre-trained weight into two components, **magnitude** and **direction** and employs LoRA for _directional_ updates to efficiently minimize the number of trainable parameters.
240+
The authors found that by using DoRA, both the learning capacity and training stability of LoRA are enhanced without any additional overhead during inference.
241+
242+
> [!NOTE]
243+
> 💡DoRA training is still _experimental_
244+
> and is likely to require different hyperparameter values to perform best compared to a LoRA.
245+
> Specifically, we've noticed 2 differences to take into account your training:
246+
> 1. **LoRA seem to converge faster than DoRA** (so a set of parameters that may lead to overfitting when training a LoRA may be working well for a DoRA)
247+
> 2. **DoRA quality superior to LoRA especially in lower ranks** the difference in quality of DoRA of rank 8 and LoRA of rank 8 appears to be more significant than when training ranks of 32 or 64 for example.
248+
> This is also aligned with some of the quantitative analysis shown in the paper.
249+
250+
**Usage**
251+
1. To use DoRA you need to install `peft` from main:
252+
```bash
253+
pip install git+https://github.com/huggingface/peft.git
254+
```
255+
2. Enable DoRA training by adding this flag
256+
```bash
257+
--use_dora
258+
```
259+
**Inference**
260+
The inference is the same as if you train a regular LoRA 🤗
261+
237262

238263
### Tips and Tricks
239264
Check out [these recommended practices](https://huggingface.co/blog/sdxl_lora_advanced_script#additional-good-practices)

examples/advanced_diffusion_training/train_dreambooth_lora_sd15_advanced.py

+12
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,16 @@ def parse_args(input_args=None):
651651
default=4,
652652
help=("The dimension of the LoRA update matrices."),
653653
)
654+
parser.add_argument(
655+
"--use_dora",
656+
type=bool,
657+
action="store_true",
658+
default=False,
659+
help=(
660+
"Wether to train a DoRA as proposed in- DoRA: Weight-Decomposed Low-Rank Adaptation https://arxiv.org/abs/2402.09353. "
661+
"Note: to use DoRA you need to install peft from main, `pip install git+https://github.com/huggingface/peft.git`"
662+
),
663+
)
654664
parser.add_argument(
655665
"--cache_latents",
656666
action="store_true",
@@ -1219,6 +1229,7 @@ def main(args):
12191229
unet_lora_config = LoraConfig(
12201230
r=args.rank,
12211231
lora_alpha=args.rank,
1232+
use_dora=args.use_dora,
12221233
init_lora_weights="gaussian",
12231234
target_modules=["to_k", "to_q", "to_v", "to_out.0"],
12241235
)
@@ -1230,6 +1241,7 @@ def main(args):
12301241
text_lora_config = LoraConfig(
12311242
r=args.rank,
12321243
lora_alpha=args.rank,
1244+
use_dora=args.use_dora,
12331245
init_lora_weights="gaussian",
12341246
target_modules=["q_proj", "k_proj", "v_proj", "out_proj"],
12351247
)

examples/advanced_diffusion_training/train_dreambooth_lora_sdxl_advanced.py

+12
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,16 @@ def parse_args(input_args=None):
661661
default=4,
662662
help=("The dimension of the LoRA update matrices."),
663663
)
664+
parser.add_argument(
665+
"--use_dora",
666+
type=bool,
667+
action="store_true",
668+
default=False,
669+
help=(
670+
"Wether to train a DoRA as proposed in- DoRA: Weight-Decomposed Low-Rank Adaptation https://arxiv.org/abs/2402.09353. "
671+
"Note: to use DoRA you need to install peft from main, `pip install git+https://github.com/huggingface/peft.git`"
672+
),
673+
)
664674
parser.add_argument(
665675
"--cache_latents",
666676
action="store_true",
@@ -1323,6 +1333,7 @@ def main(args):
13231333
unet_lora_config = LoraConfig(
13241334
r=args.rank,
13251335
lora_alpha=args.rank,
1336+
use_dora=args.use_dora,
13261337
init_lora_weights="gaussian",
13271338
target_modules=["to_k", "to_q", "to_v", "to_out.0"],
13281339
)
@@ -1334,6 +1345,7 @@ def main(args):
13341345
text_lora_config = LoraConfig(
13351346
r=args.rank,
13361347
lora_alpha=args.rank,
1348+
use_dora=args.use_dora,
13371349
init_lora_weights="gaussian",
13381350
target_modules=["q_proj", "k_proj", "v_proj", "out_proj"],
13391351
)

0 commit comments

Comments
 (0)