Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/190846
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (2 Unrelated Failures)As of commit 3c955b4 with merge base f616cd4 ( CRCR (non-blocking) - The following CRCR downstream CI jobs failed but are non-blocking:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
fffrog
left a comment
There was a problem hiding this comment.
Overal look ok to me, thank you for updates.
1361bb5 to
597a3bd
Compare
…nt test in test_multi_threaded_pg
Summary:
- Label `TestCollectivesWithWrapper` and `TestCollectivesWithBaseClass`
with `hw_classification = HardwareClassification.GENERIC` (device-agnostic
threaded-collective logic on CPU tensors).
- Move `test_bwd_sees_fwd_pg` (requires an accelerator, asserts
collective+autograd correctness on a device-tensor path) out of
`TestCollectivesWithBaseClass` into a new parallel
`TestCollectivesWithBaseClassDevice(MultiThreadedTestCase)` class
labeled `hw_classification = HardwareClassification.ACCELERATOR`,
replicating `world_size`/`setUp`/`tearDown`.
- `test_bwd_sees_fwd_pg` takes a `device` parameter and the class is
instantiated via `instantiate_device_type_tests(..., except_for=("cpu",),
allow_xpu=True)`, so the method runs on the current accelerator device
variant (e.g. privateuse1) with the device injected by the framework
rather than a module-level device string. `except_for=("cpu",)` excludes
the CPU variant since this test requires an accelerator
(`@skip_if_lt_x_gpu(1)`). This makes the class a `DeviceTypeTestBase`
subclass, ready for capability-based gating (PR pytorch#190846) when it lands.
This follows the convention that every TestCase subclass carries a
hw_classification label. The split avoids mislabeling the mixed class:
17 CPU threaded methods are GENERIC, the single accelerator-dependent
method is ACCELERATOR.
… 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]>
… 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).
… 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).
fffrog
left a comment
There was a problem hiding this comment.
Nice job, thank you.
Additionally:
Could the changes to test_flop_counter.py be split into a separate PR, focusing solely on the implementation of basic functionality?
980cdbf to
cc86cdc
Compare
albanD
left a comment
There was a problem hiding this comment.
Sounds good!
Let's be careful on not skipping tests by mistakes!
Thank you, we will be careful. :D |
|
@pytorchbot merge |
Merge failedReason: This PR needs a If not, please add the To add a label, you can comment to pytorchbot, for example For more information, see Details for Dev Infra teamRaised by workflow job |
|
@pytorchbot label "topic: not user facing" |
|
@pytorchbot merge |
Merge startedYour 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 |
Summary
Introduce a capability-based test skip mechanism that allows tests to declare required capabilities, including dtype support, feature availability, and library dependencies (e.g. FP8, Flash Attention, and Triton). The mechanism queries the current device capabilities at runtime and automatically skips tests when requirements are not satisfied.
Motivation
Centralize device capability checks
Currently, hardware and feature capability checks are scattered across the test infrastructure. Modules such as
common_cuda.pyandcommon_utils.pyexpose a large number of hardware- and feature-specific global capability flags that tests import directly and combine with decorators.Examples include:
SM*OrLater,IS_SM*)PLATFORM_SUPPORTS_FP8,PLATFORM_SUPPORTS_FLASH_ATTENTION)TEST_CUDNN,has_triton())There are currently ~50 such global capability flags across the test infrastructure, making capability checks difficult to maintain and requiring tests to manually import and compose backend-specific conditions.
Centralizing capability resolution in
DeviceTypeTestBaseallows existing backend-specific capability checks to be aggregated and exposed through a uniform interface. Tests no longer need to directly import and combine scattered global flags or backend-specific conditions.Enable capability reporting for OOT backends
Most existing capability checks are implemented with built-in backend assumptions. For example:
These checks cannot be directly reused by out-of-tree (OOT) backends.
With the capability-based test mechanism, OOT backends can provide their own capability implementations by overriding or monkey-patching capability queries through
PrivateUse1TestBase. For example:Design
Structured capability namespace
A
Capabilityclass with nested namespaces groups related capabilities, so tests referenceCapability.dtype.fp8]instead of bare strings:Capability Registry
Add
get_capabilities()and_capabilities()classmethods toDeviceTypeTestBase, whereget_capabilities()caches capability information provided by backend-specific_capabilities()hooks.Each
DeviceTypeTestBasesubclass defines its own capabilities map, for example:Declaring Requirements
Add
@requires_capabilitydecorator (callget_capabilities()at runtime) to skip tests when required capabilities are unavailable at runtime, for example:Changes
get_capabilities()and_capabilities()classmethods toDeviceTypeTestBase, whereget_capabilities()caches capability information provided by backend-specific_capabilities()hooks._capabilities()implementations forCUDATestBase,CPUTestBase, andXPUTestBaseto provide backend-specific capability queries. The initial set of capabilities covers those required bytest_flop_counter.pyand can be extended incrementally as more tests migrate.@requires_capabilitydecorator to skip tests when required capabilities are unavailable at runtime.Test Plan
pytest test/cpp_extensions/open_registration_extension/torch_openreg/tests/test_testing.py -vvvtest/cpp_extensions/open_registration_extension/torch_openreg/tests/test_testing.py::TestCapabilityGatingOPENREG::test_capability_combined_openreg SKIPPED [0.0008s] (Unsupported capabilities: test.cap_unsupported; Missing capabilities: test.cap_missing) [ 84%] test/cpp_extensions/open_registration_extension/torch_openreg/tests/test_testing.py::TestCapabilityGatingOPENREG::test_capability_missing_openreg SKIPPED [0.0008s] (Missing capabilities: test.cap_missing) [ 88%] test/cpp_extensions/open_registration_extension/torch_openreg/tests/test_testing.py::TestCapabilityGatingOPENREG::test_capability_supported_openreg PASSED [0.0008s] [ 92%] test/cpp_extensions/open_registration_extension/torch_openreg/tests/test_testing.py::TestCapabilityGatingOPENREG::test_capability_unsupported_openreg SKIPPED [0.0008s] (Unsupported capabilities: test.cap_unsupported) [ 96%]Note
This PR introduces an initial set of capabilities. The capability registry is designed to grow incrementally as additional tests adopt
@requires_capabilityand introduce new backend capability requirements.