Repository navigation
[Testcase Refactoring] Add distributed test capability gates - #191919
danieldale2026 wants to merge 1 commit into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/191919
Note: Links to docs will display an error until the docs builds have been completed.
|
|
@pytorchbot label "module: tests/distributed" |
|
@pytorchbot label "module: tests/distributed" |
… gating Refactor TestTPFSDPIntegration to the device-agnostic pattern from the testcase-refactoring initiative (pytorch#185590) so it runs on out-of-tree PrivateUse1 backends (NPU) without patching common_fsdp module globals. Introduce TPFSDPIntegrationTestBase(FSDPTestContinuous) that resolves the device and backend at runtime: _resolved_device_type() resolves the generic "privateuse1" token to the registered backend name, backend_str goes through dist.get_default_backend_for_device (npu->hccl, cuda->nccl, no hardcoding), and world_size is accelerator-aware. This mirrors DTensorPPTestBase in pytorch#192051. Tag the class HardwareClassification.ACCELERATOR, since all three methods run multi-device FSDP+TP collectives on an accelerator. Replace @skip_if_lt_x_gpu(4) with @requires_world_size(4) plus @requires_capabilities(Capability.distributed.backend/dtensor/fsdp), the same gates pytorch#192045 uses for the FSDP+DTensor path. Drop the module-level device_type global and point its six call sites at self._resolved_device_type(); the nested TestModel captures the resolved device via closure. Switch instantiate_parametrized_tests to instantiate_device_type_tests(only_for=["cuda","xpu","privateuse1"], allow_xpu=True) so per-device variants are generated and registered PrivateUse1 backends are auto-discovered. No torch_npu or backend-specific import is introduced; backend capability registration is handled separately via register_privateuse1_capabilities (pytorch#192043). Test Plan: The capability-gated form depends on pytorch#190846 (Capability/ requires_capabilities) and pytorch#191919 (Capability.distributed namespace + generalized requires_world_size), not on main yet, so opened as draft until they land (same as pytorch#192045/pytorch#192046). NPU runtime additionally needs pytorch#192043 (register_privateuse1_capabilities) plus the backend's distributed.* registration in the torch_npu repo. The full capability-gated form was validated end-to-end on 4x Ascend 910B4 (privateuse1=npu) by porting the foundation mechanism onto a local checkout (the foundation PRs do not apply cleanly to the older base). With NPU registering distributed.backend/dtensor/fsdp as supported, instantiate_device_type_tests generates the TestTPFSDPIntegrationPRIVATEUSE1 variant and all three tests pass: python test/distributed/fsdp/test_fsdp_tp_integration.py # Testing class TestTPFSDPIntegrationPRIVATEUSE1 on 4 npu # Ran 3 tests ... OK This exercises the FSDPTestContinuous x PrivateUse1TestBase MRO and the @requires_capabilities / @requires_world_size gates on a multiprocess test, both previously open risks for this test type. Authored with the assistance of an AI assistant (Claude Code). Co-Authored-By: Claude <[email protected]>
|
On replacing skip_if_lt_x_gpu with requires_world_size -- I'd push back on swapping them, for two reasons:
|
… gating Refactor TestTPFSDPIntegration to the device-agnostic pattern from the testcase-refactoring initiative (pytorch#185590) so it runs on out-of-tree PrivateUse1 backends (NPU) without patching common_fsdp module globals. Introduce TPFSDPIntegrationTestBase(FSDPTestContinuous) that resolves the device and backend at runtime: _resolved_device_type() resolves the generic "privateuse1" token to the registered backend name, backend_str goes through dist.get_default_backend_for_device (npu->hccl, cuda->nccl, no hardcoding), and world_size is accelerator-aware. This mirrors DTensorPPTestBase in pytorch#192051. Tag the class HardwareClassification.ACCELERATOR, since all three methods run multi-device FSDP+TP collectives on an accelerator. Replace @skip_if_lt_x_gpu(4) with @requires_world_size(4) plus @requires_capabilities(Capability.distributed.backend/dtensor/fsdp), the same gates pytorch#192045 uses for the FSDP+DTensor path. Drop the module-level device_type global and point its six call sites at self._resolved_device_type(); the nested TestModel captures the resolved device via closure. Switch instantiate_parametrized_tests to instantiate_device_type_tests(only_for=["cuda","xpu","privateuse1"], allow_xpu=True) so per-device variants are generated and registered PrivateUse1 backends are auto-discovered. No torch_npu or backend-specific import is introduced; backend capability registration is handled separately via register_privateuse1_capabilities (pytorch#192043). Test Plan: The capability-gated form depends on pytorch#190846 (Capability/ requires_capabilities) and pytorch#191919 (Capability.distributed namespace + generalized requires_world_size), not on main yet, so opened as draft until they land (same as pytorch#192045/pytorch#192046). NPU runtime additionally needs pytorch#192043 (register_privateuse1_capabilities) plus the backend's distributed.* registration in the torch_npu repo. The full capability-gated form was validated end-to-end on 4x Ascend 910B4 (privateuse1=npu) by porting the foundation mechanism onto a local checkout (the foundation PRs do not apply cleanly to the older base). With NPU registering distributed.backend/dtensor/fsdp as supported, instantiate_device_type_tests generates the TestTPFSDPIntegrationPRIVATEUSE1 variant and all three tests pass: python test/distributed/fsdp/test_fsdp_tp_integration.py # Testing class TestTPFSDPIntegrationPRIVATEUSE1 on 4 npu # Ran 3 tests ... OK This exercises the FSDPTestContinuous x PrivateUse1TestBase MRO and the @requires_capabilities / @requires_world_size gates on a multiprocess test, both previously open risks for this test type. Authored with the assistance of an AI assistant (Claude Code).
|
Nice preflight. |
… gating Refactor TestTPFSDPIntegration to the device-agnostic pattern from the testcase-refactoring initiative (pytorch#185590) so it runs on out-of-tree PrivateUse1 backends (NPU) without patching common_fsdp module globals. Introduce TPFSDPIntegrationTestBase(FSDPTestContinuous) that resolves the device and backend at runtime: _resolved_device_type() resolves the generic "privateuse1" token to the registered backend name, backend_str goes through dist.get_default_backend_for_device (npu->hccl, cuda->nccl, no hardcoding), and world_size is accelerator-aware. This mirrors DTensorPPTestBase in pytorch#192051. Tag the class HardwareClassification.ACCELERATOR, since all three methods run multi-device FSDP+TP collectives on an accelerator. Replace @skip_if_lt_x_gpu(4) with @requires_world_size(4) plus @requires_capabilities(Capability.distributed.backend/dtensor/fsdp), the same gates pytorch#192045 uses for the FSDP+DTensor path. Drop the module-level device_type global and point its six call sites at self._resolved_device_type(); the nested TestModel captures the resolved device via closure. Switch instantiate_parametrized_tests to instantiate_device_type_tests(except_for="cpu", allow_xpu=True) so per-device variants are generated and registered PrivateUse1 backends are auto-discovered. No torch_npu or backend-specific import is introduced; backend capability registration is handled separately via register_privateuse1_capabilities (pytorch#192043). Test Plan: The capability-gated form depends on pytorch#190846 (Capability/ requires_capabilities) and pytorch#191919 (Capability.distributed namespace + generalized requires_world_size), not on main yet, so opened as draft until they land (same as pytorch#192045/pytorch#192046). NPU runtime additionally needs pytorch#192043 (register_privateuse1_capabilities) plus the backend's distributed.* registration in the torch_npu repo. The full capability-gated form was validated end-to-end on 4x Ascend 910B4 (privateuse1=npu) by porting the foundation mechanism onto a local checkout (the foundation PRs do not apply cleanly to the older base). With NPU registering distributed.backend/dtensor/fsdp as supported, instantiate_device_type_tests generates the TestTPFSDPIntegrationPRIVATEUSE1 variant and all three tests pass: python test/distributed/fsdp/test_fsdp_tp_integration.py # Testing class TestTPFSDPIntegrationPRIVATEUSE1 on 4 npu # Ran 3 tests ... OK This exercises the FSDPTestContinuous x PrivateUse1TestBase MRO and the @requires_capabilities / @requires_world_size gates on a multiprocess test, both previously open risks for this test type. Authored with the assistance of an AI assistant (Claude Code).
…e preflight from setUp Per review feedback from @JamesD18 (pytorch#191919): - requires_world_size has harness/spawn semantics beyond device availability; changing it here would affect existing NCCL call sites that do not inherit DeviceTypeTestBase. - Restore the original implementation (uses torch.cuda.device_count). - Remove _check_required_world_size() and its call from DeviceTypeTestBase.setUp(). - Keep only the capability preflight (_check_capabilities) in setUp(). - common_distributed.py no longer appears in this PR's incremental diff. Per review feedback from @jishuangfeng (pytorch#191919): - The preflight is intentionally limited to DeviceTypeTestBase-instantiated tests. Direct MultiProcessTestCase subclasses do not expose get_capabilities() or device_type, so capability resolution is not wired into MultiProcessTestCase. Device-count admission continues via @skip_if_lt_x_gpu (hardware-agnostic via pytorch#187650). Capability admission via @requires_capabilities only. Authored with AI assistance.
|
@pytorchbot label "topic: not user facing" |
Per review feedback on pytorch#191919 (@JamesD18), requires_world_size has harness/spawn semantics beyond device availability and should not be used as a drop-in replacement for skip_if_lt_x_gpu. - test_fine_tuning.py: @requires_world_size(4) -> @skip_if_lt_x_gpu(4) - test_save_load_api.py: @requires_world_size(2) -> @skip_if_lt_x_gpu(2) Both retain @requires_capabilities for capability admission (dist.backend, dist.dtensor, dist.fsdp). Device-count admission uses @skip_if_lt_x_gpu (hardware-agnostic via pytorch#187650). Authored with AI assistance.
|
@claude review this pr with pr review skill |
|
Claude finished @can-gaa-hou's task in 25m 21s —— View job Reviewed with the Full review detailsPR Review: #191919SummaryAdds Infrastructure
API Design
Testing
Code Quality
RecommendationRequest Changes The blocking items are the uneven declaration matrix combined with hard-error-on-undeclared (Infrastructure, first bullet) — as written, the consumer PRs this stack exists to unblock will error rather than skip on MPS, Lazy, and out-of-tree PrivateUse1 backends — and the placement of in-tree capability assertions in an OpenReg-only test file, which means those assertions will not run in the CI that would catch a regression. The |
|
AI assistance disclosure: This response was prepared with AI assistance, then reviewed and explicitly authorized for publication by the PR author. I verified the reconciliation against the current PR head
|
Niran814804102
left a comment
There was a problem hiding this comment.
LGTM. Inherited from PR#190834, for the case where the capability map is missing, we need to be aware that the current code will raise AsssertionError.
|
@claude review these changes, check if changes are clear and safe. |
|
Claude finished @KarhouTam's task in 23m 5s —— View job The framework mechanics are safe and the Full review detailsPR Review: #191919SummaryAdds Infrastructure
API Design
Testing
Code Quality
RecommendationRequest Changes The blocker is the Secondary but worth settling before the names are consumed: |
|
@fffrog — your earlier requested-changes review is the one still holding this PR at CHANGES_REQUESTED, so I am asking only you here. The status summary below was prepared with AI assistance; I read it and verified each item against the current PR state before posting.
Could you please re-review the current head when you have a chance? |
…agnostic (#192694) `requires_world_size` is the world-size gate that capability-gated FSDP test migrations (e.g. #192208 and the `test_fsdp_*` series) are migrating **to** from `skip_if_lt_x_gpu`. It hardcodes `torch.cuda.device_count()`, so on any non-CUDA accelerator (XPU/HPU/PrivateUse1) every `@requires_world_size(n)` test is skipped even when devices are present. Generalizes the skip to `torch.accelerator.current_accelerator(check_available=True)` + `torch.get_device_module(acc.type).device_count()`, mirroring `skip_if_lt_x_gpu`'s generalization in #187650. Without this, #187650 alone does not unblock the migrated tests because they call `requires_world_size`, not `skip_if_lt_x_gpu`; #187650 generalized the old function while the migrations target the new one. Sibling to #187650. Independent of the capability foundation PRs #190846/#191919/#192043 (this changes `common_distributed.requires_world_size`, they change `common_device_type.py`). ## Test plan Validated on Ascend 910B (PrivateUse1, `torch.accelerator.device_count()=4`): `@requires_world_size(2)` tests run instead of being skipped ("requires 2 accelerators, found 4"); the 6 capability-gated `test_fsdp_*` files pass on 4-card NPU (56 tests, 0 failures). Container-side shims of the foundation PRs (#190846/#191919) were applied only to provide the Capability/requires_capabilities imports (not yet on main); this change is independent of those. Pull Request resolved: #192694 Approved by: https://github.com/wjlFlyer, https://github.com/fffrog
Replay the accepted pytorch#193067 consumer on the separate pytorch#191919 dependency layer. Both classes now use device-type instantiation with explicit device plumbing and capability gates; all 21 tests, assertions, parameterizations, and resource gates are retained. Consumer scope is one state-dict file. Prepared with an AI assistant (Codex); human publication review is pending. Test Plan ```bash /usr/bin/python3 -B agent_space/comment-closure/validate.py consumer-applied test/distributed/fsdp/test_fsdp_state_dict.py /usr/bin/python3 -B agent_space/comment-closure/semantics.py A git diff --check ``` In-memory compilation, five applicable cached lint checks, and AST checks passed. The +185/-68 patch exactly matches the accepted input. Runtime and collection NOT_RUN; canonical fixed-commit review pending.
Replay the pytorch#194204 consumer topic from 31cee02 on the local pytorch#191919 dependency. Retain current main's FSDPTestContinuous base and both subgroup cleanups. Preserve the parent's DEVICE_BEFORE initialization correction, device plumbing, open accelerator admission and all 24 test methods. This local replay does not update pytorch#194204; the four tail API signatures remain a separate child increment. Prepared with an AI assistant (Codex); human publication review is pending. Test Plan ```bash /usr/bin/python3 -B /home/daniel/workspace/pytorch-dev/worktrees/pytorch/pr193067-comment-closure-20260922/agent_space/comment-closure/validate.py parent test/distributed/fsdp/test_fsdp_optim_state.py /usr/bin/python3 -B /home/daniel/workspace/pytorch-dev/worktrees/pytorch/pr193067-comment-closure-20260922/agent_space/comment-closure/semantics.py B git diff --check ``` In-memory compilation, five cached lint checks and static AST preservation passed. Exact parent content plus the three main drift behaviors verified. Two accepted parent assertions require CPU instead of excluding CUDA/XPU. Runtime and collection NOT_RUN; canonical fixed-commit review pending.
Integrate main be43976 into pytorch#191919 at 925b73c. Both histories changed the test_testing import block, causing the sole merge conflict. Preserve the exact union of both input import sets, retaining TestCase. Remove the prior erroneous gc and HardwareClassification additions. Keep the automatic framework merge and freeze the parent before child consumer work. Prepared with an AI assistant (Codex); human source review required. Test Plan ```bash python3 agent_space/correct_parent_alignment.py ``` Python stdlib AST/compile and selected import inventory passed for the three parent paths. Full read-only main/index/worktree comparison confirms exactly three parent delta paths. No torch import or execution. Lint explicitly waived; collection, runtime, and build not run.
|
I reviewed this replay and its validation evidence. I believe it preserves the previously reviewed capability contract while retaining the intervening main changes. The local lint limitation is disclosed rather than hidden or fixed outside this PR's scope. The quoted summary was prepared with agent assistance.
|
Replay the capability-based test gates onto main while retaining distributed.backend and dtype.fp64. Preserve main's MPS dtype-selection behavior and provider-owned declarations. The removed dtensor/fsdp capability aliases stay absent, with no Dynamo changes. Prepared with AI assistance (Codex). Test Plan --------- The accepted artifact harness executed the stock scoped precommit command with the retained spin launcher, fixed offline tools and read-only source guard. All 20 applicable checkers completed, including actual PYREFLY with zero errors; its existing project exclusions and suppressions still apply. ```sh /usr/bin/python3 -I -B agent_space/local-integration/publication-20261006/consolidated-precommit/cp_execute_02.py plan-ready-02.json gate-02.json ``` The stock command executed inside that recorded enclosure was: ```sh spin quicklint -a -- test/cpp_extensions/open_registration_extension/torch_openreg/tests/test_testing.py test/test_testing.py torch/testing/_internal/common_device_type.py ``` Exact outer/child argv and diagnostics are retained in agent_space/local-integration/publication-20261006/consolidated-precommit. The 162 accepted static assertions are retained evidence, not freshly rerun. Runtime and collection are NOT_RUN because the available native build does not match this main-based candidate.
Linked issue or supporting maintainer
Part of #185590
BC-breaking?
No
Summary (human written only)
Agent details (if applicable)