Skip to content

[Testcase Refactoring] Add distributed capability registration to PrivateUse1TestBase - #193080

Draft
youlituao wants to merge 1 commit into
pytorch:mainfrom
youlituao:test/common_device_type_capabilities
Draft

youlituao wants to merge 1 commit into
pytorch:mainfrom
youlituao:test/common_device_type_capabilities

Conversation

@youlituao

@youlituao youlituao commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Linked issue or supporting maintainer

Part of #185590

BC-breaking

No

Summary

Add a _capabilities() override to PrivateUse1TestBase so that PrivateUse1 backends can participate in the device-type Capability gating introduced in #191919. Without it, tests decorated with @requires_capabilities(Capability.distributed.backend) are silently skipped on out-of-tree PrivateUse1 backends even when the device's default distributed backend is available.

Changes

  • Add a PrivateUse1TestBase._capabilities() override in torch/testing/_internal/common_device_type.py, following the flat identifier -> predicate mapping convention established in [Testcase Refactoring] Add distributed test capability gates #191919 (super()._capabilities() then .update(...)).
  • Declare Capability.distributed.backend via _distributed_backend_available(...), resolving the real registered backend name with torch._C._get_privateuse1_backend_name() so the check reflects the actual out-of-tree device rather than the literal "privateuse1".
  • Reuse the _distributed_backend_available() helper and the Capability.distributed.backend identifier added by [Testcase Refactoring] Add distributed test capability gates #191919; no new capability identifiers are introduced here.

Not changed

  • No distributed.dtensor / distributed.fsdp identifiers are declared. [Testcase Refactoring] Add distributed test capability gates #191919 currently defines only Capability.distributed.backend; declaring the other distributed identifiers (and their predicates) is left as a follow-up once they exist upstream.
  • No changes to the CPUTestBase / CUDATestBase / XPUTestBase / MPSTestBase / HPUTestBase capability declarations.

Depends on

This PR relies on the following upstream PR (submitted but not yet merged):

Without it, Capability.distributed.backend and _distributed_backend_available() do not exist and this override fails to import/resolve.

Test plan

  • On top of the [Testcase Refactoring] Add distributed test capability gates #191919 base, @requires_capabilities(Capability.distributed.backend) tests run on a PrivateUse1 backend whose default distributed backend is available, and skip otherwise.
  • Verified on an Ascend NPU (torch_npu 2.13.0, CANN 9.1.0-beta.1) as a representative out-of-tree PrivateUse1 backend: with this override the gated tests execute; without it they are skipped. CI is the authoritative verification environment.

@pytorch-bot

pytorch-bot Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

⚠️ 4 Awaiting Approval

As of commit 7225cac with merge base 2becd47 (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

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

@pytorch-bot

pytorch-bot Bot commented Aug 12, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@youlituao

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "module: tests/distributed"

@pytorch-bot pytorch-bot Bot added the module: tests/distributed This label covers all test cases within the Distributed sheet. label Aug 12, 2026
@fffrog fffrog moved this to Backlog in PyTorch Test Refactoring Aug 12, 2026
youlituao added a commit to youlituao/pytorch that referenced this pull request Aug 14, 2026
…ty gating

Summary:
- Replace @requires_nccl() with @requires_capabilities(Capability.distributed.backend)
- Replace .cuda(self.rank) with .to(device)
- Replace hardcoded placement with dynamic device_type
- Add hw_classification = HardwareClassification.ACCELERATOR
- Add instantiate_device_type_tests for device-variant generation

Part of pytorch#185590.
Depends on: pytorch#187650, pytorch#190528, pytorch#191919, pytorch#192417, pytorch#193080
youlituao added a commit to youlituao/pytorch that referenced this pull request Aug 14, 2026
…ty gating

Summary:
- Replace @requires_nccl() with @requires_capabilities(Capability.distributed.backend)
- Replace .cuda(self.rank) with .to(device)
- Replace hardcoded placement with dynamic device_type
- Add hw_classification = HardwareClassification.ACCELERATOR
- Add instantiate_device_type_tests for device-variant generation

Part of pytorch#185590.
Depends on: pytorch#187650, pytorch#190528, pytorch#191919, pytorch#192417, pytorch#193080
youlituao added a commit to youlituao/pytorch that referenced this pull request Aug 14, 2026
…on label

Summary:
- Refactor to instantiate_device_type_tests + spawn combination with framework-injected device parameter
- Replace implicit CUDA device-index moves (.to(rank)) with explicit torch.device(device_type, rank); bare device type derived from injected device via torch.device(device).type
- Switch backend admission to @requires_capabilities(Capability.distributed.backend)
- Add hw_classification = HardwareClassification.ACCELERATOR

Depends on: pytorch#187650, pytorch#190528, pytorch#191919, pytorch#193080

Test Plan:
- NPU (PrivateUse1, Ascend 910B3, 4 devices): 2 tests x 4 procs pass (Ran 2 tests - OK), both with PR-CI env vars and full run
- CPU: no variant generated (except_for="cpu"), NO TESTS RAN (expected, same as only_for precedent)
- CUDA: TODO - A100 regression run to be confirmed in PR thread

@Niran814804102 Niran814804102 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

youlituao added a commit to youlituao/pytorch that referenced this pull request Aug 20, 2026
…ators via capability gates

Replace @requires_accelerator_dist_backend(["nccl", "xccl"]) with
@requires_capabilities(Capability.distributed.backend) for capability-based
admission. Add hw_classification = ACCELERATOR and
instantiate_device_type_tests(except_for="cpu").

Keeps ShardedTensorTestBase + with_comms(backend=backend) + TEST_GPU_NUM +
module-level device_type/backend globals unchanged.

Depends on: pytorch#191919, pytorch#193080, pytorch#190528, pytorch#187650
youlituao added a commit to youlituao/pytorch that referenced this pull request Aug 20, 2026
…ators via capability gates

Replace @requires_accelerator_dist_backend(["nccl", "xccl"]) with
@requires_capabilities(Capability.distributed.backend) for capability-based
admission. Add hw_classification = ACCELERATOR and
instantiate_device_type_tests(except_for="cpu").

Keeps ShardedTensorTestBase + with_comms(backend=backend) + TEST_GPU_NUM +
module-level device_type/backend globals unchanged.

Depends on: pytorch#191919, pytorch#193080, pytorch#190528, pytorch#187650
youlituao added a commit to youlituao/pytorch that referenced this pull request Aug 20, 2026
…ators via capability gates

Replace @requires_accelerator_dist_backend(["nccl", "xccl"]) with
@requires_capabilities(Capability.distributed.backend) for capability-based
admission. Add hw_classification = ACCELERATOR and
instantiate_device_type_tests(except_for="cpu").

Keeps ShardedTensorTestBase + with_comms(backend=backend) + TEST_GPU_NUM +
module-level device_type/backend globals unchanged.

Depends on: pytorch#191919, pytorch#193080, pytorch#190528, pytorch#187650
youlituao added a commit to youlituao/pytorch that referenced this pull request Aug 21, 2026
…ators via capability gates

Replace @requires_accelerator_dist_backend(["nccl", "xccl"]) with
@requires_capabilities(Capability.distributed.backend) for capability-based
admission. Add hw_classification = ACCELERATOR and
instantiate_device_type_tests(except_for="cpu").

Keeps ShardedTensorTestBase + with_comms(backend=backend) + TEST_GPU_NUM +
module-level device_type/backend globals unchanged.

Depends on: pytorch#191919, pytorch#193080, pytorch#190528, pytorch#187650
youlituao added a commit to youlituao/pytorch that referenced this pull request Aug 24, 2026
…on label

Summary:
- Refactor to instantiate_device_type_tests + spawn combination with framework-injected device parameter
- Replace implicit CUDA device-index moves (.to(rank)) with explicit torch.device(device_type, rank); bare device type derived from injected device via torch.device(device).type
- Switch backend admission to @requires_capabilities(Capability.distributed.backend)
- Add hw_classification = HardwareClassification.ACCELERATOR

Depends on: pytorch#187650, pytorch#190528, pytorch#191919, pytorch#193080

Test Plan:
- NPU (PrivateUse1, Ascend 910B3, 4 devices): 2 tests x 4 procs pass (Ran 2 tests - OK), both with PR-CI env vars and full run
- CPU: no variant generated (except_for="cpu"), NO TESTS RAN (expected, same as only_for precedent)
- CUDA: TODO - A100 regression run to be confirmed in PR thread
kerer-ai pushed a commit to kerer-ai/pytorch-nv that referenced this pull request Aug 26, 2026
youlituao added a commit to youlituao/pytorch that referenced this pull request Aug 28, 2026
…on label

Summary:
- Refactor to instantiate_device_type_tests + spawn combination with framework-injected device parameter
- Replace implicit CUDA device-index moves (.to(rank)) with explicit torch.device(device_type, rank); bare device type derived from injected device via torch.device(device).type
- Switch backend admission to @requires_capabilities(Capability.distributed.backend)
- Add hw_classification = HardwareClassification.ACCELERATOR

Depends on: pytorch#187650, pytorch#190528, pytorch#191919, pytorch#193080

Test Plan:
- NPU (PrivateUse1, Ascend 910B3, 4 devices): 2 tests x 4 procs pass (Ran 2 tests - OK), both with PR-CI env vars and full run
- CPU: no variant generated (except_for="cpu"), NO TESTS RAN (expected, same as only_for precedent)
- CUDA: TODO - A100 regression run to be confirmed in PR thread
youlituao added a commit to youlituao/pytorch that referenced this pull request Aug 29, 2026
…on label

Summary:
- Refactor to instantiate_device_type_tests + spawn combination with framework-injected device parameter
- Replace implicit CUDA device-index moves (.to(rank)) with explicit torch.device(device_type, rank); bare device type derived from injected device via torch.device(device).type
- Switch backend admission to @requires_capabilities(Capability.distributed.backend)
- Add hw_classification = HardwareClassification.ACCELERATOR

Depends on: pytorch#187650, pytorch#190528, pytorch#191919, pytorch#193080

Test Plan:
- NPU (PrivateUse1, Ascend 910B3, 4 devices): 2 tests x 4 procs pass (Ran 2 tests - OK), both with PR-CI env vars and full run
- CPU: no variant generated (except_for="cpu"), NO TESTS RAN (expected, same as only_for precedent)
- CUDA: TODO - A100 regression run to be confirmed in PR thread
youlituao added a commit to youlituao/pytorch that referenced this pull request Aug 29, 2026
…ators via capability gates

Replace @requires_accelerator_dist_backend(["nccl", "xccl"]) with
@requires_capabilities(Capability.distributed.backend) for capability-based
admission. Add hw_classification = ACCELERATOR and
instantiate_device_type_tests(except_for="cpu", allow_xpu=True).

Add device parameter to all 5 test methods; extract bare device type
via torch.device(device).type for ChunkShardingSpec placements.

Remove module-level device_type/backend globals; use @with_comms(init_rpc=False)
relying on ShardedTensorTestBase.backend property for dynamic backend resolution.

Depends on: pytorch#194992, pytorch#191919, pytorch#193080, pytorch#187650
youlituao added a commit to youlituao/pytorch that referenced this pull request Aug 31, 2026
…on label

Summary:
- Refactor to instantiate_device_type_tests + spawn combination with framework-injected device parameter
- Replace implicit CUDA device-index moves (.to(rank)) with explicit torch.device(device_type, rank); bare device type derived from injected device via torch.device(device).type
- Switch backend admission to @requires_capabilities(Capability.distributed.backend)
- Add hw_classification = HardwareClassification.ACCELERATOR

Depends on: pytorch#187650, pytorch#190528, pytorch#191919, pytorch#193080

Test Plan:
- NPU (PrivateUse1, Ascend 910B3, 4 devices): 2 tests x 4 procs pass (Ran 2 tests - OK), both with PR-CI env vars and full run
- CPU: no variant generated (except_for="cpu"), NO TESTS RAN (expected, same as only_for precedent)
- CUDA: TODO - A100 regression run to be confirmed in PR thread
youlituao added a commit to youlituao/pytorch that referenced this pull request Aug 31, 2026
…on label

Summary:
- Refactor to instantiate_device_type_tests + spawn combination with framework-injected device parameter
- Replace implicit CUDA device-index moves (.to(rank)) with explicit torch.device(device_type, rank); bare device type derived from injected device via torch.device(device).type
- Switch backend admission to @requires_capabilities(Capability.distributed.backend)
- Add hw_classification = HardwareClassification.ACCELERATOR

Depends on: pytorch#187650, pytorch#190528, pytorch#191919, pytorch#193080

Test Plan:
- NPU (PrivateUse1, Ascend 910B3, 4 devices): 2 tests x 4 procs pass (Ran 2 tests - OK), both with PR-CI env vars and full run
- CPU: no variant generated (except_for="cpu"), NO TESTS RAN (expected, same as only_for precedent)
- CUDA: TODO - A100 regression run to be confirmed in PR thread
youlituao added a commit to youlituao/pytorch that referenced this pull request Aug 31, 2026
…on label

Summary:
- Refactor to instantiate_device_type_tests + spawn combination with framework-injected device parameter
- Replace implicit CUDA device-index moves (.to(rank)) with explicit torch.device(device_type, rank); bare device type derived from injected device via torch.device(device).type
- Switch backend admission to @requires_capabilities(Capability.distributed.backend)
- Add hw_classification = HardwareClassification.ACCELERATOR

Depends on: pytorch#187650, pytorch#190528, pytorch#191919, pytorch#193080

Test Plan:
- NPU (PrivateUse1, Ascend 910B3, 4 devices): 2 tests x 4 procs pass (Ran 2 tests - OK), both with PR-CI env vars and full run
- CPU: no variant generated (except_for="cpu"), NO TESTS RAN (expected, same as only_for precedent)
- CUDA: TODO - A100 regression run to be confirmed in PR thread
@youlituao
youlituao marked this pull request as ready for review October 8, 2026 01:41
@github-actions github-actions Bot added bot-triaged This is a label only to be used by the auto triage bot missing actionable issue A PR without a linked actionable issue or maintainer sponsor triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Oct 8, 2026
@soulitzer soulitzer added missing actionable issue A PR without a linked actionable issue or maintainer sponsor and removed missing actionable issue A PR without a linked actionable issue or maintainer sponsor labels Oct 15, 2026
youlituao added a commit to youlituao/pytorch that referenced this pull request Oct 20, 2026
…ators via capability gates

Replace @requires_accelerator_dist_backend(["nccl", "xccl"]) with
@requires_capabilities(Capability.distributed.backend) for capability-based
admission. Add hw_classification = ACCELERATOR and
instantiate_device_type_tests(except_for="cpu", allow_xpu=True).

Add device parameter to all 5 test methods; extract bare device type
via torch.device(device).type for ChunkShardingSpec placements.

Remove module-level device_type/backend globals; use @with_comms(init_rpc=False)
relying on ShardedTensorTestBase.backend property for dynamic backend resolution.

Depends on: pytorch#194992, pytorch#191919, pytorch#193080, pytorch#187650
Add a flat _capabilities() override to PrivateUse1TestBase declaring Capability.distributed.backend via _distributed_backend_available(), resolving the real registered backend name with torch._C._get_privateuse1_backend_name().

Depends on pytorch#191919 for the Capability mechanism.
@youlituao
youlituao force-pushed the test/common_device_type_capabilities branch from 99f62b3 to 7225cac Compare November 14, 2026 03:08
@youlituao
youlituao marked this pull request as draft November 17, 2026 09:07

This branch was previously deployed

1 inactive (outdated) deployment
bedrock — 99f62b30 Deployed Oct 8, 2026 by youlituao
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-triaged This is a label only to be used by the auto triage bot missing actionable issue A PR without a linked actionable issue or maintainer sponsor module: tests/distributed This label covers all test cases within the Distributed sheet. open source triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

4 participants