Skip to content

[TEST] Add hw_classification to test_fake_tensor.py test classes - #193986

Draft
XAheli wants to merge 6 commits into
pytorch:mainfrom
XAheli:test/dynamo-fake-tensor-hw-classification
Draft

XAheli wants to merge 6 commits into
pytorch:mainfrom
XAheli:test/dynamo-fake-tensor-hw-classification

Conversation

@XAheli

@XAheli XAheli commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

Classifies all 16 test classes in test/test_fake_tensor.py with HardwareClassification attributes

6 non-mixed classes classified directly:

  • FakeTensorConstHandling → GENERIC
  • FakeTensorOpInfoTest → ACCELERATOR
  • FakeTensorConverterTest → GENERIC
  • FakeTensorSerialization → GENERIC
  • FakeTensorMetaDevicePropagation → GENERIC
  • FakeTensorViewCopy → GENERIC

5 mixed classes split into GENERIC + CUDA pairs:

  • FakeTensorTest (140 methods) → GENERIC (~108 CPU) + FakeTensorTestCUDA (32 CUDA)
  • FakeTensorPreferDeviceType → GENERIC (1 CPU) + FakeTensorPreferDeviceTypeCUDA (1 CUDA)
  • FakeTensorPropTest → GENERIC (6 CPU) + FakeTensorPropTestCUDA (1 CUDA)
  • FakeTensorDispatchCache → GENERIC (29 CPU) + FakeTensorDispatchCacheCUDA (3 CUDA)
  • FakeTensorOperatorInvariants → GENERIC (12 CPU) + FakeTensorOperatorInvariantsCUDA (3 CUDA)

All split CUDA classes have instantiate_parametrized_tests() and/or make_propagate_real_tensors_cls() called on them where the original class had those calls, preserving parametrized test expansion and PropagateRealTensors variants. 459/459 tests preserved.

Test plan

  • python -m pytest --collect-only -q test/test_fake_tensor.py → 459 tests
  • Full test run locally: 266 pass, 14 skip, 2 xfail
  • Full test run: 264 pass, 14 skip, 2 xfail, 2 pre-existing failures (test_cuda_gru — UnsupportedOperatorException for aten._thnn_fused_gru_cell.default, reproduces on clean upstream/main)
  • lintrunner -a clean
  • ast.parse validates after every extraction step

Depends on #186918 for the HardwareClassification enum. Follows the RFC test class classification (#185142, #185390)

Co-authored with Opus 4.6

cc @RiyaP2508 @mansiag05 @vishalgoyal316

XAheli added 6 commits August 18, 2026 14:47
Add HardwareClassification import and classify 6 non-mixed classes:
- FakeTensorConstHandling: GENERIC
- FakeTensorOpInfoTest: ACCELERATOR
- FakeTensorConverterTest: GENERIC
- FakeTensorSerialization: GENERIC
- FakeTensorMetaDevicePropagation: GENERIC
- FakeTensorViewCopy: GENERIC

459/459 test count preserved.
- FakeTensorPreferDeviceType (GENERIC): test_fake_tensor_prefer_device_type_cpu_only
- FakeTensorPreferDeviceTypeCUDA (CUDA): test_fake_tensor_prefer_device_type

459/459 test count preserved.
- FakeTensorPropTest (GENERIC): 6 CPU tests
- FakeTensorPropTestCUDA (CUDA): test_torch_load_with_fake_mode
- Added make_propagate_real_tensors_cls for CUDA class

459/459 test count preserved.
- FakeTensorDispatchCache (GENERIC): 29 CPU tests
- FakeTensorDispatchCacheCUDA (CUDA): test_cache_key_device,
  test_cache_default_device, test_wrapper_tensor_subclass_different_device

459/459 test count preserved.
- FakeTensorOperatorInvariants (GENERIC): 12 CPU tests
- FakeTensorOperatorInvariantsCUDA (CUDA): test_move_meta_tensor,
  test_conv_c1_backward, test_module_to

459/459 test count preserved.
Split FakeTensorTest (140 test methods) into:
- FakeTensorTest (GENERIC): ~108 CPU/device-agnostic tests
- FakeTensorTestCUDA (CUDA): 32 CUDA-guarded tests

Both classes have instantiate_parametrized_tests() and
make_propagate_real_tensors_cls() called on them to preserve
parametrized test expansion and PropagateRealTensors variants.

Test count verified: 459/459 tests preserved.

CUDA tests extracted include:
- 29 tests guarded with @skipIf(not RUN_CUDA)/@skipUnless(RUN_CUDA)
- 2 tests guarded with @skipIf(not torch.cuda._is_compiled())
- 1 test guarded with @skipIf(not torch.backends.cuda.is_built())

Helper methods checkType() and checkMetaProps() were duplicated
into FakeTensorTestCUDA since CUDA tests reference them via self.

Depends on pytorch#186918 for the HardwareClassification enum.
Follows the RFC Test class classification (pytorch#185142, pytorch#185590).
@pytorch-bot

pytorch-bot Bot commented Aug 18, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

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

@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label Aug 18, 2026
@mansiag05 mansiag05 moved this from Backlog to Ready for Review(Initial) in PyTorch Test Refactoring Aug 21, 2026
kerer-ai pushed a commit to kerer-ai/pytorch-nv that referenced this pull request Aug 26, 2026
kerer-ai pushed a commit to kerer-ai/pytorch-nv that referenced this pull request Aug 26, 2026
kerer-ai pushed a commit to kerer-ai/pytorch-nv that referenced this pull request Sep 7, 2026

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

Request changes — good overall split strategy, but a few blocking issues:

  1. Rebase onto current main — branch is ~537 commits behind with a merge conflict in test/test_fake_tensor.py. Main added 7 tests since this branch diverged; classify them after rebase.

  2. FakeTensorDispatchCacheCUDA missing helpers — it extends TestCase but calls _test_cache_key() and assertHitsMisses() from FakeTensorDispatchCache. Prefer class FakeTensorDispatchCacheCUDA(FakeTensorDispatchCache) with hw_classification = CUDA over duplicating helpers.

  3. test_move_module_under_fake in wrong class — on main it's in FakeTensorOperatorInvariants; the PR put it in FakeTensorTestCUDA. Move it to FakeTensorOperatorInvariantsCUDA with the other CUDA operator-invariant tests.

Split integrity otherwise looks good — 459/459 preserved at branch time, instantiate_parametrized_tests / make_propagate_real_tensors_cls applied correctly.

@github-actions

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as Stale.
Feel free to remove the Stale label if you feel this was a mistake.
If you are unable to remove the Stale label please contact a maintainer in order to do so.
If you want the bot to never mark this PR stale again, add the no-stale label.
Stale pull requests will automatically be closed after 30 days of inactivity.

@github-actions github-actions Bot added the Stale label Nov 11, 2026

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

Projects

Status: Ready for Review(Initial)

Development

Successfully merging this pull request may close these issues.

3 participants