Skip to content

[Test] Add proper hw_classification attribute to test classes - #190991

Closed
KarhouTam wants to merge 2 commits into
gh/KarhouTam/18/basefrom
gh/KarhouTam/18/head
Closed

KarhouTam wants to merge 2 commits into
gh/KarhouTam/18/basefrom
gh/KarhouTam/18/head

Conversation

@KarhouTam

@KarhouTam KarhouTam commented Jul 24, 2026 •

Copy link
Copy Markdown
Collaborator

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Jul 24, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 1 Cancelled Job, 3 Unrelated Failures

As of commit b2b2e8b with merge base 2f86d10 (image):

CANCELLED JOB - The following job was cancelled. Please retry:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

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

@KarhouTam KarhouTam added module: tests Issues related to tests (not the torch.testing module) module: tests/core This label covers all test cases within the Core and Tensor sheets. labels Jul 24, 2026
@KarhouTam
KarhouTam requested a review from fffrog July 24, 2026 07:43
@fffrog fffrog moved this from Backlog to Ready for Review(Definitive) in PyTorch Test Refactoring Jul 24, 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.

SGTM, thank you for updates.

The previous discussion can be found here

[ghstack-poisoned]
KarhouTam added a commit that referenced this pull request Jul 24, 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.

Thanks

@KarhouTam

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Jul 24, 2026
@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: 1 jobs have failed, first few of them are: docs-build / get-label-type / runner-determinator

Details for Dev Infra team Raised by workflow job

@KarhouTam

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 2 checks: docs-build / get-label-type / runner-determinator, trunk / macos-py3-arm64 / test (mps, 1, 1, macos-m2-15)

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

@KarhouTam KarhouTam added the ciflow/crcr/crcr-test Label for testing the L3 CRCR functionality label Jul 25, 2026
pytorchmergebot pushed a commit that referenced this pull request Aug 12, 2026
…module (#191473)

## Summary

#186918 introduced `hw_classification` (`GENERIC`/`ACCELERATOR`/`CPU`/`CUDA`/`MPS`/`XPU`) so tests can opt into `--hw-classification` filtering. `test_modules.py` predates that rollout and its two test classes were left unclassified. This annotates them, following the same convention already applied to other files (e.g. #190991).

`TestModule` is instantiated via `instantiate_device_type_tests`, so it gets `ACCELERATOR`. `TestJitReplaceSubmodule` has no device/dtype parametrization and never touches an accelerator, so it gets `GENERIC`.
Pull Request resolved: #191473
Approved by: https://github.com/fffrog, https://github.com/albanD
gavinwang269 pushed a commit to gavinwang269/pytorch that referenced this pull request Aug 13, 2026
…module (pytorch#191473)

## Summary

pytorch#186918 introduced `hw_classification` (`GENERIC`/`ACCELERATOR`/`CPU`/`CUDA`/`MPS`/`XPU`) so tests can opt into `--hw-classification` filtering. `test_modules.py` predates that rollout and its two test classes were left unclassified. This annotates them, following the same convention already applied to other files (e.g. pytorch#190991).

`TestModule` is instantiated via `instantiate_device_type_tests`, so it gets `ACCELERATOR`. `TestJitReplaceSubmodule` has no device/dtype parametrization and never touches an accelerator, so it gets `GENERIC`.
Pull Request resolved: pytorch#191473
Approved by: https://github.com/fffrog, https://github.com/albanD
@github-actions
github-actions Bot deleted the gh/KarhouTam/18/head branch August 25, 2026 02:06
orrangetabby17 pushed a commit to orrangetabby17/pytorch that referenced this pull request Sep 2, 2026
…module (pytorch#191473)

## Summary

pytorch#186918 introduced `hw_classification` (`GENERIC`/`ACCELERATOR`/`CPU`/`CUDA`/`MPS`/`XPU`) so tests can opt into `--hw-classification` filtering. `test_modules.py` predates that rollout and its two test classes were left unclassified. This annotates them, following the same convention already applied to other files (e.g. pytorch#190991).

`TestModule` is instantiated via `instantiate_device_type_tests`, so it gets `ACCELERATOR`. `TestJitReplaceSubmodule` has no device/dtype parametrization and never touches an accelerator, so it gets `GENERIC`.
Pull Request resolved: pytorch#191473
Approved by: https://github.com/fffrog, https://github.com/albanD
ysnylmzz added a commit to ysnylmzz/pytorch that referenced this pull request Sep 3, 2026
Review feedback: the guard asserting that a device type needs no entry in
`_get_device_from_module` to be recognised did so against a literal
`('hpu', 'xpu', 'mps', 'mtia', privateuse1)`. That is the same hand-maintained
device list this change deletes from `torch/storage.py`, moved into the test, so
the next backend would still have needed an edit -- one file over.

It now iterates `set(NATIVE_DEVICES) | {"hpu"}` minus `cpu`, so it widens on its
own when a native device is added, and `NATIVE_DEVICES` already ends with
`torch._C._get_privateuse1_backend_name()`, which keeps the out-of-tree case that
matters here.

`hpu` is the one name still written out. It is absent from `NATIVE_DEVICES` and it
was one of the three entries in the whitelist being deleted, so deriving alone
would silently drop the only entry of the old behaviour that nothing else covers.

Not tagging this file's classes with `hw_classification` here. `test_torch.py` has
four device-parameterized classes and one plain one, none classified, and there is
an active upstream series doing exactly that per file (pytorch#186918, pytorch#190991, pytorch#190181).
Five mechanical lines in a storage-lookup PR would enlarge the diff for an
unrelated reason and collide with that work; happy to send it separately.
youlituao added a commit to youlituao/pytorch that referenced this pull request Sep 22, 2026
The log_sigmoid_forward decomposition decided the shape of its second
output (buffer) by enumerating CUDA and XPU. Backends whose kernels
materialize the buffer are exactly {cpu} plus {meta} (meta has no device
and the op has no Meta kernel, so the decomposition defines its meta
behavior) — enumerate that closed side instead, so CUDA/XPU/MPS and every
PrivateUse1 backend get the empty `(0,)` buffer consistently in both the
real kernels and FakeTensor inference.

Fixes the MetadataMismatchError class seen on XPU (pytorch#141333), MPS (pytorch#195417)
and out-of-tree PrivateUse1 devices.

Also adds the missing `hw_classification` class attributes to
test/test_decomp.py (per the pytorch#190991 convention) so the new regression
test is picked up by device-parameterized CI runs.

Part of the device-decoupling sweep (pytorch#194355).
youlituao added a commit to youlituao/pytorch that referenced this pull request Oct 10, 2026
The log_sigmoid_forward decomposition decided the shape of its second
output (buffer) by enumerating CUDA and XPU. Backends whose kernels
materialize the buffer are exactly {cpu} plus {meta} (meta has no device
and the op has no Meta kernel, so the decomposition defines its meta
behavior) — enumerate that closed side instead, so CUDA/XPU/MPS and every
PrivateUse1 backend get the empty `(0,)` buffer consistently in both the
real kernels and FakeTensor inference.

Fixes the MetadataMismatchError class seen on XPU (pytorch#141333), MPS (pytorch#195417)
and out-of-tree PrivateUse1 devices.

Also adds the missing `hw_classification` class attributes to
test/test_decomp.py (per the pytorch#190991 convention) so the new regression
test is picked up by device-parameterized CI runs.

Part of the device-decoupling sweep (pytorch#194355).
youlituao added a commit to youlituao/pytorch that referenced this pull request Oct 10, 2026
The log_sigmoid_forward decomposition decided the shape of its second
output (buffer) by enumerating CUDA and XPU. The buffer is materialized
only by log_sigmoid_backward_cpu; the CUDA/XPU/MPS kernels allocate an
empty (0,) buffer and ignore it (see the NOTE comments in
log_sigmoid_backward_{cuda,mps}), and we verified the same on a
PrivateUse1 device. Enumerate the evidence-backed empty-buffer devices
(cuda/xpu/mps + the PrivateUse1 backend via its registered name) while
keeping cpu and meta on the full-shape branch — meta has no device and
the op has no Meta kernel, so the decomposition defines its meta
behavior. Backends not listed keep their historical full-shape buffer:
no behavioral delta beyond the two fixes (MPS per pytorch#195417, PrivateUse1
per our device verification).

Fixes the MetadataMismatchError class seen on XPU (pytorch#141333), MPS
(pytorch#195417) and out-of-tree PrivateUse1 devices.

Also adds the missing `hw_classification` class attributes to
test/test_decomp.py (per the pytorch#190991 convention) so the new regression
test is picked up by device-parameterized CI runs.

Part of the device-decoupling sweep (pytorch#194355).
pytorchmergebot pushed a commit to youlituao/pytorch that referenced this pull request Oct 13, 2026
The log_sigmoid_forward decomposition decided the shape of its second
output (buffer) by enumerating CUDA and XPU. The buffer is materialized
only by log_sigmoid_backward_cpu; the CUDA/XPU/MPS kernels allocate an
empty (0,) buffer and ignore it (see the NOTE comments in
log_sigmoid_backward_{cuda,mps}), and we verified the same on a
PrivateUse1 device. Enumerate the evidence-backed empty-buffer devices
(cuda/xpu/mps + the PrivateUse1 backend via its registered name) while
keeping cpu and meta on the full-shape branch — meta has no device and
the op has no Meta kernel, so the decomposition defines its meta
behavior. Backends not listed keep their historical full-shape buffer:
no behavioral delta beyond the two fixes (MPS per pytorch#195417, PrivateUse1
per our device verification).

Fixes the MetadataMismatchError class seen on XPU (pytorch#141333), MPS
(pytorch#195417) and out-of-tree PrivateUse1 devices.

Also adds the missing `hw_classification` class attributes to
test/test_decomp.py (per the pytorch#190991 convention) so the new regression
test is picked up by device-parameterized CI runs.

Part of the device-decoupling sweep (pytorch#194355).
pytorchmergebot pushed a commit that referenced this pull request Oct 15, 2026
… device-agnostic instead of backend-enumerated (#197530)

## Summary

`log_sigmoid_forward` returns `(output, buffer)`. The buffer is only consumed
by the CPU backward kernel (`log_sigmoid_backward_cpu`); the CUDA/XPU/MPS
forward kernels (`log_sigmoid_forward_{cuda,mps}`) allocate an empty `(0,)`
buffer and ignore its contents (the "buffer is only used by CPU dispatch, we
just ignore it here" NOTE also appears in some backward and out variants, e.g.
`log_sigmoid_backward_cuda` and `log_sigmoid_forward_out_mps`). PrivateUse1
(out-of-tree) backends follow the accelerator semantics: we verified on
torch_npu (Ascend) that the real kernel returns an empty `(0,)` buffer.

The decomposition in `torch/_decomp/decompositions.py` (used for FakeTensor
shape inference under `torch.compile`/export and `CrossRefFakeMode`) decided
the buffer shape by enumerating backends:

    if self.is_cuda or self.is_xpu:
        buffer = self.new_zeros((0,))
    else:
        buffer = z

Every time a new backend was added, someone had to extend this enumeration and
until then FakeTensor inference disagreed with the real kernel, making
`torch.compile`/export/`CrossRefFakeMode` fail with a `MetadataMismatchError`
on that backend: XPU in #141332/#141333, MPS in #195417, and we reproduced the
identical failure on an out-of-tree PrivateUse1 device:

    MetadataMismatchError: When comparing the output of
    aten.log_sigmoid_forward.default on FakeTensor and concrete Tensors, found
    mismatched tensor metadata for output[1]: Shapes torch.Size([0]) and
    torch.Size([4]) are not equal!

This PR makes the empty-buffer set explicit and evidence-backed — cuda/xpu/mps
(source-verified) plus PrivateUse1 (verified on device, where the real kernel
returns `(0,)` and the old enumeration produced a full-shape buffer that broke
`CrossRefFakeMode`) — while **every backend not in that list (XLA, HPU, MTIA,
and any backend whose contract is unverified) keeps the historical full-shape
buffer**: no behavioral delta beyond the two fixes.

## Changes

- `torch/_decomp/decompositions.py` and `torch/_decomp/decompositions_for_jvp.py`
  (the twin copies must stay in lockstep — upstream precedent #141333/#195417):
  the branch now enumerates the evidence-backed empty-buffer devices and keeps
  the historical full-shape default for everything else:

      if self.is_cpu or self.is_meta:
          buffer = z
      elif (
          self.is_cuda
          or self.is_xpu
          or self.is_mps
          or self.device.type == torch._C._get_privateuse1_backend_name()
      ):
          buffer = self.new_zeros((0,))
      else:
          buffer = z

  Design notes: (a) meta tensors stay on the full branch — this op has no Meta
  kernel, so the decomposition defines its meta behavior, and `not
  self.is_cpu` alone would silently flip meta to the empty branch; (b)
  `Tensor.is_privateuseone` is not exposed as a Python property, so the
  PrivateUse1 backend is identified via its registered name
  (`torch._C._get_privateuse1_backend_name()`, called at runtime — no
  import-time freeze); (c) backends whose contract is unverified keep the
  historical default — no behavioral delta beyond the two fixes.
- Added a regression test `TestDecomp::test_log_sigmoid_forward_buffer_shape`
  (in `test/test_decomp.py`, owner: `module: decompositions`) calling the
  production symbols through `FakeTensorMode`: buffer full-shape for cpu,
  empty for cuda, **empty for mps (the discriminating leg — the pre-PR
  enumeration gives a full-shape buffer for mps, so the test fails without
  this fix)**, empty for PrivateUse1 (the backend name is resolved at runtime
  via `torch._C._get_privateuse1_backend_name()` and pinned with an explicit
  `:0` index, so renamed trees are covered and fake creation skips the
  `is_initialized` lookup in `FakeTensor._normalize_fake_device`), full for
  meta. `@onlyCPU` per the file's convention for device-agnostic tests (the
  assertions pivot on fake/meta devices).
- Added the `hw_classification` class attributes `test/test_decomp.py` was
  missing (TestDecomp / DecompOneOffTests → ACCELERATOR, HasDecompTest →
  GENERIC, per the #190991 convention) so the new test is picked up by
  device-parameterized CI runs.
- Removed the two `fake_backward_mps_xfails` entries in `test/test_ops.py`
  for `nn.functional.logsigmoid` and
  `nn.functional.binary_cross_entropy_with_logits` (the latter decomposes
  through `logsigmoid`). They were added on main to mask exactly the
  fake-vs-real MPS buffer mismatch this PR fixes; with the fix in place
  they report unexpected successes. The remaining entries mask unrelated
  mismatches and stay.

| device | before | after | delta |
|---|---|---|---|
| CPU | full buffer | full buffer | none |
| CUDA / XPU | empty `(0,)` | empty `(0,)` | none |
| MPS | full buffer (wrong, mismatched the real kernel) | empty `(0,)` | **fixes the #195417 mismatch** |
| meta (incl. device-less) | full buffer | full buffer | none |
| PrivateUse1 (FakeTensor) | full buffer (wrong, mismatched the real kernel) | empty `(0,)` | **fixes the mismatch** |
| XLA / HPU / MTIA / unknown | full buffer (historical) | full buffer (unchanged) | none — preserved |

## Depends on

- **#190991** (`HardwareClassification` enum) — used by the added labels.
  Already merged; present in trunk.
- No other merge dependencies. Relations, not dependencies: #195417 (same
  condition, enumeration fix — the evidence-backed form here subsumes it) and
  #193116 (XPU enablement of the same suite, orthogonal).

## Not changed

- The `test_meta.py` crossref expected failures for `log_sigmoid_forward` on
  cuda/xpu (#196554-style) are intentionally untouched: those are about
  device-less meta tensors vs real kernels, and meta behavior is unchanged.
- Pre-existing method-level `@onlyCPU` / `@onlyCUDA` gates in
  `test/test_decomp.py` are left untouched — most encode per-method device
  semantics (RNG determinism, precision, CUDA-specific NaN behavior,
  CPU-only reference behavior), a few are legacy CPU scoping that
  device-enablement efforts like #193116 are better positioned to remove.
- `torch_npu` requires no changes: its native `log_sigmoid_forward` already
  returns an empty `(0,)` buffer (verified on device), so the fix aligns
  FakeTensor inference with the real kernel.

## Test plan

- [x] NPU (PrivateUse1, torch_npu 2.13.0+git45fbeae, Ascend 910B3):
      `CrossRefFakeMode` + `F.logsigmoid` raised `MetadataMismatchError`
      before this PR (output[1] `(0,)` vs `(4,)`) and passes after;
      probe `aten.log_sigmoid_forward` buffer stays `(0,)`;
      new UT green on the box (cpu variant; `@onlyCPU` skips the real npu
      variant by design — the in-test fake PrivateUse1 leg resolves to
      `npu:0` on this tree and passes; real-kernel behavior is additionally
      covered by the probes).
- [x] CPU: new UT 1 passed; `test/functorch/test_ops.py -k logsigmoid`
      14 OK; `test_meta.py -k logsigmoid` 12 passed / 14 skipped (xfails
      unchanged).
- [x] CUDA (A100, torch 2.13.0a0): probe `(0,)` unchanged; functorch 28 OK;
      test_meta 52 tests OK (skipped=27); new UT 2 passed (cpu + cuda
      variants, pre-`@onlyCPU` form).
- [ ] CI (lint / unittest shards).

Pull Request resolved: #197530
Approved by: https://github.com/jansel, https://github.com/guangyey
pytorchmergebot pushed a commit that referenced this pull request Nov 11, 2026
## Summary

`test/distributed/test_ce_colls.py` contains a single `TestCase` subclass, `NCCLCopyEngineCollectives`, that was previously unclassified. This PR adds `hw_classification = HardwareClassification.CUDA` and instantiates it with `instantiate_device_type_tests(only_for="cuda")`.

## Changes

- **`test/distributed/test_ce_colls.py`**:
  - Added `HardwareClassification` to the `common_utils` import block.
  - Added `instantiate_device_type_tests` import from `common_device_type`.
  - Labeled `NCCLCopyEngineCollectives` with `hw_classification = HardwareClassification.CUDA`.
  - Added `instantiate_device_type_tests(NCCLCopyEngineCollectives, globals(), only_for="cuda")` at file end.
  - All `test_*` methods now accept a `device` parameter (injected by `instantiate_device_type_tests`).
  - Replaced `self.device` property references with `torch.device(f"{device}:{self.rank}")` in test method bodies.

No test logic or decorators are changed. `torch.cuda.current_stream()` / `torch.cuda.Stream()` are kept (only_for="cuda" guarantees CUDA).

## Motivation

PR #190991 established the convention that every `TestCase` subclass must carry a `hw_classification` attribute. PR #190173 (TEST_LINTER) requires that CUDA classes must use `instantiate_device_type_tests` with `only_for="cuda"` and every test method must accept a `device` parameter.

`NCCLCopyEngineCollectives` exercises NCCL Copy Engine collectives (NCCL 2.28+, `requires_cuda_p2p_access`, `symm_mem` rendezvous), which is CUDA-specific.

## Dependencies

None.

## Test Plan

- `python -m py_compile test/distributed/test_ce_colls.py` passes.
- `lintrunner test/distributed/test_ce_colls.py` passes (exit 0).
- Test count unchanged: 2 `def test_*` methods.
- Both test methods accept `device` parameter.
- `instantiate_device_type_tests(only_for="cuda")` added.

Pull Request resolved: #192764
Approved by: https://github.com/jialinw77, https://github.com/KarhouTam, https://github.com/fffrog, https://github.com/can-gaa-hou
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: amp (automated mixed precision) autocast module: tests/core This label covers all test cases within the Core and Tensor sheets. module: tests Issues related to tests (not the torch.testing module) open source topic: not user facing topic category

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants