Skip to content

Commit 6e8d065

Browse files
sayakpauldg845
authored andcommitted
fix: scale_lr and sync example readme and docs. (huggingface#3299)
* fix: scale_lr and sync example readme and docs. * fix doc link.
1 parent c8cc4f0 commit 6e8d065

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

docs/source/en/training/lora.mdx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,26 @@ Load the LoRA weights from your finetuned DreamBooth model *on top of the base m
243243
>>> image.save("bucket-dog.png")
244244
```
245245

246-
Note that the use of [`LoraLoaderMixin.load_lora_weights`] is preferred to [`UNet2DConditionLoadersMixin.load_attn_procs`] for loading LoRA parameters. This is because
247-
[`LoraLoaderMixin.load_lora_weights`] can handle the following situations:
246+
If you used `--train_text_encoder` during training, then use `pipe.load_lora_weights()` to load the LoRA
247+
weights. For example:
248+
249+
```python
250+
from huggingface_hub.repocard import RepoCard
251+
from diffusers import StableDiffusionPipeline
252+
import torch
253+
254+
lora_model_id = "sayakpaul/dreambooth-text-encoder-test"
255+
card = RepoCard.load(lora_model_id)
256+
base_model_id = card.data.to_dict()["base_model"]
257+
258+
pipe = StableDiffusionPipeline.from_pretrained(base_model_id, torch_dtype=torch.float16)
259+
pipe = pipe.to("cuda")
260+
pipe.load_lora_weights(lora_model_id)
261+
image = pipe("A picture of a sks dog in a bucket", num_inference_steps=25).images[0]
262+
```
263+
264+
Note that the use of [`~diffusers.loaders.LoraLoaderMixin.load_lora_weights`] is preferred to [`~diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs`] for loading LoRA parameters. This is because
265+
[`~diffusers.loaders.LoraLoaderMixin.load_lora_weights`] can handle the following situations:
248266

249267
* 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:
250268

examples/dreambooth/README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,26 @@ pipe = StableDiffusionPipeline.from_pretrained(base_model_id, torch_dtype=torch.
408408
...
409409
```
410410

411-
**Note** that we will gradually be depcrecating the use of [`UNet2DConditionLoadersMixin.load_attn_procs`](https://huggingface.co/docs/diffusers/main/en/api/loaders#diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs) since we now have a more general
412-
method to load the LoRA parameters -- [`LoraLoaderMixin.load_lora_weights`](https://huggingface.co/docs/diffusers/main/en/api/loaders#diffusers.loaders.LoraLoaderMixin.load_lora_weights). This is because
413-
[`LoraLoaderMixin.load_lora_weights`] can handle the following situations:
411+
If you used `--train_text_encoder` during training, then use `pipe.load_lora_weights()` to load the LoRA
412+
weights. For example:
413+
414+
```python
415+
from huggingface_hub.repocard import RepoCard
416+
from diffusers import StableDiffusionPipeline
417+
import torch
418+
419+
lora_model_id = "sayakpaul/dreambooth-text-encoder-test"
420+
card = RepoCard.load(lora_model_id)
421+
base_model_id = card.data.to_dict()["base_model"]
422+
423+
pipe = StableDiffusionPipeline.from_pretrained(base_model_id, torch_dtype=torch.float16)
424+
pipe = pipe.to("cuda")
425+
pipe.load_lora_weights(lora_model_id)
426+
image = pipe("A picture of a sks dog in a bucket", num_inference_steps=25).images[0]
427+
```
428+
429+
Note that the use of [`LoraLoaderMixin.load_lora_weights`](https://huggingface.co/docs/diffusers/main/en/api/loaders#diffusers.loaders.LoraLoaderMixin.load_lora_weights) is preferred to [`UNet2DConditionLoadersMixin.load_attn_procs`](https://huggingface.co/docs/diffusers/main/en/api/loaders#diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs) for loading LoRA parameters. This is because
430+
`LoraLoaderMixin.load_lora_weights` can handle the following situations:
414431

415432
* 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:
416433

examples/dreambooth/train_dreambooth_lora.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -746,11 +746,6 @@ def main(args):
746746
accelerator.register_for_checkpointing(text_encoder_lora_layers)
747747
del temp_pipeline
748748

749-
if args.scale_lr:
750-
args.learning_rate = (
751-
args.learning_rate * args.gradient_accumulation_steps * args.train_batch_size * accelerator.num_processes
752-
)
753-
754749
# Enable TF32 for faster training on Ampere GPUs,
755750
# cf https://pytorch.org/docs/stable/notes/cuda.html#tensorfloat-32-tf32-on-ampere-devices
756751
if args.allow_tf32:

0 commit comments

Comments
 (0)