KEMBAR78
Test parametrization for instantiated device-specific tests by jbschlosser · Pull Request #60233 · pytorch/pytorch · GitHub
Skip to content

Conversation

@jbschlosser
Copy link
Contributor

The @ops decorator provides a way to parameterize a test across a given list of ops. This would be useful for modules as well (e.g. a @modules decorator), but the mechanism by which this is accomplished is specific to ops. In the details, the @ops decorator tags a test function with the metadata needed (list of ops, dtypes) and the actual tests are generated according to this metadata during the call to instantiate_device_type_tests().

This PR makes this mechanism more generic, allowing for test parameterization across arbitrary dimensions. This makes a @modules decorator (or any similar type of decorator) straightforward to implement without changes to the device-specific test instantiation logic.

One caveat is that, since this is implemented where the old @ops decorator was (within instantiate_device_type_tests()), this only works for tests instantiated using the device-specific instantiation logic. Longer term, even device-specific test instantiation could be treated as an optional parameterization across device types, but this PR takes a low-risk approach for now. In practice, this just means that a device kwarg is required for all test signatures used with the mechanism.

The @ops decorator has been refactored to use the generic mechanism and works the same as before, with one difference: when OpDTypes.none is specified, the test signature no longer needs an unused dtype kwarg. This is a nice bonus that demonstrates the added flexibility of a generic parameterization mechanism. The refactored form also has the bonus that all op-specific test generation logic is contained within the @ops decorator class, improving readability.

Behind the scenes, the generic mechanism is a base decorator class (_TestParameterizer) from which @ops derives. The core functionality is in the _parameterize_test() method, which takes in a test function and returns a generator that produces parameterized tests, including names and parameter kwargs to pass to them. Using the @ops decorator results in a set of op-specific tests from a given generic test.

@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented Jun 18, 2021

💊 CI failures summary and remediations

As of commit 6ea2ce8 (more details on the Dr. CI page and at hud.pytorch.org/pr/60233):


  • 1/1 failures possibly* introduced in this PR
    • 1/1 non-scanned failure(s)

Preview docs built from this PR

This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

@jbschlosser jbschlosser requested a review from mruberry June 18, 2021 03:11
Copy link
Collaborator

@mruberry mruberry left a comment

Choose a reason for hiding this comment

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

This seems cool but the test failures look real

@jbschlosser jbschlosser force-pushed the test_parameterization branch from 224f49a to 2716c29 Compare June 22, 2021 20:44
@jbschlosser jbschlosser marked this pull request as ready for review June 22, 2021 20:46
@jbschlosser jbschlosser force-pushed the test_parameterization branch 2 times, most recently from 01ba128 to a919295 Compare June 22, 2021 21:09
@jbschlosser jbschlosser changed the title [WIP] Test parameterization for instantiated device-specific tests Test parameterization for instantiated device-specific tests Jun 24, 2021
@zou3519 zou3519 self-requested a review June 24, 2021 18:03
@mruberry
Copy link
Collaborator

Do you think the XLA failure is related?

@jbschlosser
Copy link
Contributor Author

jbschlosser commented Jun 28, 2021

Do you think the XLA failure is related?

No, I think those failures were caused by #60097. I'll do a rebase and see if the problem goes away.

@mruberry Looks like no more XLA failures after the rebase :)

@jbschlosser jbschlosser force-pushed the test_parameterization branch from 4a745f2 to 51fe816 Compare June 28, 2021 15:59
@jbschlosser jbschlosser changed the title Test parameterization for instantiated device-specific tests Test parametrization for instantiated device-specific tests Jun 28, 2021
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not in love with the string matching but I guess it's OK as long as we document it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, I'm not in love with it either.. Alternatively to doing this, the device / devices arg could be unconditionally passed again. It could probably be argued that all tests instantiated with instantiate_device_type_tests() should accept and use device or devices, but unfortunately some tests (probably wrongly) violate this.

Copy link
Collaborator

@mruberry mruberry left a comment

Choose a reason for hiding this comment

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

Hey @jbschlosser! This seems like a cool refactor. I made a couple inline comments for your review. Approving this now since I'll be on pto the rest of this week, however.

@facebook-github-bot
Copy link
Contributor

@jbschlosser has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@jbschlosser jbschlosser force-pushed the test_parameterization branch from f3409a8 to 6ea2ce8 Compare June 30, 2021 19:13
@facebook-github-bot
Copy link
Contributor

@jbschlosser has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@jbschlosser merged this pull request in 03b5a22.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants