Skip to content

[c10d] PyBackend: treat None options as default Backend.Options - #202194

Closed
d4l3k wants to merge 3 commits into
gh/d4l3k/302/basefrom
gh/d4l3k/302/head
Closed

d4l3k wants to merge 3 commits into
gh/d4l3k/302/basefrom
gh/d4l3k/302/head

Conversation

@d4l3k

@d4l3k d4l3k commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Stack from ghstack (oldest at bottom):

ProcessGroup::splitGroup and mergeRemoteGroup dereference Backend::getBackendOptions(). For a Python backend that comes from its options property, and when that returns None (no backend-specific options) castAndPreserve yields a null pointer and split_group / merge_remote_group crash. C++ backends with nullable options, like the C++ FakeProcessGroup, avoid this by returning fresh default options from getBackendOptions while their Python .options stays None; test_device_mesh relies on that None to tell whether an options override was supplied.

PyBackend::getBackendOptions now returns default Backend::Options named after the backend when the Python options property returns None, so Python backends can keep the same nullable .options contract. This is needed by the next PR, which moves FakeProcessGroup to Python. The alternative of making FakeProcessGroup's .options always non-None would change its observable behavior.

Test plan:

python -m pytest test/distributed/test_c10d_pybackend.py
lintrunner -a

This PR was authored with the help of an AI assistant (Claude).

…fake with entry point; review fixes

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

PR Status: Approved 🚀

Please fix all CI failures and trigger merge by commenting "@pytorchbot merge".

✅ AUTOMATED REVIEW - Ready for human review:

When a Python backend's `options` returns `None`, `PyBackend::getBackendOptions`
now returns a default `Backend::Options` named after the backend, which prevents
null dereferences in `splitGroup` and `mergeRemoteGroup`. The PR also documents
the `Backend.options` contract. Recommendation: Approve.

Reviewed commit: a4293b5

Review run

🔗 Helpful Links

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

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

✅ No Failures

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

🟡 GREEN LIGHT - PR requires human review:

  • Triviality
    • Not a plain single-cause bugfix: PyBackend::getBackendOptions now substitutes a default Options where a None options used to give a null result
    • The new options docstring in init.cpp sets a public contract for Python Backend subclasses, which is a design call for a human
  • Behavior beyond the bug
    • tryGetOptions in FlightRecorderHook.cpp used to get null for these backends; it now sets target.timeout from the default Options
  • Tests
    • The new tests in test_c10d_pybackend.py cover only the None paths through split_group and merge_remote_group, not the flight-recorder change

reason: not_trivial
Reviewed commit: a4293b5

Inference job

🐛 Report a wrong verdict

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

@pytorch-bot pytorch-bot Bot added the release notes: distributed (c10d) release notes category label Oct 27, 2026
@d4l3k
d4l3k marked this pull request as ready for review October 27, 2026 21:30
@d4l3k
d4l3k requested review from fduwjj and kapilsh as code owners October 27, 2026 21:30
@pytorchgreenlight pytorchgreenlight Bot added the GL/human GreenLight marked as needing human review label Oct 27, 2026
@pytorchbot pytorchbot added the in progress PR is being worked on by the author, until the automated review accepts it label Oct 27, 2026
github-actions[bot]

This comment was marked as outdated.

github-actions[bot]

This comment was marked as outdated.

…oc; fake registration fallback

[ghstack-poisoned]

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated review of a4293b5: nothing blocking; ready for human review.

When a Python backend's options returns None, PyBackend::getBackendOptions now returns a default Backend::Options named after the backend, which prevents null dereferences in splitGroup and mergeRemoteGroup. The PR also documents the Backend.options contract. Recommendation: Approve.

This review is AI-generated and advisory. Each new automated review replaces the previous one.

@github-actions
github-actions Bot dismissed stale reviews from themself October 27, 2026 23:27

Withdrawn: the automated review of a4293b5 found nothing blocking.

@pytorch-bot pytorch-bot Bot added ready for review Automated review passed, ready for a final review by a maintainer. and removed in progress PR is being worked on by the author, until the automated review accepts it labels Oct 28, 2026

@kapilsh kapilsh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@d4l3k

d4l3k commented Oct 28, 2026

Copy link
Copy Markdown
Member Author

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 28, 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

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: Merge rule check failed for stacked PR #202176:

2 mandatory check(s) failed. The first few are:

Dig deeper by viewing the failures on hud

Details for Dev Infra team

Raised by workflow job

Failing merge rule: Core Maintainers

@d4l3k

d4l3k commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

@pytorchbot merge

@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

d4l3k added a commit that referenced this pull request Oct 29, 2026
`FakeProcessGroup` was a C++ `c10d::Backend` subclass with every collective implemented in C++. It is a test-only backend, and keeping it in C++ meant every semantic change (uniform-rank simulation, split support, size checks) required a C++ rebuild and duplicated logic that is easier to read and extend in Python. With `dist.BackendBase` now subclassable from Python via the PyBackend trampoline, the backend can live in Python.

This moves the implementation to `torch/distributed/_backends/fake.py`, where `FakeProcessGroup` subclasses `dist.BackendBase` and implements all collectives, p2p, coalescing and `split` with the same semantics as the C++ version. Error messages match except minor wording differences (e.g. PREMUL_SUM dtype); `_create_internal` with non-fake options still raises TypeError and `split` with them still raises RuntimeError. Collectives still create the C++ `FakeWork` (now constructible with an optional result list), but PyBackend wraps any Python-returned work in a `PyWorkHolder`, so callers of `dist.*` now get a plain `Work` rather than a `FakeWork` and cannot read `seq_id` from it; no users of that were found. Direct construction stays blocked (still a TypeError, now with a message pointing at the supported paths); use `init_process_group(backend="fake")` or `FakeProcessGroup._create_internal`.

`FakeProcessGroup.Options` becomes a Python subclass of `dist.BackendBase.Options` with the same fields and defaults (`fake_option=0`, `error_on_collective=False`, `simulate_uniform_ranks=False`). This relies on #202176, which makes `split_group` preserve Python `Backend.Options` subclasses instead of slicing them to the C++ base. `.options` stays None for groups created without options, as in C++; #202194 makes `split_group` handle that for Python backends. `copy.copy` and `split_group` still produce a `FakeProcessGroup.Options` copy. As a plain Python class, the options no longer reject unknown attribute names or non-int `fake_option` values.

The backend is registered through a `fake` entry in the `torch.distributed.backends` entry point group like the other built-in backends, so `init_process_group(backend="fake", store=...)` no longer requires importing a testing module first. When no `fake` entry point is found (stale editable installs, Buck), `Backend._ensure_backend_registered` falls back to registering the built-in backend directly, so `init_process_group("fake")` keeps working without importing the testing module. `torch/testing/_internal/distributed/fake_pg.py` stays as a shim that re-exports `FakeProcessGroup`/`FakeStore`/`_create_fake_pg` and still registers the backend on import, so existing imports keep working in either case. Importing FSDP no longer registers the backend (and its device mappings) as a side effect, since it now imports the new module; lookup by name still registers it on demand; the test helpers in `common_distributed.py`/`common_fsdp.py` import the shim explicitly.

`FakeProcessGroup.hpp` now only holds `FakeWork`; the C++ `c10d::FakeProcessGroup` class and its options are removed. This breaks C++ code that subclasses or constructs it from the installed header (e.g. xLLM-AI/xllm's `process_group_batch_test.cpp`); such code should use its own test backend or the Python class.

Under `TORCH_DISTRIBUTED_DEBUG=DETAIL`, `_ProcessGroupWrapper` held the wrapped backend only in C++, so a Python backend's object was freed once group creation returned and later calls lost its overrides (e.g. an internal assert in `getBackendName`). The wrapper's init now preserves the Python object as `_register_backend` does, through `PyBackend::initSlotAndCast` (made public). Fake collectives under DETAIL still raise "does not yet support sequence numbers", as with the C++ backend.

Suggested review order: `_backends/fake.py` (the new implementation), then `init.cpp`/`FakeProcessGroup.hpp`, then the small supporting changes: the ReduceOp `factor` getter now raises instead of dereferencing an undefined supplement, since the Python path reads it for PREMUL_SUM. `torch._C._distributed_c10d.FakeProcessGroup` is kept as a lazy module `__getattr__` alias to the Python class because external code (e.g. meta-recsys) imports it from there; this keeps `import torch` from importing the backend eagerly. It no longer appears in `dir(torch._C._distributed_c10d)` and its `__module__` is now `torch.distributed._backends.fake`.

`split` accepts a base `Backend.Options` whose backend is `fake` (what C++ passes for a group without options) and fills the fake fields from this group; C++ rejected base options, but it never produced them for its own groups. Other options are rejected, as in C++.

Python overrides shadow the `Backend` binding's convenience overloads of the same name (e.g. `backend.allreduce(tensor, op)`, `backend.allgather(outputs, tensor)`), so broadcast, allreduce, reduce, allgather, gather, scatter and reduce_scatter check each argument against the canonical signature (tensor lists of the expected nesting, then an options object) and forward any other call to the base binding, which re-enters the Python method canonically or raises pybind's TypeError. Parameter names match the binding so keyword calls keep working. Calling the backend object directly differs slightly: the convenience overloads return a plain `Work` (canonical calls still return `FakeWork`), and the other methods no longer type-check their arguments. The tensor ops the backend runs (`copy_`, `mul_`, ...) are now Python calls, so an active `TorchFunctionMode` sees them, as with any Python backend.

Alternatives considered: keeping the C++ class with a Python wrapper (keeps the duplication), removing the `torch._C` name outright (breaks downstream users), or leaving the implementation under `torch.testing` (non-test code such as FSDP and `init_process_group` would keep importing the testing package).

Test plan:

```
python -m pytest test/distributed/test_fake_pg.py test/distributed/test_device_mesh.py test/distributed/test_c10d_pybackend.py test/distributed/test_c10d_common.py test/dynamo/test_fake_distributed.py test/dynamo/test_fx_graph_runnable.py
python -m pytest test/dynamo/test_guard_serialization.py -k "Backend or unsupported_types_prune"
python -m pytest test/distributed/test_fake_backend_new_group.py test/distributed/_tools/test_fake_collectives.py
python -m pytest test/test_testing.py -k "test_circular_dependencies or no_warning_on_import"
lintrunner -a
```

Run on CPU; `test_fake_collectives.py` skips without CUDA/XPU.

Line changes: implementation +752/-828, tests (`test/`) +286/-8.

This PR was authored with the help of an AI assistant (Claude).

ghstack-source-id: fc5f152
Pull-Request: #202141
d4l3k added a commit that referenced this pull request Oct 29, 2026
`FakeProcessGroup` was a C++ `c10d::Backend` subclass with every collective implemented in C++. It is a test-only backend, and keeping it in C++ meant every semantic change (uniform-rank simulation, split support, size checks) required a C++ rebuild and duplicated logic that is easier to read and extend in Python. With `dist.BackendBase` now subclassable from Python via the PyBackend trampoline, the backend can live in Python.

This moves the implementation to `torch/distributed/_backends/fake.py`, where `FakeProcessGroup` subclasses `dist.BackendBase` and implements all collectives, p2p, coalescing and `split` with the same semantics as the C++ version. Error messages match except minor wording differences (e.g. PREMUL_SUM dtype); `_create_internal` with non-fake options still raises TypeError and `split` with them still raises RuntimeError. Collectives still create the C++ `FakeWork` (now constructible with an optional result list), but PyBackend wraps any Python-returned work in a `PyWorkHolder`, so callers of `dist.*` now get a plain `Work` rather than a `FakeWork` and cannot read `seq_id` from it; no users of that were found. Direct construction stays blocked (still a TypeError, now with a message pointing at the supported paths); use `init_process_group(backend="fake")` or `FakeProcessGroup._create_internal`.

`FakeProcessGroup.Options` becomes a Python subclass of `dist.BackendBase.Options` with the same fields and defaults (`fake_option=0`, `error_on_collective=False`, `simulate_uniform_ranks=False`). This relies on #202176, which makes `split_group` preserve Python `Backend.Options` subclasses instead of slicing them to the C++ base. `.options` stays None for groups created without options, as in C++; #202194 makes `split_group` handle that for Python backends. `copy.copy` and `split_group` still produce a `FakeProcessGroup.Options` copy. As a plain Python class, the options no longer reject unknown attribute names or non-int `fake_option` values.

The backend is registered through a `fake` entry in the `torch.distributed.backends` entry point group like the other built-in backends, so `init_process_group(backend="fake", store=...)` no longer requires importing a testing module first. When no `fake` entry point is found (stale editable installs, Buck), `Backend._ensure_backend_registered` falls back to registering the built-in backend directly, so `init_process_group("fake")` keeps working without importing the testing module. `torch/testing/_internal/distributed/fake_pg.py` stays as a shim that re-exports `FakeProcessGroup`/`FakeStore`/`_create_fake_pg` and still registers the backend on import, so existing imports keep working in either case. Importing FSDP no longer registers the backend (and its device mappings) as a side effect, since it now imports the new module; lookup by name still registers it on demand; the test helpers in `common_distributed.py`/`common_fsdp.py` import the shim explicitly.

`FakeProcessGroup.hpp` now only holds `FakeWork`; the C++ `c10d::FakeProcessGroup` class and its options are removed. This breaks C++ code that subclasses or constructs it from the installed header (e.g. xLLM-AI/xllm's `process_group_batch_test.cpp`); such code should use its own test backend or the Python class.

Under `TORCH_DISTRIBUTED_DEBUG=DETAIL`, `_ProcessGroupWrapper` held the wrapped backend only in C++, so a Python backend's object was freed once group creation returned and later calls lost its overrides (e.g. an internal assert in `getBackendName`). The wrapper's init now preserves the Python object as `_register_backend` does, through `PyBackend::initSlotAndCast` (made public). Fake collectives under DETAIL still raise "does not yet support sequence numbers", as with the C++ backend.

Suggested review order: `_backends/fake.py` (the new implementation), then `init.cpp`/`FakeProcessGroup.hpp`, then the small supporting changes: the ReduceOp `factor` getter now raises instead of dereferencing an undefined supplement, since the Python path reads it for PREMUL_SUM. `torch._C._distributed_c10d.FakeProcessGroup` is kept as a lazy module `__getattr__` alias to the Python class because external code (e.g. meta-recsys) imports it from there; this keeps `import torch` from importing the backend eagerly. It no longer appears in `dir(torch._C._distributed_c10d)` and its `__module__` is now `torch.distributed._backends.fake`.

`split` accepts a base `Backend.Options` whose backend is `fake` (what C++ passes for a group without options) and fills the fake fields from this group; C++ rejected base options, but it never produced them for its own groups. Other options are rejected, as in C++.

Python overrides shadow the `Backend` binding's convenience overloads of the same name (e.g. `backend.allreduce(tensor, op)`, `backend.allgather(outputs, tensor)`), so broadcast, allreduce, reduce, allgather, gather, scatter and reduce_scatter check each argument against the canonical signature (tensor lists of the expected nesting, then an options object) and forward any other call to the base binding, which re-enters the Python method canonically or raises pybind's TypeError. Parameter names match the binding so keyword calls keep working. Calling the backend object directly differs slightly: the convenience overloads return a plain `Work` (canonical calls still return `FakeWork`), and the other methods no longer type-check their arguments. The tensor ops the backend runs (`copy_`, `mul_`, ...) are now Python calls, so an active `TorchFunctionMode` sees them, as with any Python backend.

Alternatives considered: keeping the C++ class with a Python wrapper (keeps the duplication), removing the `torch._C` name outright (breaks downstream users), or leaving the implementation under `torch.testing` (non-test code such as FSDP and `init_process_group` would keep importing the testing package).

Test plan:

```
python -m pytest test/distributed/test_fake_pg.py test/distributed/test_device_mesh.py test/distributed/test_c10d_pybackend.py test/distributed/test_c10d_common.py test/dynamo/test_fake_distributed.py test/dynamo/test_fx_graph_runnable.py
python -m pytest test/dynamo/test_guard_serialization.py -k "Backend or unsupported_types_prune"
python -m pytest test/distributed/test_fake_backend_new_group.py test/distributed/_tools/test_fake_collectives.py
python -m pytest test/test_testing.py -k "test_circular_dependencies or no_warning_on_import"
lintrunner -a
```

Run on CPU; `test_fake_collectives.py` skips without CUDA/XPU.

Line changes: implementation +757/-828, tests (`test/`) +294/-8.

This PR was authored with the help of an AI assistant (Claude).

ghstack-source-id: 763d965
Pull-Request: #202141
d4l3k added a commit that referenced this pull request Oct 29, 2026
`FakeProcessGroup` was a C++ `c10d::Backend` subclass with every collective implemented in C++. It is a test-only backend, and keeping it in C++ meant every semantic change (uniform-rank simulation, split support, size checks) required a C++ rebuild and duplicated logic that is easier to read and extend in Python. With `dist.BackendBase` now subclassable from Python via the PyBackend trampoline, the backend can live in Python.

This moves the implementation to `torch/distributed/_backends/fake.py`, where `FakeProcessGroup` subclasses `dist.BackendBase` and implements all collectives, p2p, coalescing and `split` with the same semantics as the C++ version. Error messages match except minor wording differences (e.g. PREMUL_SUM dtype); `_create_internal` with non-fake options still raises TypeError and `split` with them still raises RuntimeError. Collectives still create the C++ `FakeWork` (now constructible with an optional result list), but PyBackend wraps any Python-returned work in a `PyWorkHolder`, so callers of `dist.*` now get a plain `Work` rather than a `FakeWork` and cannot read `seq_id` from it; no users of that were found. Direct construction stays blocked (still a TypeError, now with a message pointing at the supported paths); use `init_process_group(backend="fake")` or `FakeProcessGroup._create_internal`.

`FakeProcessGroup.Options` becomes a Python subclass of `dist.BackendBase.Options` with the same fields and defaults (`fake_option=0`, `error_on_collective=False`, `simulate_uniform_ranks=False`). This relies on #202176, which makes `split_group` preserve Python `Backend.Options` subclasses instead of slicing them to the C++ base. `.options` stays None for groups created without options, as in C++; #202194 makes `split_group` handle that for Python backends. `copy.copy` and `split_group` still produce a `FakeProcessGroup.Options` copy. As a plain Python class, the options no longer reject unknown attribute names or non-int `fake_option` values.

The backend is registered through a `fake` entry in the `torch.distributed.backends` entry point group like the other built-in backends, so `init_process_group(backend="fake", store=...)` no longer requires importing a testing module first. When no `fake` entry point is found (stale editable installs, Buck), `Backend._ensure_backend_registered` falls back to registering the built-in backend directly, so `init_process_group("fake")` keeps working without importing the testing module. `torch/testing/_internal/distributed/fake_pg.py` stays as a shim that re-exports `FakeProcessGroup`/`FakeStore`/`_create_fake_pg` and still registers the backend on import, so existing imports keep working in either case. Importing FSDP no longer registers the backend (and its device mappings) as a side effect, since it now imports the new module; lookup by name still registers it on demand; the test helpers in `common_distributed.py`/`common_fsdp.py` import the shim explicitly.

`FakeProcessGroup.hpp` now only holds `FakeWork`; the C++ `c10d::FakeProcessGroup` class and its options are removed. This breaks C++ code that subclasses or constructs it from the installed header (e.g. xLLM-AI/xllm's `process_group_batch_test.cpp`); such code should use its own test backend or the Python class.

Under `TORCH_DISTRIBUTED_DEBUG=DETAIL`, `_ProcessGroupWrapper` held the wrapped backend only in C++, so a Python backend's object was freed once group creation returned and later calls lost its overrides (e.g. an internal assert in `getBackendName`). The wrapper's init now preserves the Python object as `_register_backend` does, through `PyBackend::initSlotAndCast` (made public). Fake collectives under DETAIL still raise "does not yet support sequence numbers", as with the C++ backend.

Suggested review order: `_backends/fake.py` (the new implementation), then `init.cpp`/`FakeProcessGroup.hpp`, then the small supporting changes: the ReduceOp `factor` getter now raises instead of dereferencing an undefined supplement, since the Python path reads it for PREMUL_SUM. `torch._C._distributed_c10d.FakeProcessGroup` is kept as a lazy module `__getattr__` alias to the Python class because external code (e.g. meta-recsys) imports it from there; this keeps `import torch` from importing the backend eagerly. It no longer appears in `dir(torch._C._distributed_c10d)` and its `__module__` is now `torch.distributed._backends.fake`.

`split` accepts a base `Backend.Options` whose backend is `fake` (what C++ passes for a group without options) and fills the fake fields from this group; C++ rejected base options, but it never produced them for its own groups. Other options are rejected, as in C++.

Python overrides shadow the `Backend` binding's convenience overloads of the same name (e.g. `backend.allreduce(tensor, op)`, `backend.allgather(outputs, tensor)`), so broadcast, allreduce, reduce, allgather, gather, scatter and reduce_scatter check each argument against the canonical signature (tensor lists of the expected nesting, then an options object) and forward any other call to the base binding, which re-enters the Python method canonically or raises pybind's TypeError. Parameter names match the binding so keyword calls keep working. Calling the backend object directly differs slightly: the convenience overloads return a plain `Work` (canonical calls still return `FakeWork`), and the other methods no longer type-check their arguments. The tensor ops the backend runs (`copy_`, `mul_`, ...) are now Python calls, so an active `TorchFunctionMode` sees them, as with any Python backend.

Alternatives considered: keeping the C++ class with a Python wrapper (keeps the duplication), removing the `torch._C` name outright (breaks downstream users), or leaving the implementation under `torch.testing` (non-test code such as FSDP and `init_process_group` would keep importing the testing package).

Test plan:

```
python -m pytest test/distributed/test_fake_pg.py test/distributed/test_device_mesh.py test/distributed/test_c10d_pybackend.py test/distributed/test_c10d_common.py test/dynamo/test_fake_distributed.py test/dynamo/test_fx_graph_runnable.py
python -m pytest test/dynamo/test_guard_serialization.py -k "Backend or unsupported_types_prune"
python -m pytest test/distributed/test_fake_backend_new_group.py test/distributed/_tools/test_fake_collectives.py
python -m pytest test/test_testing.py -k "test_circular_dependencies or no_warning_on_import"
lintrunner -a
```

Run on CPU; `test_fake_collectives.py` skips without CUDA/XPU.

Line changes: implementation +757/-828, tests (`test/`) +289/-8.

This PR was authored with the help of an AI assistant (Claude).

ghstack-source-id: 0127eb6
Pull-Request: #202141
d4l3k added a commit that referenced this pull request Oct 29, 2026
`FakeProcessGroup` was a C++ `c10d::Backend` subclass with every collective implemented in C++. It is a test-only backend, and keeping it in C++ meant every semantic change (uniform-rank simulation, split support, size checks) required a C++ rebuild and duplicated logic that is easier to read and extend in Python. With `dist.BackendBase` now subclassable from Python via the PyBackend trampoline, the backend can live in Python.

This moves the implementation to `torch/distributed/_backends/fake.py`, where `FakeProcessGroup` subclasses `dist.BackendBase` and implements all collectives, p2p, coalescing and `split` with the same semantics as the C++ version. Error messages match except minor wording differences (e.g. PREMUL_SUM dtype); `_create_internal` with non-fake options still raises TypeError and `split` with them still raises RuntimeError. Collectives still create the C++ `FakeWork` (now constructible with an optional result list), but PyBackend wraps any Python-returned work in a `PyWorkHolder`, so callers of `dist.*` now get a plain `Work` rather than a `FakeWork` and cannot read `seq_id` from it; no users of that were found. Direct construction stays blocked (still a TypeError, now with a message pointing at the supported paths); use `init_process_group(backend="fake")` or `FakeProcessGroup._create_internal`.

`FakeProcessGroup.Options` becomes a Python subclass of `dist.BackendBase.Options` with the same fields and defaults (`fake_option=0`, `error_on_collective=False`, `simulate_uniform_ranks=False`). This relies on #202176, which makes `split_group` preserve Python `Backend.Options` subclasses instead of slicing them to the C++ base. `.options` stays None for groups created without options, as in C++; #202194 makes `split_group` handle that for Python backends. `copy.copy` and `split_group` still produce a `FakeProcessGroup.Options` copy. As a plain Python class, the options no longer reject unknown attribute names or non-int `fake_option` values.

The backend is registered through a `fake` entry in the `torch.distributed.backends` entry point group like the other built-in backends, so `init_process_group(backend="fake", store=...)` no longer requires importing a testing module first. When no `fake` entry point is found (stale editable installs, Buck), `Backend._ensure_backend_registered` falls back to registering the built-in backend directly, so `init_process_group("fake")` keeps working without importing the testing module. `torch/testing/_internal/distributed/fake_pg.py` stays as a shim that re-exports `FakeProcessGroup`/`FakeStore`/`_create_fake_pg` and still registers the backend on import, so existing imports keep working in either case. Importing FSDP no longer registers the backend (and its device mappings) as a side effect, since it now imports the new module; lookup by name still registers it on demand; the test helpers in `common_distributed.py`/`common_fsdp.py` import the shim explicitly.

`FakeProcessGroup.hpp` now only holds `FakeWork`; the C++ `c10d::FakeProcessGroup` class and its options are removed. This breaks C++ code that subclasses or constructs it from the installed header (e.g. xLLM-AI/xllm's `process_group_batch_test.cpp`); such code should use its own test backend or the Python class.

Under `TORCH_DISTRIBUTED_DEBUG=DETAIL`, `_ProcessGroupWrapper` held the wrapped backend only in C++, so a Python backend's object was freed once group creation returned and later calls lost its overrides (e.g. an internal assert in `getBackendName`). The wrapper's init now preserves the Python object as `_register_backend` does, through `PyBackend::initSlotAndCast` (made public). Fake collectives under DETAIL still raise "does not yet support sequence numbers", as with the C++ backend.

Suggested review order: `_backends/fake.py` (the new implementation), then `init.cpp`/`FakeProcessGroup.hpp`, then the small supporting changes: the ReduceOp `factor` getter now raises instead of dereferencing an undefined supplement, since the Python path reads it for PREMUL_SUM. `torch._C._distributed_c10d.FakeProcessGroup` is kept as a lazy module `__getattr__` alias to the Python class because external code (e.g. meta-recsys) imports it from there; this keeps `import torch` from importing the backend eagerly. It no longer appears in `dir(torch._C._distributed_c10d)` and its `__module__` is now `torch.distributed._backends.fake`.

`split` accepts a base `Backend.Options` whose backend is `fake` (what C++ passes for a group without options) and fills the fake fields from this group; C++ rejected base options, but it never produced them for its own groups. Other options are rejected, as in C++.

Python overrides shadow the `Backend` binding's convenience overloads of the same name (e.g. `backend.allreduce(tensor, op)`, `backend.allgather(outputs, tensor)`), so broadcast, allreduce, reduce, allgather, gather, scatter and reduce_scatter check each argument against the canonical signature (tensor lists of the expected nesting, then an options object) and forward any other call to the base binding, which re-enters the Python method canonically or raises pybind's TypeError. Parameter names match the binding so keyword calls keep working. Calling the backend object directly differs slightly: the convenience overloads return a plain `Work` (canonical calls still return `FakeWork`), and the other methods no longer type-check their arguments. The tensor ops the backend runs (`copy_`, `mul_`, ...) are now Python calls, so an active `TorchFunctionMode` sees them, as with any Python backend.

Alternatives considered: keeping the C++ class with a Python wrapper (keeps the duplication), removing the `torch._C` name outright (breaks downstream users), or leaving the implementation under `torch.testing` (non-test code such as FSDP and `init_process_group` would keep importing the testing package).

Test plan:

```
python -m pytest test/distributed/test_fake_pg.py test/distributed/test_device_mesh.py test/distributed/test_c10d_pybackend.py test/distributed/test_c10d_common.py test/dynamo/test_fake_distributed.py test/dynamo/test_fx_graph_runnable.py
python -m pytest test/dynamo/test_guard_serialization.py -k "Backend or unsupported_types_prune"
python -m pytest test/distributed/test_fake_backend_new_group.py test/distributed/_tools/test_fake_collectives.py
python -m pytest test/test_testing.py -k "test_circular_dependencies or no_warning_on_import"
lintrunner -a
```

Run on CPU; `test_fake_collectives.py` skips without CUDA/XPU.

Line changes: implementation +757/-828, tests (`test/`) +289/-8.

This PR was authored with the help of an AI assistant (Claude).

ghstack-source-id: fac4d96
Pull-Request: #202141
d4l3k added a commit that referenced this pull request Oct 29, 2026
`FakeProcessGroup` was a C++ `c10d::Backend` subclass with every collective implemented in C++. It is a test-only backend, and keeping it in C++ meant every semantic change (uniform-rank simulation, split support, size checks) required a C++ rebuild and duplicated logic that is easier to read and extend in Python. With `dist.BackendBase` now subclassable from Python via the PyBackend trampoline, the backend can live in Python.

This moves the implementation to `torch/distributed/_backends/fake.py`, where `FakeProcessGroup` subclasses `dist.BackendBase` and implements all collectives, p2p, coalescing and `split` with the same semantics as the C++ version. Error messages match except minor wording differences (e.g. PREMUL_SUM dtype); `_create_internal` with non-fake options still raises TypeError and `split` with them still raises RuntimeError. Collectives still create the C++ `FakeWork` (now constructible with an optional result list), but PyBackend wraps any Python-returned work in a `PyWorkHolder`, so callers of `dist.*` now get a plain `Work` rather than a `FakeWork` and cannot read `seq_id` from it; no users of that were found. Direct construction stays blocked (still a TypeError, now with a message pointing at the supported paths); use `init_process_group(backend="fake")` or `FakeProcessGroup._create_internal`.

`FakeProcessGroup.Options` becomes a Python subclass of `dist.BackendBase.Options` with the same fields and defaults (`fake_option=0`, `error_on_collective=False`, `simulate_uniform_ranks=False`). This relies on #202176, which makes `split_group` preserve Python `Backend.Options` subclasses instead of slicing them to the C++ base. `.options` stays None for groups created without options, as in C++; #202194 makes `split_group` handle that for Python backends. `copy.copy` and `split_group` still produce a `FakeProcessGroup.Options` copy. As a plain Python class, the options no longer reject unknown attribute names or non-int `fake_option` values.

The backend is registered through a `fake` entry in the `torch.distributed.backends` entry point group like the other built-in backends, so `init_process_group(backend="fake", store=...)` no longer requires importing a testing module first. When no `fake` entry point is found (stale editable installs, Buck), `Backend._ensure_backend_registered` falls back to registering the built-in backend directly, so `init_process_group("fake")` keeps working without importing the testing module. `torch/testing/_internal/distributed/fake_pg.py` stays as a shim that re-exports `FakeProcessGroup`/`FakeStore`/`_create_fake_pg` and still registers the backend on import, so existing imports keep working in either case. Importing FSDP no longer registers the backend (and its device mappings) as a side effect, since it now imports the new module; lookup by name still registers it on demand; the test helpers in `common_distributed.py`/`common_fsdp.py` import the shim explicitly.

`FakeProcessGroup.hpp` now only holds `FakeWork`; the C++ `c10d::FakeProcessGroup` class and its options are removed. This breaks C++ code that subclasses or constructs it from the installed header (e.g. xLLM-AI/xllm's `process_group_batch_test.cpp`); such code should use its own test backend or the Python class.

Under `TORCH_DISTRIBUTED_DEBUG=DETAIL`, `_ProcessGroupWrapper` held the wrapped backend only in C++, so a Python backend's object was freed once group creation returned and later calls lost its overrides (e.g. an internal assert in `getBackendName`). The wrapper's init now preserves the Python object as `_register_backend` does, through `PyBackend::initSlotAndCast` (made public). Fake collectives under DETAIL still raise "does not yet support sequence numbers", as with the C++ backend.

Suggested review order: `_backends/fake.py` (the new implementation), then `init.cpp`/`FakeProcessGroup.hpp`, then the small supporting changes: the ReduceOp `factor` getter now raises instead of dereferencing an undefined supplement, since the Python path reads it for PREMUL_SUM. `torch._C._distributed_c10d.FakeProcessGroup` is kept as a lazy module `__getattr__` alias to the Python class because external code (e.g. meta-recsys) imports it from there; this keeps `import torch` from importing the backend eagerly. It no longer appears in `dir(torch._C._distributed_c10d)` and its `__module__` is now `torch.distributed._backends.fake`.

`split` accepts a base `Backend.Options` whose backend is `fake` (what C++ passes for a group without options) and fills the fake fields from this group; C++ rejected base options, but it never produced them for its own groups. Other options are rejected, as in C++.

Python overrides shadow the `Backend` binding's convenience overloads of the same name (e.g. `backend.allreduce(tensor, op)`, `backend.allgather(outputs, tensor)`), so broadcast, allreduce, reduce, allgather, gather, scatter and reduce_scatter check each argument against the canonical signature (tensor lists of the expected nesting, then an options object) and forward any other call to the base binding, which re-enters the Python method canonically or raises pybind's TypeError. Parameter names match the binding so keyword calls keep working. Calling the backend object directly differs slightly: the convenience overloads return a plain `Work` (canonical calls still return `FakeWork`), and the other methods no longer type-check their arguments. The tensor ops the backend runs (`copy_`, `mul_`, ...) are now Python calls, so an active `TorchFunctionMode` sees them, as with any Python backend.

Alternatives considered: keeping the C++ class with a Python wrapper (keeps the duplication), removing the `torch._C` name outright (breaks downstream users), or leaving the implementation under `torch.testing` (non-test code such as FSDP and `init_process_group` would keep importing the testing package).

Test plan:

```
python -m pytest test/distributed/test_fake_pg.py test/distributed/test_device_mesh.py test/distributed/test_c10d_pybackend.py test/distributed/test_c10d_common.py test/dynamo/test_fake_distributed.py test/dynamo/test_fx_graph_runnable.py
python -m pytest test/dynamo/test_guard_serialization.py -k "Backend or unsupported_types_prune"
python -m pytest test/distributed/test_fake_backend_new_group.py test/distributed/_tools/test_fake_collectives.py
python -m pytest test/test_testing.py -k "test_circular_dependencies or no_warning_on_import"
lintrunner -a
```

Run on CPU; `test_fake_collectives.py` skips without CUDA/XPU.

Line changes: implementation +760/-828, tests (`test/`) +294/-8.

This PR was authored with the help of an AI assistant (Claude).

ghstack-source-id: 19b3c66
Pull-Request: #202141
d4l3k added a commit that referenced this pull request Oct 29, 2026
`FakeProcessGroup` was a C++ `c10d::Backend` subclass with every collective implemented in C++. It is a test-only backend, and keeping it in C++ meant every semantic change (uniform-rank simulation, split support, size checks) required a C++ rebuild and duplicated logic that is easier to read and extend in Python. With `dist.BackendBase` now subclassable from Python via the PyBackend trampoline, the backend can live in Python.

This moves the implementation to `torch/distributed/_backends/fake.py`, where `FakeProcessGroup` subclasses `dist.BackendBase` and implements all collectives, p2p, coalescing and `split` with the same semantics as the C++ version. Error messages match except minor wording differences (e.g. PREMUL_SUM dtype); `_create_internal` with non-fake options still raises TypeError and `split` with them still raises RuntimeError. Collectives still create the C++ `FakeWork` (now constructible with an optional result list), but PyBackend wraps any Python-returned work in a `PyWorkHolder`, so callers of `dist.*` now get a plain `Work` rather than a `FakeWork` and cannot read `seq_id` from it; no users of that were found. Direct construction stays blocked (still a TypeError, now with a message pointing at the supported paths); use `init_process_group(backend="fake")` or `FakeProcessGroup._create_internal`.

`FakeProcessGroup.Options` becomes a Python subclass of `dist.BackendBase.Options` with the same fields and defaults (`fake_option=0`, `error_on_collective=False`, `simulate_uniform_ranks=False`). This relies on #202176, which makes `split_group` preserve Python `Backend.Options` subclasses instead of slicing them to the C++ base. `.options` stays None for groups created without options, as in C++; #202194 makes `split_group` handle that for Python backends. `copy.copy` and `split_group` still produce a `FakeProcessGroup.Options` copy. As a plain Python class, the options no longer reject unknown attribute names or non-int `fake_option` values.

The backend is registered through a `fake` entry in the `torch.distributed.backends` entry point group like the other built-in backends, so `init_process_group(backend="fake", store=...)` no longer requires importing a testing module first. When no `fake` entry point is found (stale editable installs, Buck), `Backend._ensure_backend_registered` falls back to registering the built-in backend directly, so `init_process_group("fake")` keeps working without importing the testing module. `torch/testing/_internal/distributed/fake_pg.py` stays as a shim that re-exports `FakeProcessGroup`/`FakeStore`/`_create_fake_pg` and still registers the backend on import, so existing imports keep working in either case. Importing FSDP no longer registers the backend (and its device mappings) as a side effect, since it now imports the new module; lookup by name still registers it on demand; the test helpers in `common_distributed.py`/`common_fsdp.py` import the shim explicitly.

`FakeProcessGroup.hpp` now only holds `FakeWork`; the C++ `c10d::FakeProcessGroup` class and its options are removed. This breaks C++ code that subclasses or constructs it from the installed header (e.g. xLLM-AI/xllm's `process_group_batch_test.cpp`); such code should use its own test backend or the Python class.

Under `TORCH_DISTRIBUTED_DEBUG=DETAIL`, `_ProcessGroupWrapper` held the wrapped backend only in C++, so a Python backend's object was freed once group creation returned and later calls lost its overrides (e.g. an internal assert in `getBackendName`). The wrapper's init now preserves the Python object as `_register_backend` does, through `PyBackend::initSlotAndCast` (made public). Fake collectives under DETAIL still raise "does not yet support sequence numbers", as with the C++ backend.

Suggested review order: `_backends/fake.py` (the new implementation), then `init.cpp`/`FakeProcessGroup.hpp`, then the small supporting changes: the ReduceOp `factor` getter now raises instead of dereferencing an undefined supplement, since the Python path reads it for PREMUL_SUM. `torch._C._distributed_c10d.FakeProcessGroup` is kept as a lazy module `__getattr__` alias to the Python class because external code (e.g. meta-recsys) imports it from there; this keeps `import torch` from importing the backend eagerly. It no longer appears in `dir(torch._C._distributed_c10d)` and its `__module__` is now `torch.distributed._backends.fake`.

`split` accepts a base `Backend.Options` whose backend is `fake` (what C++ passes for a group without options) and fills the fake fields from this group; C++ rejected base options, but it never produced them for its own groups. Other options are rejected, as in C++.

Python overrides shadow the `Backend` binding's convenience overloads of the same name (e.g. `backend.allreduce(tensor, op)`, `backend.allgather(outputs, tensor)`), so broadcast, allreduce, reduce, allgather, gather, scatter and reduce_scatter check each argument against the canonical signature (tensor lists of the expected nesting, then an options object) and forward any other call to the base binding, which re-enters the Python method canonically or raises pybind's TypeError. Parameter names match the binding so keyword calls keep working. Calling the backend object directly differs slightly: the convenience overloads return a plain `Work` (canonical calls still return `FakeWork`), and the other methods no longer type-check their arguments. The tensor ops the backend runs (`copy_`, `mul_`, ...) are now Python calls, so an active `TorchFunctionMode` sees them, as with any Python backend.

Alternatives considered: keeping the C++ class with a Python wrapper (keeps the duplication), removing the `torch._C` name outright (breaks downstream users), or leaving the implementation under `torch.testing` (non-test code such as FSDP and `init_process_group` would keep importing the testing package).

Test plan:

```
python -m pytest test/distributed/test_fake_pg.py test/distributed/test_device_mesh.py test/distributed/test_c10d_pybackend.py test/distributed/test_c10d_common.py test/dynamo/test_fake_distributed.py test/dynamo/test_fx_graph_runnable.py
python -m pytest test/dynamo/test_guard_serialization.py -k "Backend or unsupported_types_prune"
python -m pytest test/distributed/test_fake_backend_new_group.py test/distributed/_tools/test_fake_collectives.py
python -m pytest test/test_testing.py -k "test_circular_dependencies or no_warning_on_import"
lintrunner -a
```

Run on CPU; `test_fake_collectives.py` skips without CUDA/XPU.

Line changes: implementation +760/-828, tests (`test/`) +203/-10.

This PR was authored with the help of an AI assistant (Claude).

ghstack-source-id: 9650e8d
Pull-Request: #202141
pytorchmergebot pushed a commit that referenced this pull request Oct 30, 2026
`FakeProcessGroup` is a test-only backend, but its C++ implementation meant every semantic change needed a C++ rebuild. With `dist.BackendBase` subclassable from Python, it can live in Python.

Design: `torch/distributed/_backends/fake.py` reimplements `FakeProcessGroup` and `FakeProcessGroup.Options` on `dist.BackendBase` with the same semantics. It is registered through the `torch.distributed.backends` entry point (with a built-in fallback), so `init_process_group("fake")` no longer requires importing a testing module. `torch/testing/_internal/distributed/fake_pg.py` stays as a re-exporting shim, and `torch._C._distributed_c10d.FakeProcessGroup` stays as a lazy alias for downstream users. The C++ class is removed; `FakeWork` remains. `_ProcessGroupWrapper` (DEBUG=DETAIL) now keeps Python backend objects alive, as `_register_backend` does.

BC: C++ code using `c10d::FakeProcessGroup` from the installed header breaks. `dist.*` calls on a fake group return a plain `Work` instead of `FakeWork`.

Depends on #202176 and #202194 (Python `Backend.Options` through `split_group`).

Test plan:

```
python -m pytest test/distributed/test_fake_pg.py test/distributed/test_device_mesh.py test/distributed/test_c10d_pybackend.py test/distributed/test_c10d_common.py test/dynamo/test_fake_distributed.py test/dynamo/test_fx_graph_runnable.py
python -m pytest test/dynamo/test_guard_serialization.py -k "Backend or unsupported_types_prune"
python -m pytest test/distributed/test_fake_backend_new_group.py test/distributed/_tools/test_fake_collectives.py
python -m pytest test/test_testing.py -k "test_circular_dependencies or no_warning_on_import"
lintrunner -a
```

Line changes: implementation +760/-828, tests (`test/`) +203/-10.

This PR was authored with the help of an AI assistant (Claude).

Pull Request resolved: #202141
Approved by: https://github.com/fduwjj, https://github.com/kapilsh
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 5, 2026
…rch#202194)

`ProcessGroup::splitGroup` and `mergeRemoteGroup` dereference `Backend::getBackendOptions()`. For a Python backend that comes from its `options` property, and when that returns None (no backend-specific options) `castAndPreserve` yields a null pointer and `split_group` / `merge_remote_group` crash. C++ backends with nullable options, like the C++ FakeProcessGroup, avoid this by returning fresh default options from `getBackendOptions` while their Python `.options` stays None; test_device_mesh relies on that None to tell whether an options override was supplied.

`PyBackend::getBackendOptions` now returns default `Backend::Options` named after the backend when the Python `options` property returns None, so Python backends can keep the same nullable `.options` contract. This is needed by the next PR, which moves FakeProcessGroup to Python. The alternative of making FakeProcessGroup's `.options` always non-None would change its observable behavior.

Test plan:

```
python -m pytest test/distributed/test_c10d_pybackend.py
lintrunner -a
```

This PR was authored with the help of an AI assistant (Claude).
Pull Request resolved: pytorch#202194
Approved by: https://github.com/kapilsh
ghstack dependencies: pytorch#202176
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 5, 2026
…202141)

`FakeProcessGroup` is a test-only backend, but its C++ implementation meant every semantic change needed a C++ rebuild. With `dist.BackendBase` subclassable from Python, it can live in Python.

Design: `torch/distributed/_backends/fake.py` reimplements `FakeProcessGroup` and `FakeProcessGroup.Options` on `dist.BackendBase` with the same semantics. It is registered through the `torch.distributed.backends` entry point (with a built-in fallback), so `init_process_group("fake")` no longer requires importing a testing module. `torch/testing/_internal/distributed/fake_pg.py` stays as a re-exporting shim, and `torch._C._distributed_c10d.FakeProcessGroup` stays as a lazy alias for downstream users. The C++ class is removed; `FakeWork` remains. `_ProcessGroupWrapper` (DEBUG=DETAIL) now keeps Python backend objects alive, as `_register_backend` does.

BC: C++ code using `c10d::FakeProcessGroup` from the installed header breaks. `dist.*` calls on a fake group return a plain `Work` instead of `FakeWork`.

Depends on pytorch#202176 and pytorch#202194 (Python `Backend.Options` through `split_group`).

Test plan:

```
python -m pytest test/distributed/test_fake_pg.py test/distributed/test_device_mesh.py test/distributed/test_c10d_pybackend.py test/distributed/test_c10d_common.py test/dynamo/test_fake_distributed.py test/dynamo/test_fx_graph_runnable.py
python -m pytest test/dynamo/test_guard_serialization.py -k "Backend or unsupported_types_prune"
python -m pytest test/distributed/test_fake_backend_new_group.py test/distributed/_tools/test_fake_collectives.py
python -m pytest test/test_testing.py -k "test_circular_dependencies or no_warning_on_import"
lintrunner -a
```

Line changes: implementation +760/-828, tests (`test/`) +203/-10.

This PR was authored with the help of an AI assistant (Claude).

Pull Request resolved: pytorch#202141
Approved by: https://github.com/fduwjj, https://github.com/kapilsh
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 9, 2026
…rch#202194)

`ProcessGroup::splitGroup` and `mergeRemoteGroup` dereference `Backend::getBackendOptions()`. For a Python backend that comes from its `options` property, and when that returns None (no backend-specific options) `castAndPreserve` yields a null pointer and `split_group` / `merge_remote_group` crash. C++ backends with nullable options, like the C++ FakeProcessGroup, avoid this by returning fresh default options from `getBackendOptions` while their Python `.options` stays None; test_device_mesh relies on that None to tell whether an options override was supplied.

`PyBackend::getBackendOptions` now returns default `Backend::Options` named after the backend when the Python `options` property returns None, so Python backends can keep the same nullable `.options` contract. This is needed by the next PR, which moves FakeProcessGroup to Python. The alternative of making FakeProcessGroup's `.options` always non-None would change its observable behavior.

Test plan:

```
python -m pytest test/distributed/test_c10d_pybackend.py
lintrunner -a
```

This PR was authored with the help of an AI assistant (Claude).
Pull Request resolved: pytorch#202194
Approved by: https://github.com/kapilsh
ghstack dependencies: pytorch#202176
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 9, 2026
…202141)

`FakeProcessGroup` is a test-only backend, but its C++ implementation meant every semantic change needed a C++ rebuild. With `dist.BackendBase` subclassable from Python, it can live in Python.

Design: `torch/distributed/_backends/fake.py` reimplements `FakeProcessGroup` and `FakeProcessGroup.Options` on `dist.BackendBase` with the same semantics. It is registered through the `torch.distributed.backends` entry point (with a built-in fallback), so `init_process_group("fake")` no longer requires importing a testing module. `torch/testing/_internal/distributed/fake_pg.py` stays as a re-exporting shim, and `torch._C._distributed_c10d.FakeProcessGroup` stays as a lazy alias for downstream users. The C++ class is removed; `FakeWork` remains. `_ProcessGroupWrapper` (DEBUG=DETAIL) now keeps Python backend objects alive, as `_register_backend` does.

BC: C++ code using `c10d::FakeProcessGroup` from the installed header breaks. `dist.*` calls on a fake group return a plain `Work` instead of `FakeWork`.

Depends on pytorch#202176 and pytorch#202194 (Python `Backend.Options` through `split_group`).

Test plan:

```
python -m pytest test/distributed/test_fake_pg.py test/distributed/test_device_mesh.py test/distributed/test_c10d_pybackend.py test/distributed/test_c10d_common.py test/dynamo/test_fake_distributed.py test/dynamo/test_fx_graph_runnable.py
python -m pytest test/dynamo/test_guard_serialization.py -k "Backend or unsupported_types_prune"
python -m pytest test/distributed/test_fake_backend_new_group.py test/distributed/_tools/test_fake_collectives.py
python -m pytest test/test_testing.py -k "test_circular_dependencies or no_warning_on_import"
lintrunner -a
```

Line changes: implementation +760/-828, tests (`test/`) +203/-10.

This PR was authored with the help of an AI assistant (Claude).

Pull Request resolved: pytorch#202141
Approved by: https://github.com/fduwjj, https://github.com/kapilsh
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 GL/human GreenLight marked as needing human review Merged ready for review Automated review passed, ready for a final review by a maintainer. release notes: distributed (c10d) release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants