Skip to content

[Testcase Refactoring][FSDP] Decouple optimizer state tests from accelerator selection - #194204

Draft
danieldale2026 wants to merge 5 commits into
pytorch:mainfrom
danieldale2026:test/fsdp-optim-state-hardware-decoupling
Draft

danieldale2026 wants to merge 5 commits into
pytorch:mainfrom
danieldale2026:test/fsdp-optim-state-hardware-decoupling

Conversation

@danieldale2026

@danieldale2026 danieldale2026 commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

I reviewed the code and the quoted PR draft below, verified the reported results, and take responsibility for this submission. The title and quoted body were prepared with agent assistance.

Issue

Part of #185590.

Summary

Keep the FSDP optimizer-state consumer changes in a review-sized parent patch while preserving the existing test behavior.

Changes

  • Classify TestFSDPOptimState as HardwareClassification.ACCELERATOR.
  • Gate class setup on the distributed backend and FSDP capabilities.
  • Thread the harness device through optimizer-state model construction, stepping, and parameterized helpers.
  • Keep the four tail API tests in stacked child [Testcase Refactoring][FSDP] Pass harness device to optimizer-state API tests #195961.
  • Retain the shared FSDP helper ancestry required by the dependency stack.

Motivation

Optimizer-state synchronization is accelerator-generic FSDP behavior. Using the harness device keeps rank-local placement correct while retaining the original assertions and resource gates.

Checklist

  • Added/updated tests.
  • Preserved the existing optimizer-state coverage.
  • Passed lint: spin fixlint is unavailable because uvx/spin is unavailable in the shared WSL environment.
  • Updated documentation: not applicable for this test-only refactor.
  • Included benchmark results: not applicable; no performance behavior change.

Test Plan

  • PYTHONPYCACHEPREFIX=/tmp/pr194204-parent-pycache /home/daniel/workspace/pytorch-dev/pytorch/.venv/bin/python -m py_compile test/distributed/fsdp/test_fsdp_optim_state.py: PASS.
  • git diff --check: PASS.
  • Accelerator runtime: not run for this head; no runtime pass is claimed.

BC-breaking?

No. This changes test classification and device plumbing only.

Notes

  • Base: main@ff9d60a3e6a3002b92dd89bd9949c70a82e3688f.
  • Head: e34006e066cd5fc27cf458e51251e1bc2709875d.
  • Parent consumer delta: +151/-48 (199 changed lines).
  • Current remote stacked total: 4 commits, 4 files, +238/-66; the difference includes shared/helper ancestry.
  • The incremental API-test device refinements remain in [Testcase Refactoring][FSDP] Pass harness device to optimizer-state API tests #195961 (+8/-8).
  • The framework capability files and unrelated consumer files are outside this topic. This Draft remains dependency-blocked.

@pytorch-bot

pytorch-bot Bot commented Aug 20, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

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

@pytorch-bot pytorch-bot Bot added the release notes: distributed (fsdp) release notes category label Aug 20, 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 22, 2026
This commit was authored with AI assistance and reviewed by the contributor.

Test Plan:

```
python3 -m py_compile test/test_testing.py torch/testing/_internal/common_distributed.py torch/testing/_internal/common_fsdp.py test/distributed/fsdp/test_fsdp_optim_state.py
git diff --cached --check
```

Runtime FSDP execution is not verified in the current WSL/A2 projection.
@danieldale2026
danieldale2026 force-pushed the test/fsdp-optim-state-hardware-decoupling branch from c750386 to f9110b3 Compare August 29, 2026 01:31

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "module: tests/distributed"

Keep the optimizer-state consumer PR below the requested review-size boundary by using one class-level distributed/FSDP capability preflight. Preserve all test coverage and behavior while leaving explicit device-argument refinement for the stacked child.

Test Plan:

```bash

PYTHONPYCACHEPREFIX=/tmp/pr194204-parent-pycache python3 -m py_compile test/distributed/fsdp/test_fsdp_optim_state.py

git diff --check

```

spin fixlint was attempted but could not start because uvx is unavailable in this environment.

This commit was authored with AI assistance and reviewed by the contributor.

Copy link
Copy Markdown
Contributor Author

I reviewed the parent and child diffs and confirmed the split preserves the optimizer-state test behavior. The following status update was prepared with agent assistance:

The parent #194204 is now at 50078e8c38770cd4ad2c0fcf18bb9d39fa25270d; its consumer delta is +159/-52 excluding shared helper/framework ancestry.

Draft child #195961 is published at cf30802c018ab3fd6e7cbe5df7a6c793efacefb0 and adds only the explicit harness device parameter to the four tail API tests, +8/-8 relative to the parent.

Validation completed for the child: py_compile PASS and git diff --check PASS. Lint was not run because spin/uvx is unavailable in the environment.

Both PRs remain Draft pending dependency/review; no test coverage was intentionally removed.

Test Plan:

    /home/daniel/workspace/pytorch-dev/pytorch/.venv/bin/python -m py_compile test/distributed/fsdp/test_fsdp_optim_state.py
    git diff --check
    /home/daniel/workspace/pytorch-dev/pytorch/.venv/bin/spin fixlint

The first two commands passed. The lint command was attempted but could not
start because uvx is unavailable in the shared environment.

Consumer diff against upstream/main is +151/-48 (199 changed lines), with the
remaining API device-argument refinements kept in the stacked child.

This commit was authored with AI assistance and reviewed by the contributor.
Test Plan:\n```bash\npython3 -m py_compile <changed Python files>\ngit diff --check\nspin fixlint  # unavailable in this environment: uvx is missing\n```\n\nThis commit was prepared with assistance from an AI assistant and reviewed for correctness before publication.
danieldale2026 added a commit to danieldale2026/pytorch that referenced this pull request Sep 22, 2026
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.
danieldale2026 added a commit to danieldale2026/pytorch that referenced this pull request Sep 22, 2026
Replay only the accepted pytorch#195961 +8/-8 increment on the local pytorch#194204
parent layer. The four remaining tail API tests receive the injected
device and derive its type instead of reading self.device_type. Preserve
the parent DEVICE_BEFORE correction, accelerator admission, continuous
harness and subgroup cleanup behavior without adding child behavior.

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 child-applied 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, 24-method AST preservation,
and exact four-API added/removed lines passed. All AST outside the four
signatures and device assignments is identical to the local parent.
Runtime and collection NOT_RUN; canonical fixed-commit review pending.

@danieldale2026 danieldale2026 left a comment

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’m reviewing these hardware-decoupling changes to catch recurring test issues early and avoid repeated review requests. The inline analysis below was prepared with Codex.



class TestFSDPOptimState(FSDPTest):
hw_classification = HardwareClassification.ACCELERATOR

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.

Codex static review. Several methods in the new ACCELERATOR class still have no device/devices parameter. For example, test_full_optim_state_dict_keys allocates from self.device_type instead of the injected fixture; test_full_optim_state_dict_nested_invalid does the same. Could you thread the fixture through those methods and derive per-rank devices from it where necessary?

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

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