Open DarkMnDragon opened 2 months ago
Cc: @linoytsaban
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.
Please note that issues that do not follow the contributing guidelines are likely to be ignored.
Describe the bug
In the
train_dreambooth_lora_flux.py
script, during each call tolog_validation
, the text encoderstext_encoder_one
andtext_encoder_two
are reinitialized. https://github.com/huggingface/diffusers/blob/8ba90aa706a733f45d83508a5b221da3c59fe4cd/examples/dreambooth/train_dreambooth_lora_flux.py#L1768 This occurs even when the text encoders do not need to be trained (if not args.train_text_encoder
). This unnecessary reinitialization can lead to inefficient use of resources and may cause CUDA out-of-memory errors, especially in scenarios where VRAM is less than 48 GiB.Since the validation prompt is fixed (only one prompt is used), we can optimize the process by precomputing the text embeddings during the instance prompt preprocessing. This would allow the model to fit within 40 GiB of VRAM, preventing CUDA OOM issues.
Proposed Fix
To address this issue, add the following code snippet to precompute the validation prompt embeddings only once when the text encoders do not need to be trained and custom instance prompts are not used:
This change will prevent the unnecessary reinitialization of text encoders and reduce the VRAM usage during training.
Reproduction
Logs
No response
System Info
Who can help?
@sayakpaul