Skip to content

[Testcase Refactoring] Device-agnostic move_to_device_pass tests via instantiate + device - #191079

Closed
SHIHAIFENG15 wants to merge 9 commits into
pytorch:mainfrom
SHIHAIFENG15:npu-export-device-agnostic-passes
Closed

SHIHAIFENG15 wants to merge 9 commits into
pytorch:mainfrom
SHIHAIFENG15:npu-export-device-agnostic-passes

Conversation

@SHIHAIFENG15

@SHIHAIFENG15 SHIHAIFENG15 commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Make move_to_device_pass tests in test_passes.py device-agnostic via instantiate_device_type_tests and injected device, so accelerators including privateuse1 (NPU) are covered.

Changes

  • Move move_to_device cases into TestPassesDevice with hw_classification = ACCELERATOR and except_for="cpu".
  • Replace hardcoded "cuda" / @requires_gpu with the injected device.
  • Keep assertExpectedInline goldens, parameterized by device_type.
  • Keep the RNN case in the same TestPassesDevice class (no separate TestPassesRNN).

Test Plan

python test/export/test_passes.py -v -k TestPassesDevice

Local NPU:

python test/export/test_passes.py -v -k TestPassesDevice
(with PYTORCH_TESTING_DEVICE_ONLY_FOR=privateuse1, import torch_npu before run)

Result: Ran 4 tests — 3 passed, 1 error

PASS: test_move_device_to_npu, test_move_device_submod_npu, test_move_device_example_inputs_npu
ERROR: test_move_to_device_pass_npu — DynamicGRUV2 unsupported on NPU (float32 GRU); torch_npu backend gap, not a pass regression
This is a torch_npu backend gap (DynamicGRUV2), not a move_to_device_pass bug. The case stays on the accelerator class (no per-device skip). Tracking: https://gitcode.com/Ascend/pytorch/issues/3886
CPU: not run (TestPassesDevice uses except_for="cpu").

@wjlFlyer @pjyFight @FuDdd @fffrog @lyriexs666 @jishuangfeng @JamesD18 @JiasenTian

@pytorch-bot

pytorch-bot Bot commented Jul 25, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit c31d94a with merge base ff30875 (image):
💚 Looks good so far! There are no failures yet. 💚

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 Jul 25, 2026
@SHIHAIFENG15
SHIHAIFENG15 force-pushed the npu-export-device-agnostic-passes branch from 63746ec to 04a237e Compare July 25, 2026 08:46
@SHIHAIFENG15

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "module: tests/graph"

@pytorch-bot pytorch-bot Bot added the module: tests/graph This label covers all test cases within the Graph sheet. label Jul 25, 2026
@fffrog fffrog moved this to Developing in PyTorch Test Refactoring Jul 27, 2026
@ezyang
ezyang requested a review from fffrog July 27, 2026 18:32
@ezyang ezyang added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Jul 27, 2026
@SHIHAIFENG15 SHIHAIFENG15 changed the title [Test] Device-agnostic move_to_device_pass tests via instantiate + device [Testcase Refactoring] Device-agnostic move_to_device_pass tests via instantiate + device Jul 28, 2026

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

Thanks for the PR! Overall lgtm minor some small nits. Please take a look.

Comment thread test/export/test_passes.py Outdated
@unittest.skipIf(not TEST_CUDA, "requires cuda")
def test_move_to_device_pass(self):
def test_move_device_example_inputs(self, device):
device_type = str(device).split(":", 1)[0]

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.

Suggested change
device_type = str(device).split(":", 1)[0]
device_type = torch.device(device).type

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.

done

Comment thread test/export/test_passes.py Outdated
self.assertEqual(ep_moved.example_inputs[1]["z"].device, torch.device(device0))

def test_move_to_device_pass(self, device):
device_type = str(device).split(":", 1)[0]

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.

Ditto

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.

done

Comment thread test/export/test_passes.py Outdated
Comment on lines +1419 to +1420
if device_type not in ("cuda", "xpu"):
self.skipTest("move_to_device_pass RNN is supported only on cuda/xpu")

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.

If this test is not device-generic, please add another device-specific class (e.g. TestPassesCUDA or something?) and move to it. Try your best not to explicitly skip a specific device in the test unless you have to.

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.

Thanks for the review. Addressed the nits:

  • use torch.device(device).type instead of string split
  • move the RNN case into TestPassesRNN with only_for=("cuda", "xpu") (no in-method device skip)

@lizhihai137 lizhihai137 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

please review

Comment thread test/export/test_passes.py Outdated
self.assertEqual(ep_cuda.example_inputs[0][1].device, torch.device("cuda:0"))
self.assertEqual(ep_cuda.example_inputs[1]["z"].device, torch.device("cuda:0"))
instantiate_device_type_tests(TestPassesDevice, globals(), except_for="cpu")
instantiate_device_type_tests(TestPassesRNN, globals(), except_for="cpu")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why is it necessary to split the TestPassesRNN test case when the accelerator types of the test cases are the same?

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.

Thanks — merged TestPassesRNN into TestPassesDevice since both used the same ACCELERATOR classification and except_for="cpu" instantiate settings.

@lizhihai137 lizhihai137 left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

thank you for your contributions

fffrog
fffrog previously approved these changes Aug 12, 2026

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

Overall look ok to me ,thank you for your contributions.

Comment thread test/export/test_passes.py Outdated
add = torch.ops.aten.add.Tensor(to, to); to = None
return (add,)
""",
)

@unittest.skipIf(not TEST_CUDA, "requires cuda")
def test_move_to_device_pass(self):

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.

Why swap the positions of test_move_to_device_pass and test_move_device_example_inputs? This would increase the difficulty of review.

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.

The method order follows the original TestPasses class in main (move_device_example_inputs → move_device_submod → move_device_to → move_to_device_pass).

@SHIHAIFENG15

Copy link
Copy Markdown
Contributor Author

Updated the PR to preserve the complete device injected by instantiate_device_type_tests instead of reconstructing <device_type>:0. Device-type-only values are still used where required, such as autocast and the type-only remapping checks. I also enabled XPU instantiation with allow_xpu=True. The RNN test remains device-agnostic with the other accelerator tests.

@SHIHAIFENG15
SHIHAIFENG15 force-pushed the npu-export-device-agnostic-passes branch from 8033836 to c9ed1b5 Compare August 18, 2026 09:26
kerer-ai pushed a commit to kerer-ai/pytorch-nv that referenced this pull request Aug 26, 2026
@fffrog fffrog moved this from Developing to Ready for Review(Definitive) in PyTorch Test Refactoring Aug 26, 2026
kerer-ai pushed a commit to kerer-ai/pytorch-nv that referenced this pull request Aug 26, 2026
@can-gaa-hou

Copy link
Copy Markdown
Collaborator

@claude review this pr with pr review skill

@claude

claude Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

Claude finished @can-gaa-hou's task in 14m 17s —— View job


Reviewed with the /pr-review skill — the refactor is directionally right, but the f-string assertExpectedInline goldens break the EXPECTTEST_ACCEPT=1 workflow and the newly-enabled XPU path appears unverified.

Full PR review (click to expand)

PR Review: #191079

Summary

Converts the four move_to_device_pass tests in test/export/test_passes.py from hardcoded-cuda + skipIf(not TEST_CUDA) into a TestPassesDevice class driven by instantiate_device_type_tests(..., except_for="cpu", allow_xpu=True). The device plumbing itself is correct, but the golden strings were converted to f-strings, which breaks expecttest's accept path, and the test plan shows no CUDA or XPU run despite the PR newly enabling XPU.

Testing

1. f"""...""" goldens break the EXPECTTEST_ACCEPT=1 accept workflow. test/export/test_passes.py:1349 and :1372

self.assertExpectedInline(
    ep.graph_module.code.strip("\n"),
    f"""\
def forward(self, x):
    _assert_tensor_metadata_default = ... device = '{device_type}' ...

expecttest's accept path rewrites the source literal in place. Two problems follow:

  • Its literal-matching regex handles only the r prefix ((?<=\W)([+~]?)(r?)(["'])...); the f prefix means the character preceding """ is \w, so the lookbehind fails at the intended position. The repo already documents this class of failure: test/dynamo/test_export.py:3483 carries # TODO: This is naughty, EXPECTTEST_ACCEPT=1 doesn't work on a .format()-parameterized golden.
  • Even if it did match, accepting would bake the concrete runtime device ('cuda') into the source and destroy the {device_type} placeholder — silently converting the test back to CUDA-only.

These are 30-line multi-line graph goldens; --accept is the primary way they get maintained when the exporter's printed IR changes. Losing it is a real maintainability regression, not a cosmetic one.

The established pattern is a static golden plus post-hoc normalization — see test/inductor/test_max_autotune.py:2422-2438:

expected = """{
    'input_nodes':[
        "[[10,22],[22,1],torch.float32,device(type='cuda',index=0),0]", ...
expected = expected.replace("cuda", GPU_TYPE)
self.assertExpectedInline(remove_white_space(cache_key), remove_white_space(expected))

Applying that here keeps the literal static (so --accept works) while still parameterizing the device. Fix this →

2. allow_xpu=True newly enables these goldens on XPU, but the test plan shows no XPU or CUDA run. test/export/test_passes.py:1450-1452

allow_xpu=True is what causes XPUTestBase to be appended (common_device_type.py:1035-1036) — XPU is not in the default bases (get_device_type_test_bases, common_device_type.py:931-936). So this PR turns on a device that was never exercised by these tests before, and the PR body reports only a privateuse1/NPU run ("CPU: not run", no CUDA, no XPU). Since two of the four tests assert on exact printed IR and a third runs torch.nn.GRU on-device, "should work" is not sufficient — please post the output of:

python test/export/test_passes.py -v -k TestPassesDeviceXPU
python test/export/test_passes.py -v -k TestPassesDeviceCUDA

3. The GRU test is known-failing on the exact backend this PR exists to enable, with no skip and no tracking issue. test/export/test_passes.py:1413-1447

The PR body states test_move_to_device_pass_npu errors ("DynamicGRUV2 unsupported on NPU"). So after this lands, privateuse1 gets a permanently red test with nothing in-tree explaining it. @can-gaa-hou asked earlier to avoid per-device skips, and that is the right instinct — but the alternative cannot be shipping a known failure silently. Please either link a torch_npu tracking issue in a comment on the test, or narrow the GRU case so it does not claim coverage it does not have. This also does not block pytorch/pytorch CI (no NPU CI exists), which is precisely why it will go unnoticed.

4. On a CPU-only host these four tests now vanish rather than skip. test/export/test_passes.py:1450

instantiate_device_type_tests unconditionally does del scope[generic_test_class.__name__] (common_device_type.py:1108) and then generates classes only for available bases (:1114). With except_for="cpu" and no accelerator, zero test classes are produced. Previously @unittest.skipIf(not TEST_CUDA, "requires cuda") surfaced four explicit skips in the CI report. This is a standard tradeoff of the framework rather than a bug, but it does mean the loss of coverage on a misconfigured runner reads as green rather than as skipped — worth being deliberate about.

Code Quality

5. hw_classification = HardwareClassification.GENERIC on TestPasses is unrelated to this PR. test/export/test_passes.py:378

TestPasses is not passed to instantiate_device_type_tests and is otherwise untouched by this change. The classification is defensible on its own (it makes the class visible under --hw-classification GENERIC filtering), but it is undescribed in the PR body and expands the blast radius of a test-refactor PR. Either mention it in the description or split it out.

Note for reviewers: HardwareClassification does not exist at this branch's merge base (da9c79b0) — it was added to torch/testing/_internal/common_utils.py:127 on main afterwards. The file therefore cannot import on the branch as checked out; it only resolves against current main. CI tests the merge commit so this should be green, but a rebase would make local verification possible.

6. test_move_device_submod mixes type-only and indexed device without explanation. test/export/test_passes.py:1358-1368

torch.autocast(device_type=device_type) takes the type, x.to(device=device) takes the indexed form, and move_to_device_pass(ep, device_type) takes the type again. Each choice is individually correct, but the three-way split within eight lines is non-obvious to a future reader. One short comment noting that autocast and the pass target a device type while the tensor move targets a concrete device would carry its weight here.

Verified as correct (no action needed)

Recorded only because they were plausible failure modes I checked and ruled out, so they need not be re-investigated:

  • except_for="cpu" as a bare string is handled — common_device_type.py:968-972 explicitly branches on isinstance(except_for, str).
  • assertEqual on two torch.device objects compares type and index (c10/core/Device.h:50-51); .to("cuda:0").device == torch.device("cuda:0") holds.
  • {"cpu": str(target_device)} at :1442 genuinely exercises the dict-remap branch: a CPU device has index == -1, so Device::str() (c10/core/Device.cpp:151-158) yields "cpu" and the key matches. A miss would fail loudly at :1447, not pass vacuously.
  • Baking the indexed device into the module at :1341 while calling the pass with device_type preserves the pre-PR semantics and remains correct for a nonzero primary device index, since the pass overwrites the burnt-in device with the type-only form.
  • Class-level @skipIfTorchDynamo / @unittest.skipIf survive instantiation — they set __unittest_skip__ as a class attribute (common_utils.py:1938-1940) and the generated class inherits it via type(name, (base, generic_test_class), {}) (common_device_type.py:1125).
  • hw_classification is likewise inherited by the generated device classes and is complementary to except_for, not redundant with it.

Recommendation

Request Changes

Finding 1 is a concrete regression in test maintainability with a cheap, established fix already used elsewhere in the repo. Finding 2 asks only for evidence that the device coverage this PR advertises actually passes — given two goldens and an on-device GRU, an NPU-only test run is not enough to land XPU and CUDA enablement. Finding 3 should be resolved by a tracking-issue reference rather than by weakening the test.

| Branch: `npu-export-device-agnostic-passes`

…vice

Migrate CUDA-hardcoded / CPU-only device checks in test_passes.py to a
single device-agnostic class `TestPassesDevice` using
instantiate_device_type_tests with an injected `device`, so accelerators
including privateuse1 (NPU) are covered for the move_to_device_pass suite.

The move_to_device tests are split out of the TestExportPasses suite into
`TestPassesDevice` (except_for="cpu"). Golden strings are kept as
assertExpectedInline but parameterized by `device_type` (f-string), so the
expected graph code follows the injected device rather than a literal
"cuda".

The RNN case is scoped to cuda/xpu only via a per-method runtime skip
(`device_type not in ("cuda","xpu")`): NPU fp32 GRU fails after
move_to_device_pass via DynamicGRUV2, so it is not whitelisted. A single
class is used instead of two because instantiate_device_type_tests
applies one device filter per class; the RNN exclusion is therefore done
per-method. Note that on NPU the injected `device` strings as "npu:0"
(torch_npu renames privateuse1), so the skip keys on the device string
rather than the "privateuse1" dispatch name.

The class retains `@skipIfTorchDynamo("recursively running dynamo on
export is unlikely")` (in addition to `@unittest.skipIf(not
is_dynamo_supported(), ...)`) carried over from the original TestPasses
class on main; dropping it would let the tests run under dynamo
unintendedly.

No HAS_GPU/GPU_TYPE used as the NPU entry path; device entry is
instantiate + injected `device`.

Test Plan:
```
# CPU (except_for="cpu" -> 0 tests, confirms no import/syntax regression)
source /home/y00839695/npu-pytorch-setup/venv_cpu/bin/activate
python test/export/test_passes.py -v -k TestPassesDevice

# NPU (after sourcing CANN env + venv_npu)
export PYTORCH_TESTING_DEVICE_ONLY_FOR=npu
python test/export/test_passes.py -v -k TestPassesDevice
# 3 move_device tests ok, test_move_to_device_pass skipped
# (RNN supported only on cuda/xpu)
```
Tag TestPasses as GENERIC and TestPassesDevice (instantiate) as
ACCELERATOR for --hw-classification filtering.

Test Plan:
```
python test/export/test_passes.py --hw-classification ACCELERATOR -v -k TestPassesDevice
python test/export/test_passes.py --hw-classification GENERIC -v -k TestPasses
```
Use torch.device(device).type instead of string split. Move the RNN
move_to_device_pass case into TestPassesRNN with only_for=("cuda", "xpu")
instead of an in-method device skipTest.

Test Plan:
```
python test/export/test_passes.py -v -k 'TestPassesDevice or TestPassesRNN'
```
Replace only_for=("cuda", "xpu") with except_for="cpu" so non-CUDA
accelerators are covered by instantiate, matching other device-agnostic
move_to_device_pass coverage.

Test Plan:
```
python test/export/test_passes.py -v -k 'TestPassesDevice or TestPassesRNN'
```
TestPassesRNN used the same ACCELERATOR hw_classification and
except_for="cpu" instantiate settings as TestPassesDevice, so keep a
single class and move test_move_to_device_pass onto TestPassesDevice.

Test Plan:
```
python test/export/test_passes.py -v -k TestPassesDevice
```
The device-agnostic conversion reconstructed every target as device zero, which ignored the primary device selected by the test framework. Use the complete injected device for tensor placement, remapping, and assertions while retaining device-type-only values where the API requires them, and opt the class into XPU instantiation.

Test Plan:
```
git diff --check
```

`lintrunner -a` was attempted but could not run because `uv` is unavailable in the local environment.

Authored with AI assistant.
The original tests were CUDA-only, so do not instantiate XPU. Replace
f-string goldens with a static cuda string plus replace() so
EXPECTTEST_ACCEPT can still rewrite the literal.

Test Plan:
```
python test/export/test_passes.py -v -k TestPassesDevice
```
@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

Rebase failed due to Command git -C /home/runner/work/pytorch/pytorch rebase --onto refs/remotes/origin/viable/strict a8f05b4c4f33a94860f139ebb6b46af0ae8cc2f1 pull/191079/head returned non-zero exit code 1

Rebasing (1/7)
Auto-merging test/export/test_passes.py
CONFLICT (content): Merge conflict in test/export/test_passes.py
error: could not apply 222d4aff6d2... [Test] Device-agnostic move_to_device_pass tests via instantiate + device
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Could not apply 222d4aff6d2... # [Test] Device-agnostic move_to_device_pass tests via instantiate + device

Raised by https://github.com/pytorch/pytorch/actions/runs/38241835430

pytorch#196974 already moved these tests onto instantiate_device_type_tests for CUDA and XPU, and pytorch#185105 added the CUDA recompile regressions. Keep that code, and open the device class to other non-CPU backends with except_for="cpu" while retaining allow_xpu=True.

Test Plan:
```
python -m pytest test/export/test_passes.py --collect-only -q
# 28 tests collected on CPU. TestMoveToDevicePassDevice is not generated without an accelerator, which matches except_for="cpu".
```

@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

@SHIHAIFENG15

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 Oct 13, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

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

  • Testing (Temporarily used for test refactoring) (fffrog)
  • Metamates (aditvenk, angelayi, anshul-si, aorenste, atalman, ...)
  • 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

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

SGTM, thank you for fixing this one

Comment thread test/export/test_passes.py Outdated

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 @SHIHAIFENG15 , this one should be CUDA, right? Could you mind fixing it while you are at it?

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.

Sure, fixed it.

TestMoveToDevicePassCuda hardcodes cuda:0 and skips unless CUDA is available, so its hardware classification is CUDA rather than the accelerator-generic label.

Test Plan:
```
.venv/bin/lintrunner -a test/export/test_passes.py
```
lintrunner reported no lint issues. This machine has no CUDA, so the tests themselves still skip; loading the module shows TestMoveToDevicePassCuda.hw_classification is HardwareClassification.CUDA.

Authored with an AI assistant.
@pytorch-bot

pytorch-bot Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

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

@SHIHAIFENG15

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 3 mandatory check(s) failed. The first few are:

Dig deeper by viewing the failures on hud

Details for Dev Infra team Raised by workflow job

Failing merge rule: Core Maintainers

@SHIHAIFENG15

Copy link
Copy Markdown
Contributor Author

Could you approve the workflows so CI can run? @KarhouTam

@SHIHAIFENG15

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@github-project-automation github-project-automation Bot moved this from Ready for Review(Definitive) to Done in PyTorch Test Refactoring Oct 15, 2026
pytorchmergebot pushed a commit to tszulist-hbn/pytorch that referenced this pull request Nov 13, 2026
…rators

Four move_to_device_pass tests sat in TestMoveToDevicePassCuda behind
skipIf(not TEST_CUDA) with "cuda:0" hard-coded, so XPU and other
accelerators skipped them. Nothing in them is CUDA-specific. They check
that the moved GraphModule and its nested torch.cond submodules are
recompiled, that the source module's parameters and buffers are not
mutated, and that wrapper-subclass parameters move with their inner
tensors.

Root cause: pytorch#185105 added the tests behind a TEST_CUDA gate. pytorch#196974
moved the four older move_to_device_pass tests into the device-generic
TestMoveToDevicePassDevice but left these behind, and pytorch#191079 then
tagged their class CUDA to match its gate.

Move them into TestMoveToDevicePassDevice with a device parameter, drop
the gates and replace each "cuda:0" with device. The instantiated
primary device always carries an index (cuda:N, xpu:N,
<privateuse1>:N), so the code and device-equality assertions behave as
before on CUDA. After the previous commit the CUDA class is empty, so
delete it and the now-unused TEST_CUDA import.

XPU, PrivateUse1 and HPU gain the four tests. CUDA keeps them as
TestMoveToDevicePassDeviceCUDA::<name>_cuda. On a machine without an
accelerator they are no longer collected instead of being reported as
skipped, the same trade-off pytorch#196974 made. Widening the gate to TEST_CUDA
or TEST_XPU was the alternative; it keeps the hard-coded device and
leaves PrivateUse1 out.

See intel/torch-xpu-ops#5994.

Test Plan:

The same AST comparison as the previous commit: the four methods match
the originals once device maps back to 'cuda:0' and the device parameter
and TEST_CUDA skip are dropped. The other 40 methods are unchanged.

On an Intel Data Center GPU Max 1550:

```
python test/export/test_passes.py -v -k move_device -k move_to_device
python test/export/test_passes.py
```

All 8 TestMoveToDevicePassDeviceXPU tests pass, 4 of them new. The whole
file goes from OK (skipped=4, expected failures=2) to
OK (expected failures=2) with the same 39 tests. The only ID changes are
TestMoveToDevicePassCuda::<name> ->
TestMoveToDevicePassDeviceXPU::<name>_xpu. CUDA was not run locally.

Authored with an AI assistant (Claude Code).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
pytorchmergebot pushed a commit to tszulist-hbn/pytorch that referenced this pull request Nov 16, 2026
…rators

Four move_to_device_pass tests sat in TestMoveToDevicePassCuda behind
skipIf(not TEST_CUDA) with "cuda:0" hard-coded, so XPU and other
accelerators skipped them. Nothing in them is CUDA-specific. They check
that the moved GraphModule and its nested torch.cond submodules are
recompiled, that the source module's parameters and buffers are not
mutated, and that wrapper-subclass parameters move with their inner
tensors.

Root cause: pytorch#185105 added the tests behind a TEST_CUDA gate. pytorch#196974
moved the four older move_to_device_pass tests into the device-generic
TestMoveToDevicePassDevice but left these behind, and pytorch#191079 then
tagged their class CUDA to match its gate.

Move them into TestMoveToDevicePassDevice with a device parameter, drop
the gates and replace each "cuda:0" with device. The instantiated
primary device always carries an index (cuda:N, xpu:N,
<privateuse1>:N), so the code and device-equality assertions behave as
before on CUDA. After the previous commit the CUDA class is empty, so
delete it and the now-unused TEST_CUDA import.

XPU, PrivateUse1 and HPU gain the four tests. CUDA keeps them as
TestMoveToDevicePassDeviceCUDA::<name>_cuda. On a machine without an
accelerator they are no longer collected instead of being reported as
skipped, the same trade-off pytorch#196974 made. Widening the gate to TEST_CUDA
or TEST_XPU was the alternative; it keeps the hard-coded device and
leaves PrivateUse1 out.

See intel/torch-xpu-ops#5994.

Test Plan:

The same AST comparison as the previous commit: the four methods match
the originals once device maps back to 'cuda:0' and the device parameter
and TEST_CUDA skip are dropped. The other 40 methods are unchanged.

On an Intel Data Center GPU Max 1550:

```
python test/export/test_passes.py -v -k move_device -k move_to_device
python test/export/test_passes.py
```

All 8 TestMoveToDevicePassDeviceXPU tests pass, 4 of them new. The whole
file goes from OK (skipped=4, expected failures=2) to
OK (expected failures=2) with the same 39 tests. The only ID changes are
TestMoveToDevicePassCuda::<name> ->
TestMoveToDevicePassDeviceXPU::<name>_xpu. CUDA was not run locally.

Authored with an AI assistant (Claude Code).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
pytorchmergebot pushed a commit to tszulist-hbn/pytorch that referenced this pull request Nov 18, 2026
…rators

Four move_to_device_pass tests sat in TestMoveToDevicePassCuda behind
skipIf(not TEST_CUDA) with "cuda:0" hard-coded, so XPU and other
accelerators skipped them. Nothing in them is CUDA-specific. They check
that the moved GraphModule and its nested torch.cond submodules are
recompiled, that the source module's parameters and buffers are not
mutated, and that wrapper-subclass parameters move with their inner
tensors.

Root cause: pytorch#185105 added the tests behind a TEST_CUDA gate. pytorch#196974
moved the four older move_to_device_pass tests into the device-generic
TestMoveToDevicePassDevice but left these behind, and pytorch#191079 then
tagged their class CUDA to match its gate.

Move them into TestMoveToDevicePassDevice with a device parameter, drop
the gates and replace each "cuda:0" with device. The instantiated
primary device always carries an index (cuda:N, xpu:N,
<privateuse1>:N), so the code and device-equality assertions behave as
before on CUDA. After the previous commit the CUDA class is empty, so
delete it and the now-unused TEST_CUDA import.

XPU, PrivateUse1 and HPU gain the four tests. CUDA keeps them as
TestMoveToDevicePassDeviceCUDA::<name>_cuda. On a machine without an
accelerator they are no longer collected instead of being reported as
skipped, the same trade-off pytorch#196974 made. Widening the gate to TEST_CUDA
or TEST_XPU was the alternative; it keeps the hard-coded device and
leaves PrivateUse1 out.

See intel/torch-xpu-ops#5994.

Test Plan:

The same AST comparison as the previous commit: the four methods match
the originals once device maps back to 'cuda:0' and the device parameter
and TEST_CUDA skip are dropped. The other 40 methods are unchanged.

On an Intel Data Center GPU Max 1550:

```
python test/export/test_passes.py -v -k move_device -k move_to_device
python test/export/test_passes.py
```

All 8 TestMoveToDevicePassDeviceXPU tests pass, 4 of them new. The whole
file goes from OK (skipped=4, expected failures=2) to
OK (expected failures=2) with the same 39 tests. The only ID changes are
TestMoveToDevicePassCuda::<name> ->
TestMoveToDevicePassDeviceXPU::<name>_xpu. CUDA was not run locally.

Authored with an AI assistant (Claude Code).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 Merged module: tests/graph This label covers all test cases within the Graph sheet. open source topic: not user facing topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

8 participants