Skip to content

add REVIEW.md for test to support test domain instructions - #202723

Closed
fffrog wants to merge 7 commits into
gh/fffrog/165/basefrom
gh/fffrog/165/head
Closed

fffrog wants to merge 7 commits into
gh/fffrog/165/basefrom
gh/fffrog/165/head

Conversation

@fffrog

@fffrog fffrog commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit c6abef4 with merge base 78def3c (image):
💚 Looks good so far! There are no failures yet. 💚
🟡 GreenLight: changes can't be reviewed due to merge_rules.yaml restrictions

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

@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label Oct 30, 2026
@fffrog
fffrog marked this pull request as ready for review October 30, 2026 08:25
@fffrog fffrog moved this from Backlog to Ready for Review(Initial) in PyTorch Test Refactoring Oct 30, 2026
@pytorchgreenlight pytorchgreenlight Bot added the GL/human GreenLight marked as needing human review label Oct 30, 2026

@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 for the contribution. I've left some comments, PTAL.

Comment thread test/REVIEW.md Resolved
Comment thread test/REVIEW.md Resolved
[ghstack-poisoned]
@fffrog
fffrog requested review from albanD and malfet as code owners October 30, 2026 08:39
fffrog added a commit that referenced this pull request Oct 30, 2026
@pytorchgreenlight pytorchgreenlight Bot added GL/superseded GreenLight review is superseded by changes and removed GL/human GreenLight marked as needing human review labels Oct 30, 2026
[ghstack-poisoned]
fffrog added a commit that referenced this pull request Oct 30, 2026
[ghstack-poisoned]
fffrog added a commit that referenced this pull request Oct 30, 2026
Comment thread test/REVIEW.md Resolved
Comment thread test/REVIEW.md Resolved
Comment thread test/REVIEW.md Resolved
[ghstack-poisoned]
fffrog added a commit that referenced this pull request Oct 30, 2026
[ghstack-poisoned]
fffrog added a commit that referenced this pull request Oct 30, 2026

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

Sounds ok in principle. Very strong direction though so we should monitor how it behaves in practice and might have to smooth it out

Comment thread test/REVIEW.md Resolved
Comment thread test/REVIEW.md Resolved
Comment thread test/REVIEW.md Outdated
available accelerator, and every test receives the device under test via its
`device`/`devices` parameter.

- Every test method takes a `device` or `devices` parameter.

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.

And must use it to create Tensors

@fffrog fffrog Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thank you for pointing that out! In theory, that makes total sense.

However, in certain scenarios—especially in distributed tests—some test cases take device or devices parameters purely to resolve the corresponding backend, without actually instantiating tensors inside.

Therefore, it may be safer to expand the use of device or devices in test cases.

Comment thread test/REVIEW.md Resolved
Comment thread test/REVIEW.md Outdated
- `@dtypesIfXPU`
- `@dtypes`
- Class form:
- Must be instantiated via `instantiate_device_type_tests`

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.

Let's also mention that parametrized can also be used

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.

I think instantiate_device_type_tests has bigger coverage. So we recommend to use instantiate_device_type_tests for accelerator related test class and @instantiate_parametrized_tests only for those GENERIC and CPU classes.

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.

You cannot use @parametrize() on these device classes? Or instantiate_device_type_tests also does the @parametrize instantiation? If the latter, we should mention it explicitly.

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.

instantiate_device_type_tests also does the @parametrize instantiation?

Yes and surely we should mention it more clearly.

# In addition to parametrizing over device, dtype, and ops via OpInfos, the
# @parametrize decorator is supported for arbitrary parametrizations:

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Hi,

Here are a few more details on why we strongly prefer using instantiate_device_type_test for ACCELERATOR test classes:

  • instantiate_device_type_test can do everything instantiate_parametrize_test does.
  • instantiate_parametrize_test was not originally designed for multi-accelerator support. For ACCELERATOR test classes, relying on instantiate_device_type_test is a much better fit.
  • We have added several extensions to instantiate_device_type_test to better support out-of-tree accelerators, such as multi-level skip logic and configuration injection. Adopting instantiate_device_type_test will allow out-of-tree accelerators to easily customize these test cases during execution(And we will add more extensions for it if needed later.)

Hope this helps clarify the rationale! Please let us know what you think.

Comment thread test/REVIEW.md

Modifying tests must not reduce their existing coverage without an explicit
explanation. Any coverage reduction must be documented in the PR description
with the reason for the change; an undocumented reduction is a finding.

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.

FYI @ezyang as this is a new "fail on test coverage"

Comment thread test/REVIEW.md Outdated
explanation. Any coverage reduction must be documented in the PR description
with the reason for the change; an undocumented reduction is a finding.

## Rule 7: Requirements for the migration allowlist

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.

Let's move this section to another REVIEW.d in the adapters folder/

@fffrog fffrog Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Got it.

I thought it might be cleaner to split this section into two parts:

  • The part regarding scope reduction (shrinking): I've moved this into a new REVIEW.md inside the adapters/ directory. This makes it easier to monitor changes to this file, and the directory structure allows us to add rules for other adapters in the future easily.
  • The criteria for whether to modify the file or not: I've kept this in the original REVIEW.md, as determining whether a file needs modification falls squarely under the scope of test refactoring.

pytorchmergebot pushed a commit that referenced this pull request Nov 13, 2026
…tantiation (#202776)

Part of #185590.

This PR first added a four-line device fallback. After the review, it now changes `test/distributed/test_functional_api.py` to follow the rules in `test/REVIEW.md` (#202723). It overlaps with #192958, which has had no update since 2026-09-14.

## What changes

- Every test class has one `hw_classification`.
  - `GENERIC`: `TestExpand`, `TestPgTag`, `TestPublicAPI`, `TestGradCollectives`, `TestMetaCollectives`, `TestMakeFx`, `TestAllGatherViewOptimization`, `TestFunctionalAutograd`. Their form does not change.
  - `ACCELERATOR`: `TestTraceableCollectives`, `TestCollectivesWithDistributedBackend`, `TestDistributedBackendCollectivesWithWorldSize4`, `TestFunctionalAutogradWithDistributedBackend`.
- `TestTraceableCollectives` no longer uses `@parametrize("device", devices)` and `instantiate_parametrized_tests`. Each test takes the `device` that `instantiate_device_type_tests` injects, and the class is instantiated for CPU and each accelerator. The class keeps its `MultiThreadedTestCase` base. The seven copies of the device guard are now one method, `_setup_device`.
- The three `DistributedTestBase` classes no longer use `only_for=DEVICE`. They use `except_for=("cpu",)`, so the set of devices does not change.
- `with_comms` takes the device from the injected argument. It uses the device type, because `DeviceMesh` does not accept an index such as `"cuda:0"`. It checks the device count when the default backend of that device is not gloo. Before, it checked the global `BACKEND`.
- The `DEVICE`, `devices` and `BACKEND` globals, the NOTE comment and the `TEST_CUDA`, `TEST_HPU` and `TEST_XPU` imports are removed.
- `test/distributed/test_functional_api.py` is removed from `tools/linter/adapters/test_linter_allowlist.json`.

## Testing

I ran the same change on a copy of the `release/pt_214` test tree of a downstream fork. I linted this `main` branch only. I did not run this branch.

```
# Lint on the changed file (Python 3.14): no messages
python tools/linter/adapters/test_linter.py test/distributed/test_functional_api.py
=> rc 0
# The old file gives 6 hw_classification errors with the same command.

# CPU variants
PYTORCH_TESTING_DEVICE_ONLY_FOR=cpu python test/distributed/test_functional_api.py
=> 24 passed, 1 skipped (TestTraceableCollectivesCPU: 7 passed)
```

On an out-of-tree accelerator (Trainium trn2, torch-neuronx, 8 workers) the file gives 23 passed, 4 skipped and 7 failed. The 7 failures are the `TestTraceableCollectives` tests for that device. They fail with `Inconsistent device IDs found in kernel inputs: expected device 0 but found device 1`. That class runs each rank as a thread of one process, so it needs one process to use several devices. That backend supports one device for each process. This is a limit of that backend and not of the tests. I handle it in the downstream test registry. The accelerator-only classes pass on that backend.

I did not run CUDA, XPU or HPU.

## Notes

- The test names change, because `instantiate_device_type_tests` names the variants. For example `test_broadcast_device_cuda` becomes `test_broadcast_cuda`.
- The bot reports "missing actionable issue". I have no maintainer who agreed to this change. @fffrog, please tell me which issue to link.

An AI assistant (Claude Code) helped to write this change and this text. I reviewed both.

Pull Request resolved: #202776
Approved by: https://github.com/fffrog, https://github.com/albanD
AbigailFernandes added a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Nov 13, 2026
…d device-type instantiation

Part of pytorch#185590. Follows test/REVIEW.md (pytorch#202723).

TestFSDPExecOrder shards models on the injected device, so it is labeled
HardwareClassification.ACCELERATOR. It was instantiated with
only_for=("cuda", "hpu", "xpu"), which the rules do not allow for ACCELERATOR
classes and which excluded every other accelerator (no test ran on an
out-of-tree PrivateUse1 device). It now uses
instantiate_device_type_tests(..., allow_xpu=True). The module-level
device_type global, the devices tuple and the get_devtype import are removed; tests
use self.device_type, as the merged test_fsdp_checkpoint and
test_fsdp_backward_prefetch refactors do. The tests get @onlyAccelerator: skip_if_lt_x_gpu is a
global device-count check, so without it the generated CPU variants would run
FSDP on a CPU module. The file is removed from test_linter_allowlist.json.

Test names gain a device suffix (test_train_eval_... -> test_train_eval_..._cuda).
Coverage: the same 3 tests now also run on every other accelerator; CPU
variants are collected and skipped.

Test Plan:

```
lintrunner test/distributed/fsdp/test_fsdp_exec_order.py tools/linter/adapters/test_linter_allowlist.json
=> ok No lint issues.
python test/distributed/fsdp/test_fsdp_exec_order.py -v
=> Ran 16 tests ... OK (skipped=8)  (8 neuron variants ok, 8 CPU variants skipped)
```

lintrunner was run with PYFMT and TEST_HAS_MAIN skipped, since they need a
libcst build that was not available locally. The second command was run on a
Trainium (trn2) host with an out-of-tree neuron backend, using an older torch
build with upstream main's common_* test helpers copied over (torch_neuronx
does not yet load against current main). Not run on CUDA, XPU or HPU.

This change was authored with an AI assistant (Claude Code) and reviewed by
the author.
AbigailFernandes added a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Nov 13, 2026
… device-type instantiation

Part of pytorch#185590. Follows test/REVIEW.md (pytorch#202723).

TestFSDPFineTune shards models on the injected device, so it is labeled
HardwareClassification.ACCELERATOR. It was instantiated with
only_for=("cuda", "hpu", "xpu"), which the rules do not allow for ACCELERATOR
classes and which excluded every other accelerator. It now uses
instantiate_device_type_tests(..., allow_xpu=True). The module-level
device_type global and the get_devtype import are removed; tests use
self.device_type, as the merged test_fsdp_checkpoint and
test_fsdp_backward_prefetch refactors do. test_hooks_multi_traversal and
test_parity_with_ddp gain the device parameter. All tests get
@onlyAccelerator: skip_if_lt_x_gpu is a global device-count check, so without it
the generated CPU variants would run FSDP on a CPU module. The file is removed
from test_linter_allowlist.json.

Test names gain a device suffix. Coverage: the same 4 tests now also run on
every other accelerator; CPU variants are collected and skipped.

Test Plan:

```
lintrunner test/distributed/fsdp/test_fsdp_fine_tune.py tools/linter/adapters/test_linter_allowlist.json
=> ok No lint issues.
python test/distributed/fsdp/test_fsdp_fine_tune.py -v
=> Ran 8 tests ... OK (skipped=4)  (4 neuron variants ok, 4 CPU variants skipped)
```

lintrunner was run with PYFMT and TEST_HAS_MAIN skipped, since they need a
libcst build that was not available locally. The second command was run on a
Trainium (trn2) host with an out-of-tree neuron backend, using an older torch
build with upstream main's common_* test helpers copied over (torch_neuronx
does not yet load against current main). Not run on CUDA, XPU or HPU.

This change was authored with an AI assistant (Claude Code) and reviewed by
the author.
pytorchmergebot pushed a commit that referenced this pull request Nov 19, 2026
…ard_higher_order_ops.py GENERIC (#204722)

## Linked issue or supporting maintainer

Part of #185590

## BC-breaking?

No

## Summary (human written only)

Labels BackwardHigherOrderOpTests as `GENERIC` per `test/REVIEW.md` (#202723) and removes test/dynamo/test_backward_higher_order_ops.py from `tools/linter/adapters/test_linter_allowlist.json`.

## Agent details (if applicable)

AI-assisted (Claude Code); I reviewed the change and this text.

- Its tests trace and compile CPU tensors; the only device reference is the expected-output string `device(type='cpu')`.
- Only a class attribute and the allowlist entry change; no test logic changes.

Test plan:

```
python3 tools/linter/adapters/test_linter.py test/dynamo/test_backward_higher_order_ops.py
lintrunner test/dynamo/test_backward_higher_order_ops.py tools/linter/adapters/test_linter_allowlist.json
python3 -m py_compile test/dynamo/test_backward_higher_order_ops.py
=> no issues
```

`lintrunner` was run with PYFMT and TEST_HAS_MAIN skipped, since they need a libcst build that was not available locally. The tests were not executed locally.

Pull Request resolved: #204722
Approved by: https://github.com/fffrog, https://github.com/pbielak
pytorchmergebot pushed a commit that referenced this pull request Nov 19, 2026
…bugger.py GENERIC (#204721)

## Linked issue or supporting maintainer

Part of #185590

## BC-breaking?

No

## Summary (human written only)

Labels TestBytecodeDebugger as `GENERIC` per `test/REVIEW.md` (#202723) and removes test/dynamo/test_bytecode_debugger.py from `tools/linter/adapters/test_linter_allowlist.json`.

## Agent details (if applicable)

AI-assisted (Claude Code); I reviewed the change and this text.

- It exercises the bytecode debugger on CPU tensors and plain Python functions, so no device is involved.
- Only a class attribute and the allowlist entry change; no test logic changes.

Test plan:

```
python3 tools/linter/adapters/test_linter.py test/dynamo/test_bytecode_debugger.py
lintrunner test/dynamo/test_bytecode_debugger.py tools/linter/adapters/test_linter_allowlist.json
python3 -m py_compile test/dynamo/test_bytecode_debugger.py
=> no issues
```

`lintrunner` was run with PYFMT and TEST_HAS_MAIN skipped, since they need a libcst build that was not available locally. The tests were not executed locally.

Pull Request resolved: #204721
Approved by: https://github.com/fffrog, https://github.com/pbielak
AbigailFernandes added a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Nov 24, 2026
… device-type instantiation

Part of pytorch#185590. Follows test/REVIEW.md (pytorch#202723).

TestPureFP16 runs FSDP on the injected device, so it is labeled
HardwareClassification.ACCELERATOR. It was instantiated with
only_for=("cuda", "hpu", "xpu"), which the rules do not allow for ACCELERATOR
classes and which excluded every other accelerator. It now uses
instantiate_device_type_tests(..., allow_xpu=True). The module-level
device_type and the get_devtype import are removed: both tests take the
injected device, pass it to their run_subtests helper as device_id, and the
helper derives torch.device(device_id).type (type only, because the injected
device is the primary device and each worker binds its own rank), as
test_fsdp_freezing_weights does. test_pure_fp16_training had no device use of
its own, so it forwards that device_type to _test_fsdp_parity as device_id,
which test_fp16_dtypes already passes to FSDP. Both tests get @onlyAccelerator,
since skip_if_lt_x_gpu is a global device-count check. The file is removed from
test_linter_allowlist.json.

Test names gain a device suffix. Coverage: the same 2 tests; CPU variants are
collected and skipped, and other accelerators now run them.

Test Plan:

```
lintrunner test/distributed/fsdp/test_fsdp_pure_fp16.py tools/linter/adapters/test_linter_allowlist.json
=> ok No lint issues.
python test/distributed/fsdp/test_fsdp_pure_fp16.py -v
=> Ran 4 tests ... OK (skipped=2)  (2 neuron variants ok, 2 CPU variants skipped)
```

lintrunner was run with PYFMT and TEST_HAS_MAIN skipped, since they need a
libcst build that was not available locally. The second command was run on a
Trainium (trn2) host with an out-of-tree neuron backend, using an older torch
build with upstream main's common_* test helpers copied over (torch_neuronx
does not yet load against current main). Not run on CUDA, XPU or HPU.

This change was authored with an AI assistant (Claude Code) and reviewed by
the author.
AbigailFernandes added a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Nov 24, 2026
…d device-type instantiation

Part of pytorch#185590. Follows test/REVIEW.md (pytorch#202723).

TestFSDPExecOrder shards models on the injected device, so it is labeled
HardwareClassification.ACCELERATOR. It was instantiated with
only_for=("cuda", "hpu", "xpu"), which the rules do not allow for ACCELERATOR
classes and which excluded every other accelerator (no test ran on an
out-of-tree PrivateUse1 device). It now uses
instantiate_device_type_tests(..., allow_xpu=True). The module-level
device_type global, the devices tuple and the get_devtype import are removed; tests
use self.device_type, as the merged test_fsdp_checkpoint and
test_fsdp_backward_prefetch refactors do. The tests get @onlyAccelerator: skip_if_lt_x_gpu is a
global device-count check, so without it the generated CPU variants would run
FSDP on a CPU module. The file is removed from test_linter_allowlist.json.

Test names gain a device suffix (test_train_eval_... -> test_train_eval_..._cuda).
Coverage: the same 3 tests now also run on every other accelerator; CPU
variants are collected and skipped.

Test Plan:

```
lintrunner test/distributed/fsdp/test_fsdp_exec_order.py tools/linter/adapters/test_linter_allowlist.json
=> ok No lint issues.
python test/distributed/fsdp/test_fsdp_exec_order.py -v
=> Ran 16 tests ... OK (skipped=8)  (8 neuron variants ok, 8 CPU variants skipped)
```

lintrunner was run with PYFMT and TEST_HAS_MAIN skipped, since they need a
libcst build that was not available locally. The second command was run on a
Trainium (trn2) host with an out-of-tree neuron backend, using an older torch
build with upstream main's common_* test helpers copied over (torch_neuronx
does not yet load against current main). Not run on CUDA, XPU or HPU.

This change was authored with an AI assistant (Claude Code) and reviewed by
the author.
AbigailFernandes added a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Nov 24, 2026
… device-type instantiation

Part of pytorch#185590. Follows test/REVIEW.md (pytorch#202723).

TestFSDPFineTune shards models on the injected device, so it is labeled
HardwareClassification.ACCELERATOR. It was instantiated with
only_for=("cuda", "hpu", "xpu"), which the rules do not allow for ACCELERATOR
classes and which excluded every other accelerator. It now uses
instantiate_device_type_tests(..., allow_xpu=True). The module-level
device_type global and the get_devtype import are removed; tests use
self.device_type, as the merged test_fsdp_checkpoint and
test_fsdp_backward_prefetch refactors do. test_hooks_multi_traversal and
test_parity_with_ddp gain the device parameter. All tests get
@onlyAccelerator: skip_if_lt_x_gpu is a global device-count check, so without it
the generated CPU variants would run FSDP on a CPU module. The file is removed
from test_linter_allowlist.json.

Test names gain a device suffix. Coverage: the same 4 tests now also run on
every other accelerator; CPU variants are collected and skipped.

Test Plan:

```
lintrunner test/distributed/fsdp/test_fsdp_fine_tune.py tools/linter/adapters/test_linter_allowlist.json
=> ok No lint issues.
python test/distributed/fsdp/test_fsdp_fine_tune.py -v
=> Ran 8 tests ... OK (skipped=4)  (4 neuron variants ok, 4 CPU variants skipped)
```

lintrunner was run with PYFMT and TEST_HAS_MAIN skipped, since they need a
libcst build that was not available locally. The second command was run on a
Trainium (trn2) host with an out-of-tree neuron backend, using an older torch
build with upstream main's common_* test helpers copied over (torch_neuronx
does not yet load against current main). Not run on CUDA, XPU or HPU.

This change was authored with an AI assistant (Claude Code) and reviewed by
the author.
AbigailFernandes added a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Nov 24, 2026
…ice-type instantiation

Part of pytorch#185590. Follows test/REVIEW.md (pytorch#202723).

TestInput runs FSDP on the injected device, so it is labeled
HardwareClassification.ACCELERATOR. It was instantiated with
only_for=("cuda", "hpu", "xpu"), which the rules do not allow for ACCELERATOR
classes and which silently excluded every other accelerator (no test ran on
an out-of-tree PrivateUse1 device). It now uses
instantiate_device_type_tests(..., allow_xpu=True), and the module-level
devices tuple is removed. Both tests get @onlyAccelerator: skip_if_lt_x_gpu is a
global device-count check, so without it the generated CPU variant would run
FSDP with a CPU module and device_id. The file is removed from
test_linter_allowlist.json.

Test names gain a device suffix (test_input_type_dict -> test_input_type_dict_cuda,
...). Coverage: the same 2 tests x 2 parametrizations now also run on every
other accelerator; CPU variants are collected and skipped.

Test Plan:

```
lintrunner test/distributed/fsdp/test_fsdp_input.py tools/linter/adapters/test_linter_allowlist.json
=> ok No lint issues.
python test/distributed/fsdp/test_fsdp_input.py -v
=> Ran 8 tests ... OK (skipped=4)  (4 neuron variants ok, 4 CPU variants skipped)
```

lintrunner was run with PYFMT and TEST_HAS_MAIN skipped, since they need a
libcst build that was not available locally. The second command was run on a
Trainium (trn2) host with an out-of-tree neuron backend, using an older torch
build with upstream main's common_* test helpers copied over (torch_neuronx
does not yet load against current main). Before this change the same file
collected 0 tests on that device. Not run on CUDA, XPU or HPU.

This change was authored with an AI assistant (Claude Code) and reviewed by
the author.
AbigailFernandes added a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Nov 24, 2026
…py to device-type instantiation

Part of pytorch#185590. Follows test/REVIEW.md (pytorch#202723).

TestJoin runs the same join-context scenarios on every accelerator (and on
CPU via gloo), so it is labeled HardwareClassification.ACCELERATOR. It now
derives from DistributedTestBase and is instantiated with
instantiate_device_type_tests(..., allow_xpu=True); each test takes the
injected device and builds the process group with create_pg(device_type).
require_n_gpus_for_nccl_backend(WORLD_SIZE, BACKEND) becomes
skip_if_lt_x_gpu(WORLD_SIZE, allow_cpu=True), so the CPU variants still run on
CPU-only machines. The module-level device_type/BACKEND globals and the
hand-written setUp/tearDown/dist_init/device are removed in favor of the base
class. The file is removed from test_linter_allowlist.json.

Test names change because instantiate_device_type_tests names the variants
(e.g. test_join_kwargs -> test_join_kwargs_cpu / _cuda / ...). Coverage: the
same 9 scenarios, now run on every accelerator instead of NCCL/XCCL only,
and still on CPU.

Test Plan:

```
lintrunner test/distributed/algorithms/test_join.py tools/linter/adapters/test_linter_allowlist.json
=> ok No lint issues.
python test/distributed/algorithms/test_join.py -v
=> Ran 18 tests ... OK (9 CPU + 9 PRIVATEUSE1/neuron, 4 workers)
```

The second command was run on a Trainium (trn2) host with an out-of-tree
neuron backend, using an older torch build with upstream main's
common_distributed.py, common_device_type.py and common_fsdp.py copied over
(torch_neuronx does not yet load against current main). Not run on CUDA, XPU
or HPU. The trn2 run predates the final rebase onto main and has not been repeated since.

This change was authored with an AI assistant (Claude Code) and reviewed by
the author.
AbigailFernandes added a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Nov 24, 2026
…stricted device-type instantiation

Part of pytorch#185590. Follows test/REVIEW.md (pytorch#202723).

TestMultipleWrapping runs FSDP on the injected device, so it is labeled
HardwareClassification.ACCELERATOR. It was instantiated with only_for=("cuda", "hpu", "xpu"), which the rules do not allow for ACCELERATOR classes and which excluded every other accelerator. It now uses
instantiate_device_type_tests(..., allow_xpu=True), the module-level device_type
is removed in favor of self.device_type (as the merged test_fsdp_checkpoint and
test_fsdp_backward_prefetch refactors do), and the tests get @onlyAccelerator:
skip_if_lt_x_gpu is a global device-count check, so without it the generated CPU
variants would run FSDP on a CPU module. The file is removed from
test_linter_allowlist.json.

Test names gain a device suffix. Coverage: the same tests; CPU variants are
collected and skipped, and other accelerators now run them.

Test Plan:

```
lintrunner test/distributed/fsdp/test_fsdp_multiple_wrapping.py tools/linter/adapters/test_linter_allowlist.json
=> ok No lint issues.
python test/distributed/fsdp/test_fsdp_multiple_wrapping.py -v
=> Ran 2 tests ... OK (skipped=1)  (1 neuron variant ok, 1 CPU variant skipped)
```

lintrunner was run with PYFMT and TEST_HAS_MAIN skipped, since they need a
libcst build that was not available locally. The second command was run on a
Trainium (trn2) host with an out-of-tree neuron backend, using an older torch
build with upstream main's common_* test helpers copied over (torch_neuronx
does not yet load against current main). Not run on CUDA, XPU or HPU.

This change was authored with an AI assistant (Claude Code) and reviewed by
the author.
AbigailFernandes added a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Nov 24, 2026
…device-type instantiation

Part of pytorch#185590. Follows test/REVIEW.md (pytorch#202723).

TestGradAcc runs FSDP on the injected device, so it is labeled
HardwareClassification.ACCELERATOR. It was instantiated with instantiate_parametrized_tests and read a module-level device_type, so it did not receive the injected device; the two tests now take the device parameter. It now uses
instantiate_device_type_tests(..., allow_xpu=True), the module-level device_type
is removed in favor of self.device_type (as the merged test_fsdp_checkpoint and
test_fsdp_backward_prefetch refactors do), and the tests get @onlyAccelerator:
skip_if_lt_x_gpu is a global device-count check, so without it the generated CPU
variants would run FSDP on a CPU module. The file is removed from
test_linter_allowlist.json.

Test names gain a device suffix. Coverage: the same tests; CPU variants are
collected and skipped, and other accelerators now run them.

Test Plan:

```
lintrunner test/distributed/fsdp/test_fsdp_grad_acc.py tools/linter/adapters/test_linter_allowlist.json
=> ok No lint issues.
python test/distributed/fsdp/test_fsdp_grad_acc.py -v
=> Ran 12 tests ... OK (skipped=6)  (6 neuron variants ok, 6 CPU variants skipped; one neuron variant hit the 300 s per-test limit on its first, cold-compile run and passed in 14 s on a rerun)
```

lintrunner was run with PYFMT and TEST_HAS_MAIN skipped, since they need a
libcst build that was not available locally. The second command was run on a
Trainium (trn2) host with an out-of-tree neuron backend, using an older torch
build with upstream main's common_* test helpers copied over (torch_neuronx
does not yet load against current main). Not run on CUDA, XPU or HPU.

This change was authored with an AI assistant (Claude Code) and reviewed by
the author.
AbigailFernandes added a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Nov 24, 2026
… device-type instantiation

Part of pytorch#185590. Follows test/REVIEW.md (pytorch#202723).

TestPureFP16 runs FSDP on the injected device, so it is labeled
HardwareClassification.ACCELERATOR. It was instantiated with
only_for=("cuda", "hpu", "xpu"), which the rules do not allow for ACCELERATOR
classes and which excluded every other accelerator. It now uses
instantiate_device_type_tests(..., allow_xpu=True). The module-level
device_type and the get_devtype import are removed: both tests take the
injected device, pass it to their run_subtests helper as device_id, and the
helper derives torch.device(device_id).type (type only, because the injected
device is the primary device and each worker binds its own rank), as
test_fsdp_freezing_weights does. test_pure_fp16_training had no device use of
its own, so it forwards that device_type to _test_fsdp_parity as device_id,
which test_fp16_dtypes already passes to FSDP. Both tests get @onlyAccelerator,
since skip_if_lt_x_gpu is a global device-count check. The file is removed from
test_linter_allowlist.json.

Test names gain a device suffix. Coverage: the same 2 tests; CPU variants are
collected and skipped, and other accelerators now run them.

Test Plan:

```
lintrunner test/distributed/fsdp/test_fsdp_pure_fp16.py tools/linter/adapters/test_linter_allowlist.json
=> ok No lint issues.
python test/distributed/fsdp/test_fsdp_pure_fp16.py -v
=> Ran 4 tests ... OK (skipped=2)  (2 neuron variants ok, 2 CPU variants skipped)
```

lintrunner was run with PYFMT and TEST_HAS_MAIN skipped, since they need a
libcst build that was not available locally. The second command was run on a
Trainium (trn2) host with an out-of-tree neuron backend, using an older torch
build with upstream main's common_* test helpers copied over (torch_neuronx
does not yet load against current main). Not run on CUDA, XPU or HPU.

This change was authored with an AI assistant (Claude Code) and reviewed by
the author.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-triage-error ciflow/trunk Trigger trunk jobs on your pull request GL/superseded GreenLight review is superseded by changes Merged open source topic: not user facing topic category

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

8 participants