[kandinsky][train_text_to_image_prior.py] Fix LR scheduler when num_train_epochs is passed in a distributed training env - #14597
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 other official trainers after huggingface#8312. Fixes huggingface#8384.
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.
What was wrong
examples/kandinsky2_2/text_to_image/train_text_to_image_prior.pybuilt the LR scheduler withnum_warmup_steps=args.lr_warmup_steps * args.gradient_accumulation_stepsandnum_training_steps=args.max_train_steps * args.gradient_accumulation_steps, and computedmax_train_stepsasnum_train_epochs * ceil(len(dataloader)/gradient_accumulation)without sharding. In distributed training (accelerator.num_processes > 1) the dataloader length per process is smaller, so the scheduler saw the wrong total steps and warmup.Same issue fixed for other trainers in #8312 and follow-ups (#8450, #9316, etc.). This file was one of the remaining unchecked items in #8384.
What changed
Mirrored the fixed pattern from
examples/text_to_image/train_text_to_image.py:num_warmup_steps_for_scheduler = args.lr_warmup_steps * accelerator.num_processesmax_train_steps is None, computelen_train_dataloader_after_sharding = ceil(len(dataloader)/num_processes), thennum_training_steps_for_scheduler = num_epochs * ceil(len_sharded/grad_accum) * num_processes; elsemax_train_steps * num_processesget_scheduleraccelerator.prepare, recalcmax_train_stepswhen it was derived from epochs and warn if the expected sharded length does not match the actual lengthSingle file, single issue.
Coordination
num_train_epochsis passed in a distributed training env #8384 (standing community checklist, Good second issue)Tests
python -m py_compile examples/kandinsky2_2/text_to_image/train_text_to_image_prior.py-> OKmake style/make qualityrelevant checks are limited to this single script.Self-review