Repository navigation
Conversation
Contributor
|
Hi @nrenvo, thanks for the PR! It does not appear to link an issue it fixes. If this PR addresses an existing issue, please add a closing keyword (e.g. Please note that PRs without a linked issue are likely to be automatically closed 10 days after this notice. Once the PR links an issue (or gets the |
When AMP skips an optimizer step due to gradient overflow, model weights are unchanged. Guard the EMA update and per-step bookkeeping with not accelerator.optimizer_step_was_skipped so EMA only steps when the optimizer actually applied gradients. Also move train_loss = 0.0 outside the skipped-step guard so the loss accumulator resets on every sync_gradients boundary, including overflowed ones. Affected scripts: - examples/text_to_image/train_text_to_image.py - examples/text_to_image/train_text_to_image_sdxl.py - examples/instruct_pix2pix/train_instruct_pix2pix.py - examples/instruct_pix2pix/train_instruct_pix2pix_sdxl.py - examples/unconditional_image_generation/train_unconditional.py - examples/amused/train_amused.py - examples/vqgan/train_vqgan.py
nrenvo
force-pushed
the
fix/ema-skipped-step-v2
branch
from
November 10, 2026 11:12
49b5100 to
205621b
Compare
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.
When AMP skips an optimizer step due to gradient overflow, model weights are unchanged. The previous code still updated EMA with those unchanged weights, biasing the moving average.
Guard the EMA update and per-step bookkeeping with not accelerator.optimizer_step_was_skipped so EMA only steps when the optimizer actually applied gradients.
Also move train_loss = 0.0 outside the skipped-step guard so the loss accumulator resets on every sync_gradients boundary, including overflowed ones.
Affected scripts: train_text_to_image, train_text_to_image_sdxl, train_instruct_pix2pix, train_instruct_pix2pix_sdxl, train_unconditional, train_amused, train_vqgan.
Adds a parametrized test that simulates an overflow on step 2 and asserts EMA is never called for a skipped step.
Splits out from #15173 as requested.
Fixes #15112