Skip to content

Conversation

Sohaib-Ahmed21
Copy link
Contributor

@Sohaib-Ahmed21 Sohaib-Ahmed21 commented Sep 28, 2025

What does this PR do?

Fixes gradient synchronization when using manual optimization with DDPStrategy(static_graph=True).

  • Calls reducer._delay_all_reduce() in post_backward to ensure gradients are properly reduced in the first iteration.
  • Adds a regression test (test_ddp_gradients_synced) that checks gradient synchronization across:
    • automatic_optimization=True / False
    • static_graph=True / False

Fixes #18086

Before submitting
  • Was this discussed/agreed via a GitHub issue? (not for typos and docs)
    Yes
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you write any new necessary tests? (not for typos and docs)
    yes
  • Did you verify new and existing tests pass locally with your changes?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or minor internal changes/refactors)

PR review

Anyone in the community is welcome to review the PR.
Before you start reviewing, make sure you have read the review guidelines. In short, see the following bullet-list:

Reviewer checklist
  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

📚 Documentation preview 📚: https://pytorch-lightning--21251.org.readthedocs.build/en/21251/

@github-actions github-actions bot added the pl Generic label for PyTorch Lightning package label Sep 28, 2025
@Sohaib-Ahmed21
Copy link
Contributor Author

Sohaib-Ahmed21 commented Oct 1, 2025

@SkafteNicki @Borda @lantiga kindly review this pull request, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pl Generic label for PyTorch Lightning package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gradients seem not synchronized with manual optimization and DDPStrategy with static_graph=True
1 participant