Skip to content

[Testcase Refactoring][FSDP] Pass harness device to optimizer-state API tests - #195961

Draft
danieldale2026 wants to merge 3 commits into
pytorch:mainfrom
danieldale2026:test/fsdp-optim-state-api-device-20260904
Draft

danieldale2026 wants to merge 3 commits into
pytorch:mainfrom
danieldale2026:test/fsdp-optim-state-api-device-20260904

Conversation

@danieldale2026

@danieldale2026 danieldale2026 commented Sep 4, 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. This references the tracking issue only and does not close it.

Summary

Refine #194204 by passing the explicit device-test harness device to the four remaining optimizer-state API tests: test_interface_arguments, test_state_dict_with_none_tensor_state, test_with_no_shard, and test_no_grad.

Stack layout and scope

This branch has two declared, unmerged ancestry layers:

This PR's own increment relative to the parent is exactly the four tail API signature/device changes in test/distributed/fsdp/test_fsdp_optim_state.py (+8/-8):

Because both ancestry layers are unmerged, the cumulative GitHub diff against main shows four files (+500/-139); only the +8/-8 child delta is newly proposed here.

Changes

Motivation

These tests exercise accelerator-generic FSDP optimizer-state behavior. Passing the harness-selected device removes implicit accelerator selection without changing the tested semantics.

Test Plan

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

  • In-memory compilation and AST parsing of all changed files: PASS.
  • AST identity: reversing only the four child edits reproduces the local parent replay at b3b3301 exactly; the final file equals the accepted child plus main's harness/cleanup drift. All 24 methods and 18 test-body assertion calls 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 optimizer-state), 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 optimizer-state tests generally require 2 devices, 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 device plumbing only.

@pytorch-bot

pytorch-bot Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

⚠️ 4 Awaiting Approval

As of commit c501b06 with merge base 67d293e (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.

@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 Sep 4, 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 Sep 4, 2026
@fffrog fffrog moved this to Backlog in PyTorch Test Refactoring Sep 4, 2026
FSDPInitMode.RECURSIVE if wrap else FSDPInitMode.NO_FSDP,
DEVICEInitMode.DEVICE_BEFORE,
# Initialize on CPU, then move to the current rank's accelerator.
DEVICEInitMode.DEVICE_NEVER,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

DEVICEInitMode.DEVICE_NEVER, refer to:#194204

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 DEVICEInitMode

Thanks! I re-checked #194204: the parent moved init from the earlier DEVICEInitMode.DEVICE_NEVER usage to DEVICEInitMode.DEVICE_BEFORE, and that correction is what this revision retains — the child does not reintroduce DEVICE_NEVER.

Layering in this revision:

  • Parent layer (replay of [Testcase Refactoring][FSDP] Decouple optimizer state tests from accelerator selection #194204, commit b3b3301): keeps DEVICE_BEFORE, the FSDPTestContinuous import/base from the reviewed main baseline 67d293e, and both halve_world_size subgroup cleanups; test_fsdp_optim_state.py +145/-47.
  • Child layer (this PR's own increment, commit c501b06, own diff b3b3301...c501b06): exactly the four tail API tests — test_interface_arguments, test_state_dict_with_none_tensor_state, test_with_no_shard, test_no_grad — taking device and deriving device_type = torch.device(device).type (+8/-8). All 24 methods, assertions, skips, and @skip_if_lt_x_gpu(2) gates are preserved.

Static/AST checks and scoped lint PASS on this head; multi-accelerator runtime and collection were not performed in local validation (the optimizer-state tests generally need 2 devices), 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 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.
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 force-pushed the test/fsdp-optim-state-api-device-20260904 branch from 76dbffb to c501b06 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 re-review request

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

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