Add sync_dist_op to LightningModule logging - #21892
Open
zupengwang wants to merge 1 commit into
Open
Conversation
Signed-off-by: Zupeng Wang <71580390+zupengwang@users.noreply.github.com>
zupengwang
marked this pull request as ready for review
August 9, 2026 13:36
zupengwang
requested review from
ethanwharris,
justusschock and
tchaton
as code owners
August 9, 2026 13:36
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 does this PR do?
Adds a
sync_dist_opargument toLightningModule.logandLightningModule.log_dictso the reduction across distributed ranks can be configured independently from the reduction across epoch steps.When
sync_dist_opis omitted, the distributed operation still falls back toreduce_fx, preserving existing behavior. The argument is appended to the public signatures to avoid shifting existing positional arguments. The API docstrings and PyTorch changelog are updated.The regression test covers CPU, single-GPU, two-process CPU DDP, and two-GPU DDP. It logs rank-dependent values with
sync_dist_op="sum"andreduce_fx="max", verifying the two reduction stages produce the expected metric.Validation:
python -m pytest -q tests/tests_pytorch/trainer/logging_/test_train_loop_logging.py::test_logging_sync_dist_true(4 passed)CUDA_VISIBLE_DEVICES= python -m pytest -q tests/tests_pytorch/core/test_results.py tests/tests_pytorch/trainer/logging_/test_train_loop_logging.py(31 passed, 4 skipped)PL_RUN_STANDALONE_TESTS=1 python -m pytest -q tests/tests_pytorch/strategies/test_ddp_integration.py::test_ddp_gradients_synced[...](all four automatic/manual and static/non-static variants passed when run individually)ruff checkandruff format --checkon the changed Python filesmypyon the changed source filesuv build --offline --wheelfor thepytorchpackageAI assistance disclosure: AI tools assisted with implementation and test preparation. The contributor reviewed the complete diff and validated the change on CPU and GPU.
Fixes #17831
No breaking changes are intended. The default distributed reduction remains unchanged.
Before submitting
strategy.reducevsreduce_fx#17831.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