[train_text_to_image_sdxl.py] Fix the LR scheduler when num_train_epochs is passed in a distributed training env - #14527
Open
adi-IL wants to merge 1 commit into
Conversation
…raining Scale warmup and training steps by accelerator.num_processes so --num_train_epochs builds the same schedule as the other official trainers after huggingface#8312.
adi-IL
force-pushed
the
fix/sdxl-t2i-lr-scheduler-distributed
branch
from
August 18, 2026 16:06
c848282 to
b5cac75
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8384
This PR updates only
examples/text_to_image/train_text_to_image_sdxl.py, matching the #8312 pattern already applied totrain_text_to_image.pyand the DreamBooth trainers.What was wrong
When
--num_train_epochsis used (somax_train_stepsis derived), the SDXL trainer still built the LR schedule from the unsharded dataloader length and ignoredaccelerator.num_processes. In a multi-process run that makes the scheduler finish too early.What changed
get_schedulerare scaled byaccelerator.num_processes.accelerator.prepare, we warn if the prepared dataloader length does not match that assumption.--num_train_epochs 1.Coordination
Claimed on #8384: #8384 (comment)
@sayakpaul @geniuspatrick
Minimal training command using
num_train_epochsTests I ran
That passed. I did not run the example pytest here because this machine does not have the package or its test extras installed. The new
test_text_to_image_sdxl_num_train_epochsplus the existingtest_text_to_image_sdxlshould cover both--max_train_stepsand--num_train_epochsin CI.Self-review
train_text_to_image.py, not reinvented.train_text_to_image_lora_sdxl.pyand the other remaining scripts alone so this stays one script per PR.