Skip to content

[c10d][nccl2] Record a split child's world ranks and stop it borrowing commName - #192115

Closed
tushar00jain wants to merge 5 commits into
gh/tushar00jain/12/basefrom
gh/tushar00jain/12/head
Closed

tushar00jain wants to merge 5 commits into
gh/tushar00jain/12/basefrom
gh/tushar00jain/12/head

Conversation

@tushar00jain

@tushar00jain tushar00jain commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Summary:
nccl2's split() copies the parent's timeout, config, group name, group
description and abort policy into the child's Options, but never records the
child's membership in world-rank terms. Stock ProcessGroupNCCL::split() fills
global_ranks_in_group; nccl2 left it empty.

nccl2 never reads that map itself, and get_process_group_ranks() does not go
through it, so this is observability fidelity rather than a correctness bug.
The one consumer is the opt-in FlightRecorderHook, which falls back to identity
ranks when the map is absent -- so a child group's recorded membership claimed
world ranks it does not contain. A second-level split was worse: the ranks it
was handed are indices into the parent, so without the parent's map there is
nothing to resolve them against.

The child now maps each requested rank through this group's own
global_ranks_in_group rather than the Options it was passed. That distinction
matters after the per-backend Options change earlier in this stack ("Give each
backend its own Options when splitting or merging a process group"): the
Options reaching split() is a clone owned by the caller, while the live map
belongs to the group. An empty map means "spans the world in rank order", and
a merged group inherits its parent's shorter map, so a map shorter than
getSize() is treated the same way instead of being indexed out of bounds --
the same read that the NCCL split fix earlier in this stack closed.

Second, smaller change in the same function. config.commName was assigned
name.c_str() and then stored into the child's Options, leaving the child
holding a pointer that outlives the string it borrows. This is latent, not
live: every consumer of a stored config assigns commName from a live string
before handing it to NCCL -- createNcclComm(), reconfigure(), and split()
itself -- and populateNcclConfigFromHints() borrows from the caller's live
hints map rather than from a stored one. Storing nullptr records what the
child actually owns instead of a pointer that happens never to be read.

Both are nccl2's own defects. Stock is unaffected: its split() already records
the rank map, and it does not stash a borrowed commName.

Test Plan:
test_split_group_child_global_ranks in test/distributed/test_c10d_nccl2.py
(requires_nccl, 2 GPUs) splits a 2-rank world into halves and asserts:

python test/distributed/test_c10d_nccl2.py
ProcessGroupNCCL2ObservabilityTest.test_split_group_child_global_ranks -v

  • the child's global_ranks_in_group is its own half's world ranks
  • a second-level split maps through the parent: the grandchild reports
    [self.rank], which the identity fallback would report as [0]
  • config.comm_name is not stored on the child
  • an all_reduce on the child still produces sum(halves), i.e. the added
    bookkeeping does not disturb the communicator

Pre-fix the first assertion fails with "mismatch: 0 != 2".

Recorded suite runs with this change present:

test_c10d_nccl2.py Ran 24 tests OK
test_c10d_nccl.py Ran 285 tests OK (skipped=15)

Authored with the assistance of an AI coding agent.

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Aug 4, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/192115

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 77aef85 with merge base dac77b5 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

[ghstack-poisoned]
tushar00jain added a commit that referenced this pull request Aug 4, 2026
…g commName

Summary:
nccl2's split() copies the parent's timeout, config, group name, group
description and abort policy into the child's Options, but never records the
child's membership in world-rank terms. Stock ProcessGroupNCCL::split() fills
global_ranks_in_group; nccl2 left it empty.

nccl2 never reads that map itself, and get_process_group_ranks() does not go
through it, so this is observability fidelity rather than a correctness bug.
The one consumer is the opt-in FlightRecorderHook, which falls back to identity
ranks when the map is absent -- so a child group's recorded membership claimed
world ranks it does not contain. A second-level split was worse: the ranks it
was handed are indices into the parent, so without the parent's map there is
nothing to resolve them against.

The child now maps each requested rank through *this* group's own
global_ranks_in_group rather than the Options it was passed. That distinction
matters after the per-backend Options change earlier in this stack ("Give each
backend its own Options when splitting or merging a process group"): the
Options reaching split() is a clone owned by the caller, while the live map
belongs to the group. An empty map means "spans the world in rank order", and
a merged group inherits its parent's shorter map, so a map shorter than
getSize() is treated the same way instead of being indexed out of bounds --
the same read that the NCCL split fix earlier in this stack closed.

Second, smaller change in the same function. config.commName was assigned
name.c_str() and then stored into the child's Options, leaving the child
holding a pointer that outlives the string it borrows. This is latent, not
live: every consumer of a stored config assigns commName from a live string
before handing it to NCCL -- createNcclComm(), reconfigure(), and split()
itself -- and populateNcclConfigFromHints() borrows from the caller's live
hints map rather than from a stored one. Storing nullptr records what the
child actually owns instead of a pointer that happens never to be read.

Both are nccl2's own defects. Stock is unaffected: its split() already records
the rank map, and it does not stash a borrowed commName.

Test Plan:
test_split_group_child_global_ranks in test/distributed/test_c10d_nccl2.py
(requires_nccl, 2 GPUs) splits a 2-rank world into halves and asserts:

  python test/distributed/test_c10d_nccl2.py \
    ProcessGroupNCCL2ObservabilityTest.test_split_group_child_global_ranks -v

  - the child's global_ranks_in_group is its own half's world ranks
  - a second-level split maps through the parent: the grandchild reports
    [self.rank], which the identity fallback would report as [0]
  - config.comm_name is not stored on the child
  - an all_reduce on the child still produces sum(halves), i.e. the added
    bookkeeping does not disturb the communicator

Pre-fix the first assertion fails with "mismatch: 0 != 2".

Recorded suite runs with this change present:

  test_c10d_nccl2.py   Ran 24 tests    OK
  test_c10d_nccl.py    Ran 285 tests   OK (skipped=15)

Authored with the assistance of an AI coding agent.


ghstack-source-id: 9d2e831
Pull-Request: #192115

@d4l3k d4l3k left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approving due to switching to ghstack from sl

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@tushar00jain

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Aug 5, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your 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

Advanced Debugging
Check the merge workflow status
here

ankitbhrdwj pushed a commit to ankitbhrdwj/pytorch that referenced this pull request Aug 12, 2026
…g commName (pytorch#192115)

Summary:
nccl2's split() copies the parent's timeout, config, group name, group
description and abort policy into the child's Options, but never records the
child's membership in world-rank terms. Stock ProcessGroupNCCL::split() fills
global_ranks_in_group; nccl2 left it empty.

nccl2 never reads that map itself, and get_process_group_ranks() does not go
through it, so this is observability fidelity rather than a correctness bug.
The one consumer is the opt-in FlightRecorderHook, which falls back to identity
ranks when the map is absent -- so a child group's recorded membership claimed
world ranks it does not contain. A second-level split was worse: the ranks it
was handed are indices into the parent, so without the parent's map there is
nothing to resolve them against.

The child now maps each requested rank through *this* group's own
global_ranks_in_group rather than the Options it was passed. That distinction
matters after the per-backend Options change earlier in this stack ("Give each
backend its own Options when splitting or merging a process group"): the
Options reaching split() is a clone owned by the caller, while the live map
belongs to the group. An empty map means "spans the world in rank order", and
a merged group inherits its parent's shorter map, so a map shorter than
getSize() is treated the same way instead of being indexed out of bounds --
the same read that the NCCL split fix earlier in this stack closed.

Second, smaller change in the same function. config.commName was assigned
name.c_str() and then stored into the child's Options, leaving the child
holding a pointer that outlives the string it borrows. This is latent, not
live: every consumer of a stored config assigns commName from a live string
before handing it to NCCL -- createNcclComm(), reconfigure(), and split()
itself -- and populateNcclConfigFromHints() borrows from the caller's live
hints map rather than from a stored one. Storing nullptr records what the
child actually owns instead of a pointer that happens never to be read.

Both are nccl2's own defects. Stock is unaffected: its split() already records
the rank map, and it does not stash a borrowed commName.

Test Plan:
test_split_group_child_global_ranks in test/distributed/test_c10d_nccl2.py
(requires_nccl, 2 GPUs) splits a 2-rank world into halves and asserts:

  python test/distributed/test_c10d_nccl2.py \
    ProcessGroupNCCL2ObservabilityTest.test_split_group_child_global_ranks -v

  - the child's global_ranks_in_group is its own half's world ranks
  - a second-level split maps through the parent: the grandchild reports
    [self.rank], which the identity fallback would report as [0]
  - config.comm_name is not stored on the child
  - an all_reduce on the child still produces sum(halves), i.e. the added
    bookkeeping does not disturb the communicator

Pre-fix the first assertion fails with "mismatch: 0 != 2".

Recorded suite runs with this change present:

  test_c10d_nccl2.py   Ran 24 tests    OK
  test_c10d_nccl.py    Ran 285 tests   OK (skipped=15)

Authored with the assistance of an AI coding agent.
Pull Request resolved: pytorch#192115
Approved by: https://github.com/d4l3k
ghstack dependencies: pytorch#192114
@github-actions
github-actions Bot deleted the gh/tushar00jain/12/head branch October 31, 2026 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged release notes: distributed (c10d) release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants