Repository navigation
Conversation
The scheduler was created using max_train_steps * accelerator.num_processes where max_train_steps itself was derived from the pre-sharded dataloader length. After accelerator.prepare() the dataloader is sharded across GPUs, so the real update steps per epoch drop by num_processes, but the scheduler had already been initialized with a value N times too large. Applies the pattern established in PR huggingface#8312: - Pre-compute len_train_dataloader_after_sharding = ceil(len(dataloader) / num_processes) - Derive num_training_steps_for_scheduler using the sharded length - Pass num_training_steps_for_scheduler to get_scheduler() and DummyScheduler Fixes huggingface#15087
This branch has not been deployed
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.
What this PR does / why we need it
Fixes #15087
Several training scripts create the
lr_schedulerbeforeaccelerator.prepare()using a step count derived from the non-sharded dataloader length. Afteraccelerator.prepare(), the dataloader is sharded across GPUs so its length drops bynum_processes— but the scheduler was already built with an N× inflated step count. This causes:constantorcosineschedulesRoot cause
Fix
Applies the correct pattern established in PR #8312 consistently across all affected scripts:
Affected scripts (15 files)
examples/dreambooth/train_dreambooth_lora_qwen_image.pyexamples/dreambooth/train_dreambooth_lora_qwenimage21.pyexamples/dreambooth/train_dreambooth_lora_qwenimage21_img2img.pyexamples/dreambooth/train_dreambooth_lora_hidream.pyexamples/dreambooth/train_dreambooth_lora_krea2.pyexamples/dreambooth/train_dreambooth_lora_lumina2.pyexamples/dreambooth/train_dreambooth_lora_sana.pyexamples/dreambooth/train_dreambooth_sd3.pyexamples/controlnet/train_controlnet_sd3.pyexamples/controlnet/train_controlnet_flux.py(hadnum_training_steps_for_schedulercomputed correctly but not passed toget_scheduler)examples/cogvideo/train_cogvideox_lora.pyexamples/cogvideo/train_cogvideox_image_to_video_lora.pyexamples/cogview4-control/train_control_cogview4.py(same partial-fix as controlnet_flux)examples/textual_inversion/textual_inversion.pyexamples/rfd4_proteina/train_rfd4_proteina_lora.pyWho can help?
@sayakpaul @DN6