Repository navigation
[Testcase Refactoring] Instantiate TestConverterDevice for all supported devices - #190296
SHIHAIFENG15 wants to merge 16 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/190296
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (1 Unrelated Failure)As of commit 1da7a61 with merge base ff30875 ( NEW FAILURES SUPPRESSED BY AI (non-blocking) - The following job failed, but the AI CI Advisor judged the failure not to be evidence against this change:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
|
|
|
e8cec13 to
46b160e
Compare
46b160e to
a7da3c2
Compare
Stack on npu-device-agnostic-from-main (PR pytorch#190296). Continue device-agnosticizing Export/AOTI tests with instantiate_device_type_tests and injected device, without using GPU_TYPE/HAS_GPU as the NPU entry path. Includes accelerator/Triton splits for export+serialize, MoveToDevicePass, nativert/experimental non-Flex coverage, dynamic AOTI runner selection, torchbind instantiate+Triton helper, plus MoveToDeviceIndex and AutocastException device classes (except_for=cpu). Test Plan: ``` ./run_test.sh cpu test/export/test_converter.py -v -k prim_device ./run_test.sh npu test/export/test_export.py -v -k assert_tensor_metadata_device_index ./run_test.sh npu test/export/test_export.py -v -k TestExportAutocastException ``` Co-authored-by: Cursor <[email protected]>
Stack on npu-device-agnostic-from-main (PR pytorch#190296). Continue device-agnosticizing Export/AOTI tests with instantiate_device_type_tests and injected device, without using GPU_TYPE/HAS_GPU as the NPU entry path. Includes accelerator/Triton splits for export+serialize, MoveToDevicePass, nativert coverage, FlexAttention/BlockMask export instantiate classes, dynamic AOTI runner selection, shared ensure_triton helper, torchbind instantiate+Triton gate, plus MoveToDeviceIndex and AutocastException device classes (except_for=cpu). Test Plan: ``` ./run_test.sh cpu test/export/test_export.py -v -k test_flex_attention_export ./run_test.sh npu test/export/test_export.py -v -k test_flex_attention_export ./run_test.sh cpu test/export/test_experimental.py -v -k TestExperimentFlex ./run_test.sh npu test/export/test_experimental.py -v -k TestExperimentFlex ./run_test.sh npu test/export/test_export.py -v -k TestExportAutocastException ``` Co-authored-by: Cursor <[email protected]>
Stack on npu-device-agnostic-from-main (PR pytorch#190296). Continue device-agnosticizing Export/AOTI tests with instantiate_device_type_tests and injected device, without using GPU_TYPE/HAS_GPU as the NPU entry path. Includes accelerator/Triton splits for export+serialize, MoveToDevicePass, nativert coverage, FlexAttention/BlockMask export instantiate classes, dynamic AOTI runner selection, shared ensure_triton helper, torchbind instantiate+Triton gate, plus MoveToDeviceIndex and AutocastException device classes (except_for=cpu). Test Plan: ``` ./run_test.sh cpu test/export/test_export.py -v -k test_flex_attention_export ./run_test.sh npu test/export/test_export.py -v -k test_flex_attention_export ./run_test.sh cpu test/export/test_experimental.py -v -k TestExperimentFlex ./run_test.sh npu test/export/test_experimental.py -v -k TestExperimentFlex ./run_test.sh npu test/export/test_export.py -v -k TestExportAutocastException ``` Co-authored-by: Cursor <[email protected]>
Stack on npu-device-agnostic-from-main (PR pytorch#190296). Continue device-agnosticizing Export/AOTI tests with instantiate_device_type_tests and injected device, without using GPU_TYPE/HAS_GPU as the NPU entry path. Includes accelerator/Triton splits for export+serialize, MoveToDevicePass, nativert coverage, FlexAttention/BlockMask export instantiate classes, dynamic AOTI runner selection, shared ensure_triton helper, torchbind instantiate+Triton gate, plus MoveToDeviceIndex and AutocastException device classes (except_for=cpu). Test Plan: ``` ./run_test.sh cpu test/export/test_export.py -v -k test_flex_attention_export ./run_test.sh npu test/export/test_export.py -v -k test_flex_attention_export ./run_test.sh cpu test/export/test_experimental.py -v -k TestExperimentFlex ./run_test.sh npu test/export/test_experimental.py -v -k TestExperimentFlex ./run_test.sh npu test/export/test_export.py -v -k TestExportAutocastException ``` Co-authored-by: Cursor <[email protected]>
|
@pytorchbot label "module: tests/graph" |
| from torch.testing._internal.common_quantized import override_quantized_engine | ||
| from torch.testing._internal.common_utils import IS_WINDOWS, run_tests, xfailIfS390X | ||
| from torch.testing._internal.common_utils import HardwareClassification, IS_WINDOWS, run_tests, xfailIfS390X |
There was a problem hiding this comment.
The line is too long. You are advised to split it into multiple lines.
There was a problem hiding this comment.
Thanks — fixed.
| return torch.ones(2, 3, device=device) | ||
|
|
||
| inp = (torch.rand((3, 4), device=device),) | ||
| TestConverter()._check_equal_ts_ep_converter(Module(), inp) |
There was a problem hiding this comment.
The TestConverter object is directly instantiated and the method is called. As a result, the original setUp is not triggered, and init_torchbind_implementations is skipped. It is recommended that a public base class be extracted, and setUp and other methods be placed in the base class. TestConverter and TestConverterPrimDevice inherit the new base class.
There was a problem hiding this comment.
Fixed — added _ConverterCheckMixin with the shared helpers; TestConverterPrimDevice now calls self._check_equal_ts_ep_converter(...). Verified on CPU/NPU.
| @@ -12,7 +12,8 @@ | |||
| from torch.export._draft_export import DraftExportReport, FailureReport, FailureType | |||
| from torch.fx.experimental.symbolic_shapes import ShapeEnv | |||
| from torch.testing import FileCheck | |||
| from torch.testing._internal.common_utils import IS_WINDOWS, run_tests, TestCase | |||
| from torch.testing._internal.common_device_type import instantiate_device_type_tests | |||
| from torch.testing._internal.common_utils import HardwareClassification, IS_WINDOWS, run_tests, TestCase | |||
| @@ -767,6 +762,11 @@ def forward(self, x, y): | |||
| package_path=f.name, | |||
| ) | |||
|
|
|||
|
|
|||
|
|
|||
| class TestDraftExportCuda(TestCase): | |||
There was a problem hiding this comment.
There are three blank lines before the class definition.
| return x | ||
| def forward(self, x, y=None): | ||
| # Tensor default args are always created on CPU; build on x.device instead. | ||
| if y is None: |
There was a problem hiding this comment.
The semantics has changed. When y is None, x is returned. Now, when y is None, y is automatically created as y = torch.ones_like(x), and x + y is returned.
There was a problem hiding this comment.
Fixed — restored return x when y is None and kept y in example_args for device-safe tracing.
| @@ -767,6 +762,11 @@ def forward(self, x, y): | |||
| package_path=f.name, | |||
| ) | |||
|
|
|||
|
|
|||
|
|
|||
| class TestDraftExportCuda(TestCase): | |||
There was a problem hiding this comment.
The TestDraftExportCuda class is not registered using instantiate_device_type_tests.
There was a problem hiding this comment.
Fixed — registered with instantiate_device_type_tests(..., only_for="cuda").
| dynamic_shapes=rewrite_case.dynamic_shapes, | ||
| strict=True, | ||
| ) | ||
|
|
||
|
|
||
| instantiate_parametrized_tests(ExampleTests) | ||
| instantiate_device_type_tests(ExampleTests, globals()) |
There was a problem hiding this comment.
Should allow_mps=True and allow_xpu=True be added? Originally, there was no constraint, and it only supported CPU and CUDA.
There was a problem hiding this comment.
Addressed — kept default instantiate (CPU/CUDA/PrivateUse1). No other test/export/* file opts into MPS/XPU via allow_mps/allow_xpu; this PR follows the same pattern. Enabling them would expand test scope beyond this refactor task.
a9e8d7f to
071e1f0
Compare
|
@claude review this pr with pr review skill |
|
Claude finished @can-gaa-hou's task in 28m 52s —— View job Test-only refactor that moves CUDA-hardcoded export tests to Full review — PR #190296PR Review: #190296SummaryConverts CUDA-gated / CPU-only device checks in Testing
Infrastructure
Code Quality
RecommendationRequest Changes The |
9a2e875 to
1ae6fc3
Compare
Keep TestConverterPrimDevice as ACCELERATOR with except_for="cpu", and restore CPU test_prim_device on TestConverter. _ConverterCheckMixin no longer subclasses TestCase; both classes take (mixin, TestCase). Skip draft-export memory measurement when getMemoryInfo is missing. Test Plan: ``` python test/export/test_converter.py -k prim_device python test/export/test_draft_export.py -k memory_usage ``` Authored with an AI assistant.
1ae6fc3 to
4fbf82e
Compare
Thanks for the review. On hw_classification: going with option (b). TestConverterPrimDevice stays ACCELERATOR and is instantiated with except_for="cpu". The CPU coverage is restored as TestConverter.test_prim_device (GENERIC), next to test_prim_dtype. GENERIC vs ACCELERATOR here is the CI --hw-classification label; instantiate_device_type_tests is what generates the per-device classes and injects device. On test_memory_usage: get_memory_info now skips on NotImplementedError (PrivateUse1 without allocator hooks). The skipIf(not torch.accelerator.is_available()) decorator is gone; instantiate + except_for="cpu" already keeps this off CPU. We touch the allocator with torch.empty(1, device=device) before the baseline, and read peak via memory_stats(device).get("allocated_bytes.all.peak"), skipping if that key is missing. Cleanup: _ConverterCheckMixin no longer subclasses TestCase. TestConverter and TestConverterPrimDevice are both (_ConverterCheckMixin, TestCase). Locally on NPU: TestConverter.test_prim_device, TestConverterPrimDevicePRIVATEUSE1.test_prim_device_npu, and TestDraftExportDevicePRIVATEUSE1.test_memory_usage_npu all passed. |
Dismissing my approval to avoid accidental merging. Another maintainer’s approval is still required before merging.
pytorch#197113 already moved prim_device into TestConverterDevice for CPU, CUDA, and XPU. Keep that class and drop only_for, so the default bases also instantiate privateuse1 while allow_xpu=True stays. The draft-export device tests and the ExportDB GENERIC tag are unchanged. Test Plan: ``` python -m pytest test/export/test_converter.py test/export/test_db.py test/export/test_draft_export.py --collect-only -q # 106 tests collected on CPU. TestConverterDeviceCPU::test_prim_device_cpu is generated. TestDraftExportDevice is not, which matches except_for="cpu". ```
test_db.py and test_draft_export.py move to their own branches. This branch now only drops only_for on TestConverterDevice so the default bases also instantiate privateuse1, while allow_xpu=True stays. Test Plan: ``` python -m pytest test/export/test_converter.py --collect-only -q # 47 tests collected on CPU, including TestConverterDeviceCPU::test_prim_device_cpu. ```
Test Plan: ``` .venv/bin/lintrunner -a test/export/test_converter.py ``` lintrunner reported no lint issues. Comment-only change. Authored with an AI assistant.
|
Hi @fffrog @KarhouTam Most changes in this PR have already been split out and merged. What's left is now just a small change. So Could you have a look when you have time? Thanks! |
|
@pytorchbot merge |
Merge startedYour 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 |
…ted devices (pytorch#190296) ## Summary Drop `only_for=("cpu", "cuda", "xpu")` from `instantiate_device_type_tests(TestConverterDevice, ...)`, so the class instantiates for every supported device type, including PrivateUse1 backends such as NPU. `allow_xpu=True` is preserved, keeping the XPU class from pytorch#197113. `test_prim_device` needs no changes for this: it creates its input on the injected `device`, and the module under test builds `torch.ones(..., device=x.device)`. ## Test plan ```bash python -m pytest test/export/test_converter.py --collect-only -q ``` CPU collect: 47 tests, including `TestConverterDeviceCPU::test_prim_device_cpu`. With a registered PrivateUse1 backend (for example NPU), `TestConverterDevicePRIVATEUSE1::test_prim_device_npu` is collected as well. Pull Request resolved: pytorch#190296 Approved by: https://github.com/lizhihai137, https://github.com/fffrog, https://github.com/KarhouTam Co-authored-by: Cursor <[email protected]>
Summary
Drop
only_for=("cpu", "cuda", "xpu")frominstantiate_device_type_tests(TestConverterDevice, ...), so the class instantiates for every supported device type, including PrivateUse1 backends such as NPU.allow_xpu=Trueis preserved, keeping the XPU class from #197113.test_prim_deviceneeds no changes for this: it creates its input on the injecteddevice, and the module under test buildstorch.ones(..., device=x.device).Test plan
CPU collect: 47 tests, including
TestConverterDeviceCPU::test_prim_device_cpu.With a registered PrivateUse1 backend (for example NPU),
TestConverterDevicePRIVATEUSE1::test_prim_device_npuis collected as well.