Skip to content

[Testcase Refactoring] Tag test_format_utils.py with hw_classification - #192045

Open
shichuanliujie9527 wants to merge 2 commits into
pytorch:mainfrom
shichuanliujie9527:test/dcp-format-utils-capability
Open

shichuanliujie9527 wants to merge 2 commits into
pytorch:mainfrom
shichuanliujie9527:test/dcp-format-utils-capability

Conversation

@shichuanliujie9527

@shichuanliujie9527 shichuanliujie9527 commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Classify the distributed format test as ACCELERATOR and keep the two conversion-only tests in a separate GENERIC class.

Changes

  • Instantiate TestFormatUtils with except_for="cpu", allow_xpu=True.
  • Keep conversion-only tests in TestFormatUtilsNoDist without device instantiation.
  • Use the injected device type for both the device mesh and the model, preserving each worker’s rank-local device.
  • Check that the selected device can supply the mesh world size before starting workers, then bind each rank to that device type before creating the process group.
  • Remove the file from the test-linter allowlist.

Validation

The online conversion test passed on four HCCL ranks. Each worker used its own device and the restored weights matched the original state dictionary. With one device available, the worker setup skipped before spawning any processes. The successful CUDA/NCCL path on a mixed-accelerator host remains untested.

Part of #185590.

@pytorch-bot

pytorch-bot Bot commented Aug 4, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

⚠️ 4 Awaiting Approval

As of commit 24d722b with merge base 792c698 (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.

@shichuanliujie9527

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 4, 2026
li-lizhe added a commit to li-lizhe/pytorch that referenced this pull request Aug 5, 2026
… 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]>
li-lizhe added a commit to li-lizhe/pytorch that referenced this pull request Aug 5, 2026
… 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).
@shichuanliujie9527
shichuanliujie9527 force-pushed the test/dcp-format-utils-capability branch from 06cc0ca to 6f6bbbc Compare August 5, 2026 10:57
li-lizhe added a commit to li-lizhe/pytorch that referenced this pull request Aug 6, 2026
… 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 fffrog moved this to Backlog in PyTorch Test Refactoring Aug 7, 2026

@JamesD18 JamesD18 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.

Since the test was not written for XPU, we suggest retaining the current setup without using allow_xpu.

@shichuanliujie9527

Copy link
Copy Markdown
Contributor Author

Good point — this test hasn't been validated on XPU, so allow_xpu=True was
asserting something we can't back up. Dropped it in the latest commit;
instantiate_device_type_tests now just gets except_for="cpu".

For context, allow_xpu defaults to False in
common_device_type.py::get_desired_device_type_test_bases, with a comment
marking it as a temporary opt-in until Intel GPU support is complete — it's
meant to be turned on deliberately per file, not carried along by default.
This has zero effect on the PrivateUse1 (NPU) device class this PR targets;
it only stops generating the XPU variant.

li-lizhe added a commit to li-lizhe/pytorch that referenced this pull request Aug 13, 2026
… 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).
@shichuanliujie9527 shichuanliujie9527 changed the title [Testcase Refactoring] Migrate test_format_utils.py to capability-based gating [Testcase Refactoring] Tag test_format_utils.py with hw_classification Aug 19, 2026

@JamesD18 JamesD18 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.Thanks for addressing the review comments.

kerer-ai pushed a commit to kerer-ai/pytorch-nv that referenced this pull request Aug 26, 2026
kerer-ai pushed a commit to kerer-ai/pytorch-nv that referenced this pull request Aug 26, 2026
@shichuanliujie9527
shichuanliujie9527 force-pushed the test/dcp-format-utils-capability branch from 68d063f to 6caf06a Compare August 28, 2026 09:50
@shichuanliujie9527

Copy link
Copy Markdown
Contributor Author

Good point. I removed the module-level current_accelerator() lookup and the
global device_type. SimpleModelUneven.get_input() now follows the model
parameter device directly, while the distributed test continues to use the
device type injected by instantiate_device_type_tests.

This is the only code change in the follow-up.

@JamesD18 JamesD18 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.Thanks for addressing the review comments.

@shichuanliujie9527
shichuanliujie9527 marked this pull request as ready for review August 31, 2026 02:23

@KarhouTam KarhouTam left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks.
cc @fffrog

@orangeH25 orangeH25 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi @shichuanliujie9527 , I left a few comments. Please take a look when you have a chance.

@shichuanliujie9527

Copy link
Copy Markdown
Contributor Author

@orangeH25 @JamesD18 @KarhouTam Both threads are addressed on the latest head (unused get_input removed; allow_xpu=True added). Could you take another look?

kerer-ai pushed a commit to kerer-ai/pytorch-nv that referenced this pull request Sep 7, 2026
@shichuanliujie9527

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorch-bot

pytorch-bot Bot commented Sep 28, 2026

Copy link
Copy Markdown

This PR has pending changes requested. Please address the comments and update the PR before merging.

@shichuanliujie9527

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Sep 28, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: Approvers from one of the following sets are needed:

  • Distributed (wconstab, mrshenli, pritamdamania87, zhaojuanmao, rohan-varma, ...)
  • Testing (Temporarily used for test refactoring) (fffrog)
  • Metamates (aditvenk, AmesingFlank, angelayi, anshul-si, aorenste, ...)
  • Greenlight Review Bot (pytorchgreenlight)
  • Core Reviewers (mruberry, lezcano, Skylion007, ngimel, peterbell10, ...)
  • Core Maintainers (soumith, gchanan, ezyang, malfet, albanD, ...)
Details for Dev Infra team Raised by workflow job

Failing merge rule: Core Maintainers

@can-gaa-hou can-gaa-hou left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM overall

@shichuanliujie9527
shichuanliujie9527 force-pushed the test/dcp-format-utils-capability branch from 0891e4a to 2b5c5f1 Compare October 21, 2026 04:48
@pytorch-bot

pytorch-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown

The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:

  • ciflow/trunk

Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows.

@KarhouTam

Copy link
Copy Markdown
Collaborator

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased test/dcp-format-utils-capability onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout test/dcp-format-utils-capability && git pull --rebase)

@pytorchmergebot
pytorchmergebot force-pushed the test/dcp-format-utils-capability branch from acd78fe to 524cd3f Compare December 2, 2026 03:01

This branch has not been deployed

No deployments
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 module: tests/distributed This label covers all test cases within the Distributed sheet. open source release notes: distributed (checkpoint) topic: not user facing topic category

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

8 participants