Repository navigation
[dynamo] Build the compile sync group on the fake backend over a fake world - #202253
bobrenjc93 wants to merge 6 commits into
Conversation
[ghstack-poisoned]
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". ✅ AUTOMATED REVIEW - Ready for human review:
Reviewed commit: 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/202253
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 Unclassified FailureAs of commit 5d0883f with merge base 25298e6 ( 🟡 GREEN LIGHT - OUTDATED (earlier commit) - PR requires human review:
reason: UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@claude review |
|
Claude finished @bobrenjc93's task in 1m 9s —— View job One small test-style fix needed; the logic looks correct and I'd approve once that's done. DetailsPR Review: #202253SummaryWhen every device backend of the default group is fake, I checked these points and found no problems:
Testing
RecommendationApprove after the test change above. It is minor and does not affect correctness. |
[ghstack-poisoned]
|
Review replies:
|
|
@claude review |
|
Claude finished @bobrenjc93's task in 27s —— View job I found no remaining issues on re-review: the DetailsPR Review: #202253SummaryWhen every device backend of the default group is fake, The earlier finding, the RecommendationApprove: there are no blocking issues. The tests cover the all-fake world, the |
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
There was a problem hiding this comment.
Automated review of 5d0883f: nothing blocking; ready for human review.
When every device backend of the default process group is fake, this PR builds the compile sync group on the fake backend so it no longer attempts a gloo rendezvous with nonexistent ranks, reads the sync group's timeout from a non-fake backend, and primes the group in sync_cache_decision_cross_ranks whenever it can be built; the review found no issues. Recommendation: Approve.
This review is AI-generated and advisory. Each new automated review replaces the previous one.
|
Starting merge as part of PR stack under #202258 |
|
@pytorchbot merge -i |
Merge startedYour change will be merged while ignoring the following 1 checks: docs-build Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
`torch.library.triton_op` now wraps the user's function with `functools.wraps`, so the op's `_init_fn.__module__` is the module that defined it, not `torch._library.triton`. ## Why precompile needs this A precompile artifact runs on every rank in a fresh process, where nothing has imported the modules that register the custom ops its graphs call. The next commits have the artifact import those modules, found through `torch._library.custom_ops.OPDEFS[name]._init_fn.__module__`. For a `custom_op` that is already the user's module. For a `triton_op` it was `torch._library.triton`, which is importable but registers nothing, so the artifact would import the wrong module and still fail. ## What changes - `triton_op`'s inner `backend_fn` is decorated with `functools.wraps(fn, updated=())`. This copies `__module__`, `__name__`, `__qualname__`, `__doc__` and `__wrapped__`, but not `__dict__`. - Calling the op is unchanged. ## Test plan New test `test_triton_op_function_is_the_users` in `test/test_custom_ops.py`. ``` python test/test_custom_ops.py -k triton_op_function_is_the_users ``` *Written with an AI assistant (Claude Code) and reviewed by me.* Co-Authored-By: Claude Opus 5.5 <[email protected]> Pull Request resolved: #202256 Approved by: https://github.com/pytorchgreenlight ghstack dependencies: #202253
…label classes Summary: - Split the mixed TestFakePG class: the fake-PG mechanism tests (copy semantics, requires_grad propagation, validation errors, dispatch tracing) stay in TestFakePG labeled GENERIC, while the nine accelerator-path tests (FSDP/TP e2e, functional-collectives tracing, split_group) move to a new TestFakePGDevice labeled ACCELERATOR. - TestFakePGDevice is instantiated via instantiate_device_type_tests with allow_xpu=True, and the moved methods take the injected device parameter instead of the module-level device_type = get_devtype().type (deleted). - Gate the nine methods with the variant-aware @onlyAccelerator instead of excluding the CPU variant: the CPU variant is collected and skips cleanly on every host (the guard reads the running variant's device_type), so CPU-only machines report explicit skips instead of the class being invisible, while accelerator variants run unchanged. Same gating form as the landed pytorch#192712 and pytorch#191905. @skipIfHpu blacklist guards are kept. - Rebase absorption: keep pytorch#202253's six compile-sync methods in the GENERIC TestFakePG (14 expanded cases, parametrizations and gloo availability guards intact; their config strings naming cuda/nccl do not exercise device-tensor paths) and pytorch#202141's whole-file adjustments (fake backend moved to a Python PyBackend, new GENERIC debug-wrapper/alias/split-options tests, updated assertion patterns); the unittest/unittest.mock imports the new tests use are kept. This allows the accelerator-path tests to run on any out-of-tree accelerator variant instead of being skipped wherever HAS_ACCELERATOR is False, while the device-agnostic fake-PG mechanics stay in a GENERIC class that runs everywhere. Verified on an old-snapshot verify host (its C++ fake backend predates the Python PyBackend move): - The generated CPU class collects 15 cases, all skipped with the exact reason "onlyAccelerator: doesn't run on CPU or meta devices" (OK, 0 errors). - A whole-file run is not obtainable there: a newly absorbed GENERIC test crashes the old C++ fake backend. - The PrivateUse1 variant fails there at the fake backend's device-type lookup (observed error). Full-file validation on the rebased stack remains pending. GENERIC/CPU and accelerator coverage will be checked in the corresponding CI jobs where selected. PrivateUse1 execution additionally requires pytorch#202363 at the new registration site, with the backend plugin loaded before fake registration, and a compatible verification environment; ordinary CPU/CUDA CI does not cover it.
… world (pytorch#202253) A fake default process group lets one real rank trace a model sized for the real world (for example 1 rank standing in for 64), but `get_compile_sync_pg` still builds a gloo group over that world, so the trace hangs or segfaults in `gloo::transport::tcp::Rank::Rank` waiting for ranks that do not exist. ## Why precompile needs this Capturing a multi-host training job with `torch.compiler.precompile` runs in a single process under a fake default group sized like the real world. Partitioner and AOTAutograd cache decisions sync across ranks through the compile sync group, which must not rendezvous with peers that are not there. ## What changes - When every device backend of the default group is fake, the compile sync group is fake as well. Its collectives return the local value, so each sync decision is this rank's own. No gloo is needed. - The group's timeout is read from a backend that is not fake and has options, the object-collective device first. This fixes the `AttributeError` on `"cpu:fake,cuda:nccl"`, where the CPU backend is fake. - `sync_cache_decision_cross_ranks` primes the group whenever it can be built rather than only when gloo is available. - Real worlds are unchanged: they still sync over gloo and still raise without it. ## Test plan New tests in `test/distributed/test_fake_pg.py`: all-fake and `cpu:fake` worlds get a fake group without gloo; the backend choice per device-backend config; the timeout comes from the real backend in `cpu:fake,cuda:gloo`; the cache sync primes the fake group without gloo; sync decisions stay local. ``` python test/distributed/test_fake_pg.py python test/distributed/test_inductor_collectives.py -k compile_sync ``` *Written with an AI assistant (Claude Code) and reviewed by me.* Co-Authored-By: Claude Opus 5.5 <[email protected]> Pull Request resolved: pytorch#202253 Approved by: https://github.com/Mingming-Ding
…02256) `torch.library.triton_op` now wraps the user's function with `functools.wraps`, so the op's `_init_fn.__module__` is the module that defined it, not `torch._library.triton`. ## Why precompile needs this A precompile artifact runs on every rank in a fresh process, where nothing has imported the modules that register the custom ops its graphs call. The next commits have the artifact import those modules, found through `torch._library.custom_ops.OPDEFS[name]._init_fn.__module__`. For a `custom_op` that is already the user's module. For a `triton_op` it was `torch._library.triton`, which is importable but registers nothing, so the artifact would import the wrong module and still fail. ## What changes - `triton_op`'s inner `backend_fn` is decorated with `functools.wraps(fn, updated=())`. This copies `__module__`, `__name__`, `__qualname__`, `__doc__` and `__wrapped__`, but not `__dict__`. - Calling the op is unchanged. ## Test plan New test `test_triton_op_function_is_the_users` in `test/test_custom_ops.py`. ``` python test/test_custom_ops.py -k triton_op_function_is_the_users ``` *Written with an AI assistant (Claude Code) and reviewed by me.* Co-Authored-By: Claude Opus 5.5 <[email protected]> Pull Request resolved: pytorch#202256 Approved by: https://github.com/pytorchgreenlight ghstack dependencies: pytorch#202253
… world (pytorch#202253) A fake default process group lets one real rank trace a model sized for the real world (for example 1 rank standing in for 64), but `get_compile_sync_pg` still builds a gloo group over that world, so the trace hangs or segfaults in `gloo::transport::tcp::Rank::Rank` waiting for ranks that do not exist. ## Why precompile needs this Capturing a multi-host training job with `torch.compiler.precompile` runs in a single process under a fake default group sized like the real world. Partitioner and AOTAutograd cache decisions sync across ranks through the compile sync group, which must not rendezvous with peers that are not there. ## What changes - When every device backend of the default group is fake, the compile sync group is fake as well. Its collectives return the local value, so each sync decision is this rank's own. No gloo is needed. - The group's timeout is read from a backend that is not fake and has options, the object-collective device first. This fixes the `AttributeError` on `"cpu:fake,cuda:nccl"`, where the CPU backend is fake. - `sync_cache_decision_cross_ranks` primes the group whenever it can be built rather than only when gloo is available. - Real worlds are unchanged: they still sync over gloo and still raise without it. ## Test plan New tests in `test/distributed/test_fake_pg.py`: all-fake and `cpu:fake` worlds get a fake group without gloo; the backend choice per device-backend config; the timeout comes from the real backend in `cpu:fake,cuda:gloo`; the cache sync primes the fake group without gloo; sync decisions stay local. ``` python test/distributed/test_fake_pg.py python test/distributed/test_inductor_collectives.py -k compile_sync ``` *Written with an AI assistant (Claude Code) and reviewed by me.* Co-Authored-By: Claude Opus 5.5 <[email protected]> Pull Request resolved: pytorch#202253 Approved by: https://github.com/Mingming-Ding
…02256) `torch.library.triton_op` now wraps the user's function with `functools.wraps`, so the op's `_init_fn.__module__` is the module that defined it, not `torch._library.triton`. ## Why precompile needs this A precompile artifact runs on every rank in a fresh process, where nothing has imported the modules that register the custom ops its graphs call. The next commits have the artifact import those modules, found through `torch._library.custom_ops.OPDEFS[name]._init_fn.__module__`. For a `custom_op` that is already the user's module. For a `triton_op` it was `torch._library.triton`, which is importable but registers nothing, so the artifact would import the wrong module and still fail. ## What changes - `triton_op`'s inner `backend_fn` is decorated with `functools.wraps(fn, updated=())`. This copies `__module__`, `__name__`, `__qualname__`, `__doc__` and `__wrapped__`, but not `__dict__`. - Calling the op is unchanged. ## Test plan New test `test_triton_op_function_is_the_users` in `test/test_custom_ops.py`. ``` python test/test_custom_ops.py -k triton_op_function_is_the_users ``` *Written with an AI assistant (Claude Code) and reviewed by me.* Co-Authored-By: Claude Opus 5.5 <[email protected]> Pull Request resolved: pytorch#202256 Approved by: https://github.com/pytorchgreenlight ghstack dependencies: pytorch#202253
…label classes Summary: - Split the mixed TestFakePG class: the fake-PG mechanism tests (copy semantics, requires_grad propagation, validation errors, dispatch tracing) stay in TestFakePG labeled GENERIC, while the nine accelerator-path tests (FSDP/TP e2e, functional-collectives tracing, split_group) move to a new TestFakePGDevice labeled ACCELERATOR. - TestFakePGDevice is instantiated via instantiate_device_type_tests with allow_xpu=True, and the moved methods take the injected device parameter instead of the module-level device_type = get_devtype().type (deleted). - Gate the nine methods with the variant-aware @onlyAccelerator instead of excluding the CPU variant: the CPU variant is collected and skips cleanly on every host (the guard reads the running variant's device_type), so CPU-only machines report explicit skips instead of the class being invisible, while accelerator variants run unchanged. Same gating form as the landed pytorch#192712 and pytorch#191905. @skipIfHpu blacklist guards are kept. - Rebase absorption: keep pytorch#202253's six compile-sync methods in the GENERIC TestFakePG (14 expanded cases, parametrizations and gloo availability guards intact; their config strings naming cuda/nccl do not exercise device-tensor paths) and pytorch#202141's whole-file adjustments (fake backend moved to a Python PyBackend, new GENERIC debug-wrapper/alias/split-options tests, updated assertion patterns); the unittest/unittest.mock imports the new tests use are kept. This allows the accelerator-path tests to run on any out-of-tree accelerator variant instead of being skipped wherever HAS_ACCELERATOR is False, while the device-agnostic fake-PG mechanics stay in a GENERIC class that runs everywhere. Verified on an old-snapshot verify host (its C++ fake backend predates the Python PyBackend move): - The generated CPU class collects 15 cases, all skipped with the exact reason "onlyAccelerator: doesn't run on CPU or meta devices" (OK, 0 errors). - A whole-file run is not obtainable there: a newly absorbed GENERIC test crashes the old C++ fake backend. - The PrivateUse1 variant fails there at the fake backend's device-type lookup (observed error). Full-file validation on the rebased stack remains pending. GENERIC/CPU and accelerator coverage will be checked in the corresponding CI jobs where selected. PrivateUse1 execution additionally requires pytorch#202363 at the new registration site, with the backend plugin loaded before fake registration, and a compatible verification environment; ordinary CPU/CUDA CI does not cover it.
…label classes Summary: - Split the mixed TestFakePG class: the fake-PG mechanism tests (copy semantics, requires_grad propagation, validation errors, dispatch tracing) stay in TestFakePG labeled GENERIC, while the nine accelerator-path tests (FSDP/TP e2e, functional-collectives tracing, split_group) move to a new TestFakePGDevice labeled ACCELERATOR. - TestFakePGDevice is instantiated via instantiate_device_type_tests with allow_xpu=True, and the moved methods take the injected device parameter instead of the module-level device_type = get_devtype().type (deleted). - Gate the nine methods with the variant-aware @onlyAccelerator instead of excluding the CPU variant: the CPU variant is collected and skips cleanly on every host (the guard reads the running variant's device_type), so CPU-only machines report explicit skips instead of the class being invisible, while accelerator variants run unchanged. Same gating form as the landed pytorch#192712 and pytorch#191905. @skipIfHpu blacklist guards are kept. - Rebase absorption: keep pytorch#202253's six compile-sync methods in the GENERIC TestFakePG (14 expanded cases, parametrizations and gloo availability guards intact; their config strings naming cuda/nccl do not exercise device-tensor paths) and pytorch#202141's whole-file adjustments (fake backend moved to a Python PyBackend, new GENERIC debug-wrapper/alias/split-options tests, updated assertion patterns); the unittest/unittest.mock imports the new tests use are kept. This allows the accelerator-path tests to run on any out-of-tree accelerator variant instead of being skipped wherever HAS_ACCELERATOR is False, while the device-agnostic fake-PG mechanics stay in a GENERIC class that runs everywhere. Verified on an old-snapshot verify host (its C++ fake backend predates the Python PyBackend move): - The generated CPU class collects 15 cases, all skipped with the exact reason "onlyAccelerator: doesn't run on CPU or meta devices" (OK, 0 errors). - A whole-file run is not obtainable there: a newly absorbed GENERIC test crashes the old C++ fake backend. - The PrivateUse1 variant fails there at the fake backend's device-type lookup (observed error). Full-file validation on the rebased stack remains pending. GENERIC/CPU and accelerator coverage will be checked in the corresponding CI jobs where selected. PrivateUse1 execution additionally requires pytorch#202363 at the new registration site, with the backend plugin loaded before fake registration, and a compatible verification environment; ordinary CPU/CUDA CI does not cover it.
Stack from ghstack (oldest at bottom):
A fake default process group lets one real rank trace a model sized for the real world (for example 1 rank standing in for 64), but
get_compile_sync_pgstill builds a gloo group over that world, so the trace hangs or segfaults ingloo::transport::tcp::Rank::Rankwaiting for ranks that do not exist.Why precompile needs this
Capturing a multi-host training job with
torch.compiler.precompileruns in a single process under a fake default group sized like the real world. Partitioner and AOTAutograd cache decisions sync across ranks through the compile sync group, which must not rendezvous with peers that are not there.What changes
AttributeErroron"cpu:fake,cuda:nccl", where the CPU backend is fake.sync_cache_decision_cross_ranksprimes the group whenever it can be built rather than only when gloo is available.Test plan
New tests in
test/distributed/test_fake_pg.py: all-fake andcpu:fakeworlds get a fake group without gloo; the backend choice per device-backend config; the timeout comes from the real backend incpu:fake,cuda:gloo; the cache sync primes the fake group without gloo; sync decisions stay local.Written with an AI assistant (Claude Code) and reviewed by me.
Co-Authored-By: Claude Opus 5.5 [email protected]
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @chauhang @amjames @jataylo @azahed98