Skip to content

[Testcase Refactoring][FSDP] Decouple state and sharding tests from accelerator hardware - #193067

Draft
danieldale2026 wants to merge 2 commits into
pytorch:mainfrom
danieldale2026:test/fsdp-v1-core-hardware-decoupling
Draft

danieldale2026 wants to merge 2 commits into
pytorch:mainfrom
danieldale2026:test/fsdp-v1-core-hardware-decoupling

Conversation

@danieldale2026

@danieldale2026 danieldale2026 commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

I have reviewed the code changes and the accompanying explanations. The changes are reasonable, and I have no further comments.

AI-assisted PR body

Issue

Part of #185590.

Summary

Decouple FSDP v1 state and sharding coverage from fixed accelerator selection. Both TestFSDPStateDict and TestFSDPStateDict4GPUs are now instantiated through instantiate_device_type_tests (CPU case excluded, XPU allowed), while all 21 existing tests, their assertions, parameterizations, and device-count/capability gates are preserved.

Stack layout and scope

This branch is stacked on the unmerged capability-gate PR #191919, present in this branch's ancestry as commit 100dc079 (three harness/test files, +351/-88). That dependency is declared here, not re-proposed.

This PR's own increment relative to that dependency is a single file, test/distributed/fsdp/test_fsdp_state_dict.py (+185/-68):

Because #191919 is unmerged, the cumulative GitHub diff against main also shows its three framework/test files (four files, +536/-156 total); those lines belong to the declared #191919 dependency rather than this PR’s own increment. This branch does not modify the common_fsdp/common_distributed helpers as reviewed at the main baseline 67d293e.

Changes

  • Instantiate TestFSDPStateDict (20 tests) and TestFSDPStateDict4GPUs (test_local_state_dict_reshard) via instantiate_device_type_tests, with CPU excluded and XPU allowed.
  • Thread the injected device through every test while preserving assertions, skips, subtests, and parameterizations.
  • Preserve the dynamic device-count gates (20 two-device tests, one four-device test) and the distributed capability gates from [Testcase Refactoring] Add distributed test capability gates #191919.
  • Keep execution, initialization, training/scaler, and device-specific gate changes in their separate topics.

Motivation

State handling and sharding semantics are not intrinsically tied to one accelerator. Device-type instantiation with capability gates lets capable backends run the same assertions without weakening the tested behavior.

Test Plan

Checks actually run on this revision's head (d73b3a6f):

  • In-memory compilation and AST parsing of all four changed files: PASS.
  • AST comparison confirming all 21 test methods, test-body and helper assertion calls, parameterizations, and resource gates preserved: PASS.
  • Scoped lint over the FLAKE8, RUFF, PYFMT, TEST_HAS_MAIN, and TEST_DEVICE_BIAS families: all 17 unique final file/family pairs for this branch's files PASS (12 shared-dependency + 5 state-dict), with the three configured exclusions from the dependency lint manifest (PYFMT on test/test_testing.py; TEST_HAS_MAIN/TEST_DEVICE_BIAS on torch/testing/_internal/common_device_type.py). This is scoped lint, not full-repo lint or CI.
  • git diff --check: PASS.

Not run, and not claimed:

  • Multi-accelerator runtime and test collection were not performed in local validation; the state-dict tests generally require 2 devices and test_local_state_dict_reshard requires 4, so no runtime pass is claimed.
  • No CI result is claimed in this update; see the PR checks for CI status (pushing can start CI).

BC-breaking?

No. This changes test classification and device plumbing only.

@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/193067

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

❌ 2 New Failures, 4 Unclassified Failures

As of commit d73b3a6 with merge base 67d293e (image):

NEW FAILURES - The following jobs have failed:

UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:

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

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@danieldale2026 danieldale2026 changed the title [FSDP] Decouple core v1 tests from accelerator hardware [Testcase Refactoring] Decouple core FSDP v1 tests from accelerator hardware Aug 12, 2026
@danieldale2026 danieldale2026 changed the title [Testcase Refactoring] Decouple core FSDP v1 tests from accelerator hardware [Testcase Refactoring][FSDP] Decouple core FSDP v1 tests from accelerator hardware Aug 12, 2026
@danieldale2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "topic: not user facing"

@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label Aug 12, 2026
@danieldale2026

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
@danieldale2026
danieldale2026 force-pushed the test/fsdp-v1-core-hardware-decoupling branch from bc457ba to 2686138 Compare August 14, 2026 08:44
@danieldale2026 danieldale2026 changed the title [Testcase Refactoring][FSDP] Decouple core FSDP v1 tests from accelerator hardware [Testcase Refactoring][FSDP] Decouple state and sharding tests from accelerator hardware Aug 14, 2026
@linux-foundation-easycla

linux-foundation-easycla Bot commented Aug 17, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@danieldale2026
danieldale2026 force-pushed the test/fsdp-v1-core-hardware-decoupling branch from fa36e73 to 079de11 Compare August 17, 2026 11:24
@danieldale2026
danieldale2026 force-pushed the test/fsdp-v1-core-hardware-decoupling branch 2 times, most recently from dd90db8 to 166bece Compare August 20, 2026 09:12
kerer-ai pushed a commit to kerer-ai/pytorch-nv that referenced this pull request Aug 26, 2026
@jialinw77

Copy link
Copy Markdown

Some modification is the same as other pr, such as: #191178.
How about extract these modification in a new pr.

@danieldale2026
danieldale2026 force-pushed the test/fsdp-v1-core-hardware-decoupling branch 2 times, most recently from e5f9aae to aa59a7f Compare September 3, 2026 12:23
return torch.rand(8, 8, device=device_type)


class TestFSDPStateDict(FSDPTest):
hw_classification = HardwareClassification.ACCELERATOR

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Testclass tagged accelerator should be instantiated by instantiate_device_type_tests.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Plz also review class TestFSDPStateDict.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have reviewed the code changes and the accompanying explanations. The changes are reasonable, and I have no further comments.

AI-assisted reply on device-type instantiation

Thanks! In this revision, both classes are instantiated by instantiate_device_type_tests:

  • TestFSDPStateDict: all 20 test methods, with the CPU case excluded and XPU allowed.
  • TestFSDPStateDict4GPUs: test_local_state_dict_reshard, likewise instantiated.

All 21 test methods are retained; every test receives the injected device, and the resource gates are preserved (20 two-device tests plus the one four-device test). The change is contained in this PR's own increment: d73b3a6f, own diff 100dc079...d73b3a6f (test/distributed/fsdp/test_fsdp_state_dict.py, +185/-68).

Verification performed on this head: in-memory compilation, AST comparison of methods/assertions/parameterizations/gates, and scoped lint (FLAKE8/RUFF/PYFMT/TEST_HAS_MAIN/TEST_DEVICE_BIAS) all PASS. Multi-accelerator runtime and collection were not performed in local validation — the state-dict tests generally need 2 devices (reshard needs 4) — so no runtime pass is claimed. No CI result is claimed in this update; see the PR checks for CI status.

Local replay of pytorch#191919 at 925b73c
on pinned main 67d293e. Preserve the
accepted flat capability contract: missing declarations fail, unsupported
capabilities skip, and out-of-tree providers own their declarations.
This local dependency freeze does not update pytorch#191919.

Prepared with an AI assistant (Codex); human publication review is pending.

Test Plan
```bash
/usr/bin/python3 -B agent_space/comment-closure/validate.py dependency-r2 torch/testing/_internal/common_device_type.py test/test_testing.py test/cpp_extensions/open_registration_extension/torch_openreg/tests/test_testing.py
git diff --check
```
In-memory compilation and 12 applicable cached lint/file checks passed;
three manifest exclusions. Exact accepted patch and strict-missing AST
checks passed. Runtime and collection NOT_RUN; scoped static checks only.
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.
@danieldale2026
danieldale2026 force-pushed the test/fsdp-v1-core-hardware-decoupling branch from c532d8a to d73b3a6 Compare September 22, 2026 09:44
@danieldale2026

Copy link
Copy Markdown
Contributor Author

I have reviewed the code changes and the accompanying explanations. The changes are reasonable, and I have no further comments.

AI-assisted reply on shared changes

Thanks for flagging the overlap. To make the split explicit in this revision:

  • The genuinely shared framework/test-harness modifications are already extracted into the separate capability-gate PR [Testcase Refactoring] Add distributed test capability gates #191919 (three files, +351/-88). That PR is still unmerged, so its content appears in this branch only as declared stacked ancestry (commit 100dc079); it remains a declared dependency rather than part of this PR’s own increment.
  • Helper changes that have already landed on main are not re-copied: this branch uses the common_fsdp.py and common_distributed.py helpers as reviewed at the main baseline 67d293e, unmodified.
  • This PR's own increment is exactly one file, test/distributed/fsdp/test_fsdp_state_dict.py (+185/-68): own commit d73b3a6f, own diff 100dc079...d73b3a6f.

Since the GitHub PR diff is computed against main and #191919 is not merged yet, the cumulative Files Changed still includes the three dependency files; those lines belong to #191919 rather than this topic. Happy to restructure further if you would prefer a different split.

@danieldale2026

Copy link
Copy Markdown
Contributor Author

I have reviewed the code changes and the accompanying explanations. The changes are reasonable, and I have no further comments.

AI-assisted re-review request

@wjlFlyer Could you please take another look at this revision when you have time? Head: d73b3a6f.

  • Both TestFSDPStateDict and TestFSDPStateDict4GPUs are now instantiated by instantiate_device_type_tests (replies posted in the review thread); all 21 tests and their resource gates are preserved.
  • Own increment: test/distributed/fsdp/test_fsdp_state_dict.py +185/-68 (own diff).
  • Known open items: the branch still stacks on unmerged [Testcase Refactoring] Add distributed test capability gates #191919 (visible in the cumulative diff), and multi-accelerator runtime was not performed in local validation; no CI result is claimed in this update, so see the PR checks for CI status. I am keeping the PR in Draft while those remain open.

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

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

3 participants