Skip to content

[c10d] Tests for the flight recorder hook - #192837

Closed
tushar00jain wants to merge 2 commits into
gh/tushar00jain/16/basefrom
gh/tushar00jain/16/head
Closed

tushar00jain wants to merge 2 commits into
gh/tushar00jain/16/basefrom
gh/tushar00jain/16/head

Conversation

@tushar00jain

@tushar00jain tushar00jain commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Tests for the commit below this one, split out to keep each PR under the 2000 LOC
review limit. They do not stand alone -- the implementation is in that commit.

test_c10d_fr_hook.py is the bulk, parameterized over a backend that pushes
completion (nccl2) and one that does not (fake), so both tiers are covered: the
pushed path gets a real device duration and reaches "completed", the fallback
retires at issue with neither. The gloo cases assert the hook records nothing,
since ProcessGroupGloo records itself and a second recording would duplicate
every collective.

The ones worth knowing about, because they encode properties rather than
behaviour:

  • a hung collective must read not-completed, and flip to completed once the peer
    arrives. This is the property the whole feature exists for, so it is a test and
    not just a drill.
  • an op still in flight must not report completed. Driven deterministically by
    making the backend throw between the pre- and post-hook rather than by timing.
  • recording inside torch.cuda.graph must not invalidate the capture.
  • a subgroup on a backend with no rank mapping must publish neither ranks nor a
    process-wide rank, since a fabricated one collides dump filenames.
  • hook-produced entries must survive the real analyzer: test_fr_analysis.py runs
    build_db over hook-shaped entries for the in-place and list-form collectives,
    with negative cases so the list-form allowance cannot silently accept anything.

Test Plan:

python test/distributed/test_c10d_fr_hook.py -v
python test/distributed/test_c10d_nccl2.py -v
python test/distributed/flight_recorder/test_fr_analysis.py
python test/distributed/elastic/test_control_plane.py

Results are quoted in the implementation commit's message; these files are the
tests that produced them.

Authored with the assistance of an AI coding agent.

[ghstack-poisoned]
@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label Aug 10, 2026
@pytorch-bot

pytorch-bot Bot commented Aug 10, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

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

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

tushar00jain added a commit that referenced this pull request Aug 10, 2026
Tests for the commit below this one, split out to keep each PR under the 2000 LOC
review limit. They do not stand alone -- the implementation is in that commit.

test_c10d_fr_hook.py is the bulk, parameterized over a backend that pushes
completion (nccl2) and one that does not (fake), so both tiers are covered: the
pushed path gets a real device duration and reaches "completed", the fallback
retires at issue with neither. The gloo cases assert the hook records nothing,
since ProcessGroupGloo records itself and a second recording would duplicate
every collective.

The ones worth knowing about, because they encode properties rather than
behaviour:

- a hung collective must read not-completed, and flip to completed once the peer
  arrives. This is the property the whole feature exists for, so it is a test and
  not just a drill.
- an op still in flight must not report completed. Driven deterministically by
  making the backend throw between the pre- and post-hook rather than by timing.
- recording inside torch.cuda.graph must not invalidate the capture.
- a subgroup on a backend with no rank mapping must publish neither ranks nor a
  process-wide rank, since a fabricated one collides dump filenames.
- hook-produced entries must survive the real analyzer: test_fr_analysis.py runs
  build_db over hook-shaped entries for the in-place and list-form collectives,
  with negative cases so the list-form allowance cannot silently accept anything.

Test Plan:

```
python test/distributed/test_c10d_fr_hook.py -v
python test/distributed/test_c10d_nccl2.py -v
python test/distributed/flight_recorder/test_fr_analysis.py
python test/distributed/elastic/test_control_plane.py
```

Results are quoted in the implementation commit's message; these files are the
tests that produced them.

Authored with the assistance of an AI coding agent.


ghstack-source-id: 1737789
Pull-Request: #192837
tushar00jain added a commit that referenced this pull request Aug 10, 2026
Tests for the commit below this one, split out to keep each PR under the 2000 LOC
review limit. They do not stand alone -- the implementation is in that commit.

test_c10d_fr_hook.py is the bulk, parameterized over a backend that pushes
completion (nccl2) and one that does not (fake), so both tiers are covered: the
pushed path gets a real device duration and reaches "completed", the fallback
retires at issue with neither. The gloo cases assert the hook records nothing,
since ProcessGroupGloo records itself and a second recording would duplicate
every collective.

The ones worth knowing about, because they encode properties rather than
behaviour:

- a hung collective must read not-completed, and flip to completed once the peer
  arrives. This is the property the whole feature exists for, so it is a test and
  not just a drill.
- an op still in flight must not report completed. Driven deterministically by
  making the backend throw between the pre- and post-hook rather than by timing.
- recording inside torch.cuda.graph must not invalidate the capture.
- a subgroup on a backend with no rank mapping must publish neither ranks nor a
  process-wide rank, since a fabricated one collides dump filenames.
- hook-produced entries must survive the real analyzer: test_fr_analysis.py runs
  build_db over hook-shaped entries for the in-place and list-form collectives,
  with negative cases so the list-form allowance cannot silently accept anything.

Test Plan:

```
python test/distributed/test_c10d_fr_hook.py -v
python test/distributed/test_c10d_nccl2.py -v
python test/distributed/flight_recorder/test_fr_analysis.py
python test/distributed/elastic/test_control_plane.py
```

Results are quoted in the implementation commit's message; these files are the
tests that produced them.

Authored with the assistance of an AI coding agent.


ghstack-source-id: 1737789
Pull-Request: #192837
tushar00jain added a commit that referenced this pull request Aug 10, 2026
Tests for the commit below this one, split out to keep each PR under the 2000 LOC
review limit. They do not stand alone -- the implementation is in that commit.

test_c10d_fr_hook.py is the bulk, parameterized over a backend that pushes
completion (nccl2) and one that does not (fake), so both tiers are covered: the
pushed path gets a real device duration and reaches "completed", the fallback
retires at issue with neither. The gloo cases assert the hook records nothing,
since ProcessGroupGloo records itself and a second recording would duplicate
every collective.

The ones worth knowing about, because they encode properties rather than
behaviour:

- a hung collective must read not-completed, and flip to completed once the peer
  arrives. This is the property the whole feature exists for, so it is a test and
  not just a drill.
- an op still in flight must not report completed. Driven deterministically by
  making the backend throw between the pre- and post-hook rather than by timing.
- recording inside torch.cuda.graph must not invalidate the capture.
- a subgroup on a backend with no rank mapping must publish neither ranks nor a
  process-wide rank, since a fabricated one collides dump filenames.
- hook-produced entries must survive the real analyzer: test_fr_analysis.py runs
  build_db over hook-shaped entries for the in-place and list-form collectives,
  with negative cases so the list-form allowance cannot silently accept anything.

Test Plan:

```
python test/distributed/test_c10d_fr_hook.py -v
python test/distributed/test_c10d_nccl2.py -v
python test/distributed/flight_recorder/test_fr_analysis.py
python test/distributed/elastic/test_control_plane.py
```

Results are quoted in the implementation commit's message; these files are the
tests that produced them.

Authored with the assistance of an AI coding agent.


ghstack-source-id: 1737789
Pull-Request: #192837
[ghstack-poisoned]
tushar00jain added a commit that referenced this pull request Aug 10, 2026
Tests for the commit below this one, split out to keep each PR under the 2000 LOC
review limit. They do not stand alone -- the implementation is in that commit.

test_c10d_fr_hook.py is the bulk, parameterized over a backend that pushes
completion (nccl2) and one that does not (fake), so both tiers are covered: the
pushed path gets a real device duration and reaches "completed", the fallback
retires at issue with neither. The gloo cases assert the hook records nothing,
since ProcessGroupGloo records itself and a second recording would duplicate
every collective.

The ones worth knowing about, because they encode properties rather than
behaviour:

- a hung collective must read not-completed, and flip to completed once the peer
  arrives. This is the property the whole feature exists for, so it is a test and
  not just a drill.
- an op still in flight must not report completed. Driven deterministically by
  making the backend throw between the pre- and post-hook rather than by timing.
- recording inside torch.cuda.graph must not invalidate the capture.
- a subgroup on a backend with no rank mapping must publish neither ranks nor a
  process-wide rank, since a fabricated one collides dump filenames.
- hook-produced entries must survive the real analyzer: test_fr_analysis.py runs
  build_db over hook-shaped entries for the in-place and list-form collectives,
  with negative cases so the list-form allowance cannot silently accept anything.

Test Plan:

```
python test/distributed/test_c10d_fr_hook.py -v
python test/distributed/test_c10d_nccl2.py -v
python test/distributed/flight_recorder/test_fr_analysis.py
python test/distributed/elastic/test_control_plane.py
```

Results are quoted in the implementation commit's message; these files are the
tests that produced them.

Authored with the assistance of an AI coding agent.

ghstack-source-id: 1737789
Pull-Request: #192837

@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.

LGTM

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Starting merge as part of PR stack under #192858

2 similar comments
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Starting merge as part of PR stack under #192858

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Starting merge as part of PR stack under #192858

pytorchmergebot pushed a commit that referenced this pull request Aug 11, 2026
…mpletion race (#192858)

Two defects in the flight recorder, found in review. Separate from the commits
below only because they do not fit inside the 2000 LOC review limit.

The backend string "nccl" had two sources of truth for what it builds, and only
one of them read TORCH_DIST_USE_NCCL2. _register_builtin_nccl_backend picks its
creator from that flag; _FR_SELF_RECORDING_BACKENDS hard-coded Backend.NCCL as
self-recording regardless. They agree today by luck, because the flag defaults
off and "nccl" builds stock ProcessGroupNCCL, which does record natively. The
moment the default flips, "nccl" builds nccl2 and the flight recorder skips it as
self-recording -- so the default path loses the feature entirely, and silently.
Existing tests never caught it because they all request "nccl2" explicitly.

Rather than special-case the name, the registration now records what it actually
built: the set is derived from the creator that was chosen, keyed off creator
identity rather than re-reading the env, so flipping the default is still a
one-line change to the existing ternary and there is no second site to keep in
sync. Ordering holds because _ensure_backend_registered runs well before the
attach decision, for both new_group and split_group. "nccl-legacy" is added to
the set for the same reason -- it builds stock, so the hook it was getting could
never record anything.

The second is a race. A completion is delivered with the Work, and the hook can
only map a Work to its trace entry from the post-hook, which is the one place
op_id and the Work are both visible. A fast collective can be completed by the
backend's watchdog after it is enqueued but before that post-hook runs, and the
callback was then dropped on the floor -- leaving a healthy op unretired and
reading "scheduled" forever, which is precisely the false hang signal this
feature exists to rule out.

A completion that arrives early is no longer a special case. The post-hook, once
it has registered the mapping, simply asks the Work whether it already finished
successfully and retires it if so. There is then no interval in which a
completion can be missed: if it landed before registration this catches it, and
if after, the callback finds the mapping.

Retirement is claiming rather than checking, so it happens exactly once however
the two interleave -- the lookup and both erases happen under one lock, and the
loser takes the same early return a Work that was never ours would. An earlier
version of this fix stashed early completions keyed by Work* and replayed them,
bounded three ways. That was a workaround: Work* is not a stable identity, since
the allocator can reuse the address once the original is destroyed, and a stale
entry would then report a *different* op as completed while it was still in
flight -- a false "completed", which is worse than the false "hang" being fixed.
The bounds only shrank the window in which the key could lie.

One consequence worth knowing: asking the Work also advances its status, so a
short healthy collective now usually retires on the issuing thread rather than
from the watchdog push, and pays one event query per op on the issue path.

Hook maps become ordered so hooks fire by id. That is what lets the race be
tested deterministically rather than with a sleep, and the flight recorder hook's
id already assumed ordering against user hooks.

Test Plan:

The race test does not sleep. A user post-hook with a lower id holds the window
open and, inside it, issues a sentinel collective behind the target on the same
stream queue; nccl2 pops that queue in order, so a retired sentinel proves the
target's completion was already delivered. It then asserts the target is not yet
retired -- i.e. the race really occurred -- and that it is retired, completed and
still carries a duration once the post-hook returns. Without the fix the last
assertion fails, since the completion fires once per Work and no second one is
coming.

The attach test asserts on what was built rather than on the env var, so it holds
either side of the default flip.

```
python test/distributed/test_c10d_fr_hook.py
python test/distributed/test_c10d_nccl2.py
python test/distributed/test_c10d_nccl.py NCCLTraceTest
python test/distributed/flight_recorder/test_fr_analysis.py
python test/distributed/test_c10d_hooks.py
python test/distributed/test_c10d_nan_check.py
```
```
Ran 63 tests in 323.043s  OK (skipped=9)
Ran 50 tests in 345.898s  OK (skipped=1)
Ran 61 tests in 496.705s  OK
Ran 23 tests in   1.790s  OK
Ran  2 tests in   7.803s  OK
Ran 20 tests in 102.351s  OK
```
The last two cover the other consumers of the hook plumbing whose map ordering
changed.

lintrunner --revision HEAD: clean.

Authored with the assistance of an AI coding agent.
Pull Request resolved: #192858
Approved by: https://github.com/d4l3k
ghstack dependencies: #192233, #192837
ankitbhrdwj pushed a commit to ankitbhrdwj/pytorch that referenced this pull request Aug 12, 2026
Tests for the commit below this one, split out to keep each PR under the 2000 LOC
review limit. They do not stand alone -- the implementation is in that commit.

test_c10d_fr_hook.py is the bulk, parameterized over a backend that pushes
completion (nccl2) and one that does not (fake), so both tiers are covered: the
pushed path gets a real device duration and reaches "completed", the fallback
retires at issue with neither. The gloo cases assert the hook records nothing,
since ProcessGroupGloo records itself and a second recording would duplicate
every collective.

The ones worth knowing about, because they encode properties rather than
behaviour:

- a hung collective must read not-completed, and flip to completed once the peer
  arrives. This is the property the whole feature exists for, so it is a test and
  not just a drill.
- an op still in flight must not report completed. Driven deterministically by
  making the backend throw between the pre- and post-hook rather than by timing.
- recording inside torch.cuda.graph must not invalidate the capture.
- a subgroup on a backend with no rank mapping must publish neither ranks nor a
  process-wide rank, since a fabricated one collides dump filenames.
- hook-produced entries must survive the real analyzer: test_fr_analysis.py runs
  build_db over hook-shaped entries for the in-place and list-form collectives,
  with negative cases so the list-form allowance cannot silently accept anything.

Test Plan:

```
python test/distributed/test_c10d_fr_hook.py -v
python test/distributed/test_c10d_nccl2.py -v
python test/distributed/flight_recorder/test_fr_analysis.py
python test/distributed/elastic/test_control_plane.py
```

Results are quoted in the implementation commit's message; these files are the
tests that produced them.

Authored with the assistance of an AI coding agent.
Pull Request resolved: pytorch#192837
Approved by: https://github.com/d4l3k
ghstack dependencies: pytorch#192233
ankitbhrdwj pushed a commit to ankitbhrdwj/pytorch that referenced this pull request Aug 12, 2026
…mpletion race (pytorch#192858)

Two defects in the flight recorder, found in review. Separate from the commits
below only because they do not fit inside the 2000 LOC review limit.

The backend string "nccl" had two sources of truth for what it builds, and only
one of them read TORCH_DIST_USE_NCCL2. _register_builtin_nccl_backend picks its
creator from that flag; _FR_SELF_RECORDING_BACKENDS hard-coded Backend.NCCL as
self-recording regardless. They agree today by luck, because the flag defaults
off and "nccl" builds stock ProcessGroupNCCL, which does record natively. The
moment the default flips, "nccl" builds nccl2 and the flight recorder skips it as
self-recording -- so the default path loses the feature entirely, and silently.
Existing tests never caught it because they all request "nccl2" explicitly.

Rather than special-case the name, the registration now records what it actually
built: the set is derived from the creator that was chosen, keyed off creator
identity rather than re-reading the env, so flipping the default is still a
one-line change to the existing ternary and there is no second site to keep in
sync. Ordering holds because _ensure_backend_registered runs well before the
attach decision, for both new_group and split_group. "nccl-legacy" is added to
the set for the same reason -- it builds stock, so the hook it was getting could
never record anything.

The second is a race. A completion is delivered with the Work, and the hook can
only map a Work to its trace entry from the post-hook, which is the one place
op_id and the Work are both visible. A fast collective can be completed by the
backend's watchdog after it is enqueued but before that post-hook runs, and the
callback was then dropped on the floor -- leaving a healthy op unretired and
reading "scheduled" forever, which is precisely the false hang signal this
feature exists to rule out.

A completion that arrives early is no longer a special case. The post-hook, once
it has registered the mapping, simply asks the Work whether it already finished
successfully and retires it if so. There is then no interval in which a
completion can be missed: if it landed before registration this catches it, and
if after, the callback finds the mapping.

Retirement is claiming rather than checking, so it happens exactly once however
the two interleave -- the lookup and both erases happen under one lock, and the
loser takes the same early return a Work that was never ours would. An earlier
version of this fix stashed early completions keyed by Work* and replayed them,
bounded three ways. That was a workaround: Work* is not a stable identity, since
the allocator can reuse the address once the original is destroyed, and a stale
entry would then report a *different* op as completed while it was still in
flight -- a false "completed", which is worse than the false "hang" being fixed.
The bounds only shrank the window in which the key could lie.

One consequence worth knowing: asking the Work also advances its status, so a
short healthy collective now usually retires on the issuing thread rather than
from the watchdog push, and pays one event query per op on the issue path.

Hook maps become ordered so hooks fire by id. That is what lets the race be
tested deterministically rather than with a sleep, and the flight recorder hook's
id already assumed ordering against user hooks.

Test Plan:

The race test does not sleep. A user post-hook with a lower id holds the window
open and, inside it, issues a sentinel collective behind the target on the same
stream queue; nccl2 pops that queue in order, so a retired sentinel proves the
target's completion was already delivered. It then asserts the target is not yet
retired -- i.e. the race really occurred -- and that it is retired, completed and
still carries a duration once the post-hook returns. Without the fix the last
assertion fails, since the completion fires once per Work and no second one is
coming.

The attach test asserts on what was built rather than on the env var, so it holds
either side of the default flip.

```
python test/distributed/test_c10d_fr_hook.py
python test/distributed/test_c10d_nccl2.py
python test/distributed/test_c10d_nccl.py NCCLTraceTest
python test/distributed/flight_recorder/test_fr_analysis.py
python test/distributed/test_c10d_hooks.py
python test/distributed/test_c10d_nan_check.py
```
```
Ran 63 tests in 323.043s  OK (skipped=9)
Ran 50 tests in 345.898s  OK (skipped=1)
Ran 61 tests in 496.705s  OK
Ran 23 tests in   1.790s  OK
Ran  2 tests in   7.803s  OK
Ran 20 tests in 102.351s  OK
```
The last two cover the other consumers of the hook plumbing whose map ordering
changed.

lintrunner --revision HEAD: clean.

Authored with the assistance of an AI coding agent.
Pull Request resolved: pytorch#192858
Approved by: https://github.com/d4l3k
ghstack dependencies: pytorch#192233, pytorch#192837
gavinwang269 pushed a commit to gavinwang269/pytorch that referenced this pull request Aug 13, 2026
Tests for the commit below this one, split out to keep each PR under the 2000 LOC
review limit. They do not stand alone -- the implementation is in that commit.

test_c10d_fr_hook.py is the bulk, parameterized over a backend that pushes
completion (nccl2) and one that does not (fake), so both tiers are covered: the
pushed path gets a real device duration and reaches "completed", the fallback
retires at issue with neither. The gloo cases assert the hook records nothing,
since ProcessGroupGloo records itself and a second recording would duplicate
every collective.

The ones worth knowing about, because they encode properties rather than
behaviour:

- a hung collective must read not-completed, and flip to completed once the peer
  arrives. This is the property the whole feature exists for, so it is a test and
  not just a drill.
- an op still in flight must not report completed. Driven deterministically by
  making the backend throw between the pre- and post-hook rather than by timing.
- recording inside torch.cuda.graph must not invalidate the capture.
- a subgroup on a backend with no rank mapping must publish neither ranks nor a
  process-wide rank, since a fabricated one collides dump filenames.
- hook-produced entries must survive the real analyzer: test_fr_analysis.py runs
  build_db over hook-shaped entries for the in-place and list-form collectives,
  with negative cases so the list-form allowance cannot silently accept anything.

Test Plan:

```
python test/distributed/test_c10d_fr_hook.py -v
python test/distributed/test_c10d_nccl2.py -v
python test/distributed/flight_recorder/test_fr_analysis.py
python test/distributed/elastic/test_control_plane.py
```

Results are quoted in the implementation commit's message; these files are the
tests that produced them.

Authored with the assistance of an AI coding agent.
Pull Request resolved: pytorch#192837
Approved by: https://github.com/d4l3k
ghstack dependencies: pytorch#192233
gavinwang269 pushed a commit to gavinwang269/pytorch that referenced this pull request Aug 13, 2026
…mpletion race (pytorch#192858)

Two defects in the flight recorder, found in review. Separate from the commits
below only because they do not fit inside the 2000 LOC review limit.

The backend string "nccl" had two sources of truth for what it builds, and only
one of them read TORCH_DIST_USE_NCCL2. _register_builtin_nccl_backend picks its
creator from that flag; _FR_SELF_RECORDING_BACKENDS hard-coded Backend.NCCL as
self-recording regardless. They agree today by luck, because the flag defaults
off and "nccl" builds stock ProcessGroupNCCL, which does record natively. The
moment the default flips, "nccl" builds nccl2 and the flight recorder skips it as
self-recording -- so the default path loses the feature entirely, and silently.
Existing tests never caught it because they all request "nccl2" explicitly.

Rather than special-case the name, the registration now records what it actually
built: the set is derived from the creator that was chosen, keyed off creator
identity rather than re-reading the env, so flipping the default is still a
one-line change to the existing ternary and there is no second site to keep in
sync. Ordering holds because _ensure_backend_registered runs well before the
attach decision, for both new_group and split_group. "nccl-legacy" is added to
the set for the same reason -- it builds stock, so the hook it was getting could
never record anything.

The second is a race. A completion is delivered with the Work, and the hook can
only map a Work to its trace entry from the post-hook, which is the one place
op_id and the Work are both visible. A fast collective can be completed by the
backend's watchdog after it is enqueued but before that post-hook runs, and the
callback was then dropped on the floor -- leaving a healthy op unretired and
reading "scheduled" forever, which is precisely the false hang signal this
feature exists to rule out.

A completion that arrives early is no longer a special case. The post-hook, once
it has registered the mapping, simply asks the Work whether it already finished
successfully and retires it if so. There is then no interval in which a
completion can be missed: if it landed before registration this catches it, and
if after, the callback finds the mapping.

Retirement is claiming rather than checking, so it happens exactly once however
the two interleave -- the lookup and both erases happen under one lock, and the
loser takes the same early return a Work that was never ours would. An earlier
version of this fix stashed early completions keyed by Work* and replayed them,
bounded three ways. That was a workaround: Work* is not a stable identity, since
the allocator can reuse the address once the original is destroyed, and a stale
entry would then report a *different* op as completed while it was still in
flight -- a false "completed", which is worse than the false "hang" being fixed.
The bounds only shrank the window in which the key could lie.

One consequence worth knowing: asking the Work also advances its status, so a
short healthy collective now usually retires on the issuing thread rather than
from the watchdog push, and pays one event query per op on the issue path.

Hook maps become ordered so hooks fire by id. That is what lets the race be
tested deterministically rather than with a sleep, and the flight recorder hook's
id already assumed ordering against user hooks.

Test Plan:

The race test does not sleep. A user post-hook with a lower id holds the window
open and, inside it, issues a sentinel collective behind the target on the same
stream queue; nccl2 pops that queue in order, so a retired sentinel proves the
target's completion was already delivered. It then asserts the target is not yet
retired -- i.e. the race really occurred -- and that it is retired, completed and
still carries a duration once the post-hook returns. Without the fix the last
assertion fails, since the completion fires once per Work and no second one is
coming.

The attach test asserts on what was built rather than on the env var, so it holds
either side of the default flip.

```
python test/distributed/test_c10d_fr_hook.py
python test/distributed/test_c10d_nccl2.py
python test/distributed/test_c10d_nccl.py NCCLTraceTest
python test/distributed/flight_recorder/test_fr_analysis.py
python test/distributed/test_c10d_hooks.py
python test/distributed/test_c10d_nan_check.py
```
```
Ran 63 tests in 323.043s  OK (skipped=9)
Ran 50 tests in 345.898s  OK (skipped=1)
Ran 61 tests in 496.705s  OK
Ran 23 tests in   1.790s  OK
Ran  2 tests in   7.803s  OK
Ran 20 tests in 102.351s  OK
```
The last two cover the other consumers of the hook plumbing whose map ordering
changed.

lintrunner --revision HEAD: clean.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants