pytorch - ✅(Solved) Fix Standardize device-agnostic test cases via instantiate_device_type_tests [1 pull requests, 3 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
pytorch/pytorch#177260Fetched 2026-04-08 00:42:30
View on GitHub
Comments
3
Participants
3
Timeline
25
Reactions
1
Author
Timeline (top)
subscribed ×6mentioned ×5labeled ×4commented ×3

Fix Action

Fixed

PR fix notes

PR #177680: Migrate copy_tests to instantiate_device_type_tests for 3 test files …

Description (problem / solution / changelog)

Issue

Part of #177260

Summary

Migrates the 3 lowest-difficulty copy_tests call sites to instantiate_device_type_tests.

Files: test_efficient_conv_bn_eval.py, test_binary_folding.py, test_provenance_tracing.py

Co-authored-by: Claude (Anthropic)

Checklist

  • Passes lint (spin fixlint)
  • Added/updated tests
  • Updated documentation (if applicable)
  • Included benchmark results (for PRs impacting perf)

BC-breaking?

No

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo

Changed files

  • test/inductor/test_binary_folding.py (modified, +20/-43)
  • test/inductor/test_efficient_conv_bn_eval.py (modified, +6/-23)
  • test/inductor/test_provenance_tracing.py (modified, +17/-41)

Code Example

# Before
class AOTInductorTestsTemplate:
    def test_custom_op_add(self) -> None:
      ...

copy_tests(
    AOTInductorTestsTemplate,
    AOTInductorTestABICompatibleCpu,
    "cpu",
    CPU_TEST_FAILURES,
)

# After
class AOTInductorTestsTemplate:
    def test_custom_op_add(self, device) -> None:
      ...

instantiate_device_type_tests(AOTInductorTestsTemplate, globals())
RAW_BUFFERClick to expand / collapse

Promote that all device-agnostic testcases are instantiated through mechanisms like instantiate_device_type_tests, and provide a configurable entry point for backends based on PrivateUse1.

# Before
class AOTInductorTestsTemplate:
    def test_custom_op_add(self) -> None:
      ...

copy_tests(
    AOTInductorTestsTemplate,
    AOTInductorTestABICompatibleCpu,
    "cpu",
    CPU_TEST_FAILURES,
)

# After
class AOTInductorTestsTemplate:
    def test_custom_op_add(self, device) -> None:
      ...

instantiate_device_type_tests(AOTInductorTestsTemplate, globals())

There are currently 17 files and more than 30 copy_tests call sites in the codebase. The following is a layered overview based on refactoring difficulty, from low to high:

Lowest difficulty

Template classFiles
EfficientConvBNEvalTemplatetest/inductor/test_efficient_conv_bn_eval.py
BinaryFoldingTemplatetest/inductor/test_binary_folding.py
ProvenanceTracingKernelContextTemplatetest/inductor/test_provenance_tracing.py

Medium difficulty

TODO

cc @mruberry

extent analysis

Fix Plan

To address the issue, we will refactor the test cases to use the instantiate_device_type_tests mechanism. Here are the steps:

  • Identify the template classes that need to be refactored, starting with the lowest difficulty ones:
    • EfficientConvBNEvalTemplate
    • BinaryFoldingTemplate
    • ProvenanceTracingKernelContextTemplate
  • Modify the template classes to accept a device parameter in their test methods:
class EfficientConvBNEvalTemplate:
    def test_custom_op_add(self, device) -> None:
        # test implementation
        pass
  • Replace the copy_tests calls with instantiate_device_type_tests:
instantiate_device_type_tests(EfficientConvBNEvalTemplate, globals())
  • Repeat the process for the remaining template classes.

Example Code

Here's an example of how the EfficientConvBNEvalTemplate class could be refactored:

# Before
class EfficientConvBNEvalTemplate:
    def test_custom_op_add(self) -> None:
        # test implementation
        pass

copy_tests(
    EfficientConvBNEvalTemplate,
    EfficientConvBNEvalTestABICompatibleCpu,
    "cpu",
    CPU_TEST_FAILURES,
)

# After
class EfficientConvBNEvalTemplate:
    def test_custom_op_add(self, device) -> None:
        # test implementation
        pass

instantiate_device_type_tests(EfficientConvBNEvalTemplate, globals())

Verification

To verify that the fix worked, run the test cases and ensure that they pass without errors. Additionally, check that the instantiate_device_type_tests mechanism is correctly instantiating the test cases for each device type.

Extra Tips

  • Make sure to update the test cases to handle any device-specific logic or errors.
  • Consider adding additional logging or debugging statements to help diagnose any issues that may arise during testing.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

pytorch - ✅(Solved) Fix Standardize device-agnostic test cases via instantiate_device_type_tests [1 pull requests, 3 comments, 3 participants]