Repository navigation
[c10d] FakeProcessGroup: match NCCL's version-counter effect on collective outputs (#201606) - #201606
stanley-shi wants to merge 1 commit into
Conversation
|
This appears to be a diff that was exported from phabricator, but the PR author does not have sufficient permissions to run CI. @stanley-shi, please do step 2 of internal wiki to get write access so you do not need to get CI approvals in the future. If you think this is a mistake, please contact the Pytorch Dev Infra team. |
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". ✅ AUTOMATED REVIEW - Ready for human review:
Reviewed commit: 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/201606
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit f3f3103 with merge base 289f49d ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
|
|
@stanley-shi has exported this pull request. If you are a Meta employee, you can view the originating Diff in D126530628. |
|
@stanley-shi has imported this pull request. If you are a Meta employee, you can view this in D126530628. |
|
/easycla |
ezyang
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
354a3fe to
c422f78
Compare
…ctive outputs (pytorch#201606) Summary: `FakeProcessGroup`'s collectives fill caller-owned outputs with `copy_()` under `at::AutoDispatchBelowAutograd`. That guard skips the Autograd key but not ADInplaceOrView, so every write bumps the output's version counter: `all_gather_into_tensor` into a fresh tensor goes from version 0 to `world_size`. On NCCL it stays at 0, because NCCL writes from its own kernels. This breaks any tensor that autograd saved for backward and a collective then refills. TorchRec's fully sharded 2D embedding (`ShardedBatchedFusedEmbeddingBag`) reduce-scatters a TBE's `weights_dev` after forward and all-gathers it back into the same tensor before backward, so under FakePG the TBE backward fails with `modified by an inplace operation: ... is at version 2; expected version 0`. Every Ads 2D-sparse training run under FakePG dies at its first backward. The fix matches ProcessGroupNCCL collective by collective (NOTE [FakeProcessGroup output version counters]): - Outputs NCCL writes from its kernels (`all_gather_into_tensor` and its coalesced form, the reduce-scatters, the all-to-alls, the all-reduces) now use `AutoDispatchBelowADInplaceOrView` and leave the counter alone. - Outputs NCCL fills with `copy_` (each slot of list `all_gather`, the root's `scatter` output, the root's own `gather` slot) keep `AutoDispatchBelowAutograd` and still bump. Peers' `gather` slots arrive by `ncclRecv` and no longer bump. - `allgather_coalesced` is unchanged; ProcessGroupNCCL does not implement it. ## Agent details (AI-generated) The diagnosis, code change and tests were drafted by an AI coding agent (Claude) working with the author. The per-collective behavior was read from `ProcessGroupNCCL.cpp` and `torch/csrc/cuda/nccl.cpp`, and checked against real NCCL on 2 GPUs during development. Per review, the tests were trimmed to one version-counter check per behavior class plus the backward regression. Test Plan: ``` buck2 test fbcode//mode/opt fbcode//caffe2/test/distributed:test_fake_pg -- --regex 'TestFakePGVersionCounter|TestFakePGUniformRanks|TestFakePG\.' ``` Pass 43, Fail 0: https://www.internalfb.com/intern/testinfra/testrun/20829148338057493 New `TestFakePGVersionCounter` (single process, CPU): - `test_output_versions_match_nccl`: `all_gather_into_tensor`, `reduce_scatter_tensor` and `all_to_all_single` leave the output at version 0; list `all_gather` bumps each slot to 1; `gather` at the root bumps only its own slot (`[1, 0, 0, 0]`). - `test_tensor_saved_for_backward_survives_all_gather_into_it`: the 2D-sparse regression; fails on the original header with "modified by an inplace operation". ``` buck2 test fbcode//mode/opt fbcode//caffe2/test/distributed:test_fake_pg -- --regex TestFakePGVersionCounter ``` https://www.internalfb.com/intern/testinfra/testrun/28710447673116028 The previous revision also verified every collective's version counter against real NCCL on 2 GPUs (`TestFakePGNCCLVersionParity`, since removed per review): the per-collective table above matched at both ranks. Reviewed By: ezyang Differential Revision: D126530628 Pulled By: stanley-shi
…ctive outputs (pytorch#201606) Summary: `FakeProcessGroup`'s collectives fill caller-owned outputs with `copy_()` under `at::AutoDispatchBelowAutograd`. That guard skips the Autograd key but not ADInplaceOrView, so every write bumps the output's version counter: `all_gather_into_tensor` into a fresh tensor goes from version 0 to `world_size`. On NCCL it stays at 0, because NCCL writes from its own kernels. This breaks any tensor that autograd saved for backward and a collective then refills. TorchRec's fully sharded 2D embedding (`ShardedBatchedFusedEmbeddingBag`) reduce-scatters a TBE's `weights_dev` after forward and all-gathers it back into the same tensor before backward, so under FakePG the TBE backward fails with `modified by an inplace operation: ... is at version 2; expected version 0`. Every Ads 2D-sparse training run under FakePG dies at its first backward. The fix matches ProcessGroupNCCL collective by collective (NOTE [FakeProcessGroup output version counters]): - Outputs NCCL writes from its kernels (`all_gather_into_tensor` and its coalesced form, the reduce-scatters, the all-to-alls, the all-reduces) now use `AutoDispatchBelowADInplaceOrView` and leave the counter alone. - Outputs NCCL fills with `copy_` (each slot of list `all_gather`, the root's `scatter` output, the root's own `gather` slot) keep `AutoDispatchBelowAutograd` and still bump. Peers' `gather` slots arrive by `ncclRecv` and no longer bump. - `allgather_coalesced` is unchanged; ProcessGroupNCCL does not implement it. ## Agent details (AI-generated) The diagnosis, code change and tests were drafted by an AI coding agent (Claude) working with the author. The per-collective behavior was read from `ProcessGroupNCCL.cpp` and `torch/csrc/cuda/nccl.cpp`, and checked against real NCCL on 2 GPUs during development. Per review, the tests were trimmed to one version-counter check per behavior class plus the backward regression. Test Plan: ``` buck2 test fbcode//mode/opt fbcode//caffe2/test/distributed:test_fake_pg -- --regex 'TestFakePGVersionCounter|TestFakePGUniformRanks|TestFakePG\.' ``` Pass 43, Fail 0: https://www.internalfb.com/intern/testinfra/testrun/20829148338057493 New `TestFakePGVersionCounter` (single process, CPU): - `test_output_versions_match_nccl`: `all_gather_into_tensor`, `reduce_scatter_tensor` and `all_to_all_single` leave the output at version 0; list `all_gather` bumps each slot to 1; `gather` at the root bumps only its own slot (`[1, 0, 0, 0]`). - `test_tensor_saved_for_backward_survives_all_gather_into_it`: the 2D-sparse regression; fails on the original header with "modified by an inplace operation". ``` buck2 test fbcode//mode/opt fbcode//caffe2/test/distributed:test_fake_pg -- --regex TestFakePGVersionCounter ``` https://www.internalfb.com/intern/testinfra/testrun/28710447673116028 The previous revision also verified every collective's version counter against real NCCL on 2 GPUs (`TestFakePGNCCLVersionParity`, since removed per review): the per-collective table above matched at both ranks. Reviewed By: ezyang Differential Revision: D126530628 Pulled By: stanley-shi
c422f78 to
f3f3103
Compare
There was a problem hiding this comment.
Automated review of f3f3103: nothing blocking; ready for human review.
The PR changes FakeProcessGroup so a collective's output version counter moves the way it does on ProcessGroupNCCL: outputs NCCL writes directly stay at version 0, while outputs filled via copy_ (list all_gather slots, the root's own scatter/gather slot) still get bumped. The review found no issues. Recommendation: Approve.
This review is AI-generated and advisory. Each new automated review replaces the previous one.
Withdrawn: the automated review of f3f3103 found nothing blocking.
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
…oc; fake registration fallback [ghstack-poisoned]
…oc; fake registration fallback [ghstack-poisoned]
…oc; fake registration fallback [ghstack-poisoned]
…ctive outputs (pytorch#201606) (pytorch#201606) Summary: `FakeProcessGroup`'s collectives fill caller-owned outputs with `copy_()` under `at::AutoDispatchBelowAutograd`. That guard skips the Autograd key but not ADInplaceOrView, so every write bumps the output's version counter: `all_gather_into_tensor` into a fresh tensor goes from version 0 to `world_size`. On NCCL it stays at 0, because NCCL writes from its own kernels. This breaks any tensor that autograd saved for backward and a collective then refills. TorchRec's fully sharded 2D embedding (`ShardedBatchedFusedEmbeddingBag`) reduce-scatters a TBE's `weights_dev` after forward and all-gathers it back into the same tensor before backward, so under FakePG the TBE backward fails with `modified by an inplace operation: ... is at version 2; expected version 0`. Every Ads 2D-sparse training run under FakePG dies at its first backward. The fix matches ProcessGroupNCCL collective by collective (NOTE [FakeProcessGroup output version counters]): - Outputs NCCL writes from its kernels (`all_gather_into_tensor` and its coalesced form, the reduce-scatters, the all-to-alls, the all-reduces) now use `AutoDispatchBelowADInplaceOrView` and leave the counter alone. - Outputs NCCL fills with `copy_` (each slot of list `all_gather`, the root's `scatter` output, the root's own `gather` slot) keep `AutoDispatchBelowAutograd` and still bump. Peers' `gather` slots arrive by `ncclRecv` and no longer bump. - `allgather_coalesced` is unchanged; ProcessGroupNCCL does not implement it. ## Agent details (AI-generated) The diagnosis, code change and tests were drafted by an AI coding agent (Claude) working with the author. The per-collective behavior was read from `ProcessGroupNCCL.cpp` and `torch/csrc/cuda/nccl.cpp`, and checked against real NCCL on 2 GPUs during development. Per review, the tests were trimmed to one version-counter check per behavior class plus the backward regression. Test Plan: ``` buck2 test fbcode//mode/opt fbcode//caffe2/test/distributed:test_fake_pg -- --regex 'TestFakePGVersionCounter|TestFakePGUniformRanks|TestFakePG\.' ``` Pass 43, Fail 0: https://www.internalfb.com/intern/testinfra/testrun/20829148338057493 New `TestFakePGVersionCounter` (single process, CPU): - `test_output_versions_match_nccl`: `all_gather_into_tensor`, `reduce_scatter_tensor` and `all_to_all_single` leave the output at version 0; list `all_gather` bumps each slot to 1; `gather` at the root bumps only its own slot (`[1, 0, 0, 0]`). - `test_tensor_saved_for_backward_survives_all_gather_into_it`: the 2D-sparse regression; fails on the original header with "modified by an inplace operation". ``` buck2 test fbcode//mode/opt fbcode//caffe2/test/distributed:test_fake_pg -- --regex TestFakePGVersionCounter ``` https://www.internalfb.com/intern/testinfra/testrun/28710447673116028 The previous revision also verified every collective's version counter against real NCCL on 2 GPUs (`TestFakePGNCCLVersionParity`, since removed per review): the per-collective table above matched at both ranks. Reviewed By: ezyang Differential Revision: D126530628 Pulled By: stanley-shi Pull Request resolved: pytorch#201606 Approved by: https://github.com/ezyang, https://github.com/d4l3k, https://github.com/kapilsh
Summary:
FakeProcessGroup's collectives fill caller-owned outputs withcopy_()underat::AutoDispatchBelowAutograd. That guard skips the Autograd key but not ADInplaceOrView, so every write bumps the output's version counter:all_gather_into_tensorinto a fresh tensor goes from version 0 toworld_size. On NCCL it stays at 0, because NCCL writes from its own kernels.This breaks any tensor that autograd saved for backward and a collective then refills. TorchRec's fully sharded 2D embedding (
ShardedBatchedFusedEmbeddingBag) reduce-scatters a TBE'sweights_devafter forward and all-gathers it back into the same tensor before backward, so under FakePG the TBE backward fails withmodified by an inplace operation: ... is at version 2; expected version 0. Every Ads 2D-sparse training run under FakePG dies at its first backward.The fix matches ProcessGroupNCCL collective by collective (NOTE [FakeProcessGroup output version counters]):
all_gather_into_tensorand its coalesced form, the reduce-scatters, the all-to-alls, the all-reduces) now useAutoDispatchBelowADInplaceOrViewand leave the counter alone.copy_(each slot of listall_gather, the root'sscatteroutput, the root's owngatherslot) keepAutoDispatchBelowAutogradand still bump. Peers'gatherslots arrive byncclRecvand no longer bump.allgather_coalescedis unchanged; ProcessGroupNCCL does not implement it.Agent details (AI-generated)
The diagnosis, code change and tests were drafted by an AI coding agent (Claude) working with the author. The per-collective behavior was read from
ProcessGroupNCCL.cppandtorch/csrc/cuda/nccl.cpp, and checked against real NCCL on 2 GPUs during development. Per review, the tests were trimmed to one version-counter check per behavior class plus the backward regression.Test Plan:
Pass 43, Fail 0: https://www.internalfb.com/intern/testinfra/testrun/20829148338057493
New
TestFakePGVersionCounter(single process, CPU):test_output_versions_match_nccl:all_gather_into_tensor,reduce_scatter_tensorandall_to_all_singleleave the output at version 0; listall_gatherbumps each slot to 1;gatherat the root bumps only its own slot ([1, 0, 0, 0]).test_tensor_saved_for_backward_survives_all_gather_into_it: the 2D-sparse regression; fails on the original header with "modified by an inplace operation".https://www.internalfb.com/intern/testinfra/testrun/28710447673116028
The previous revision also verified every collective's version counter against real NCCL on 2 GPUs (
TestFakePGNCCLVersionParity, since removed per review): the per-collective table above matched at both ranks.Reviewed By: ezyang
Differential Revision: D126530628
Pulled By: stanley-shi