New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds an OpInfo note #57428
Adds an OpInfo note #57428
Conversation
💊 CI failures summary and remediationsAs of commit b7dff0a (more details on the Dr. CI page and at hud.pytorch.org/pr/57428): 💚 💚 Looks good so far! There are no failures yet. 💚 💚 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just asked one question.
LGTM!
Thanks
# Most OpInfos are collected in the "op_db" sequence, although some specialized | ||
# tests have their own OpInfo-based datastructures. | ||
# | ||
# OpInfos are intended to replace custom test generators, like "method_tests()" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this paragraph needed? I believe gradually (hopefully soon) the mentioned test generators will be removed and will no longer serve as a reference for this paragraph. (Plus this just doesn't describe anything about the usage and details of OpInfo)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome write-up! I think this makes it a lot easier for someone starting to work on OpInfo
's.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great comment, this is surely going to make it easier for people to get started with OpInfos.
# of metadata related to a PyTorch operator, like torch.add. This metadata | ||
# can be separated into three categories: | ||
# | ||
# 1) Metadata describing the operator, like "dtypesIfCPU", which describes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metadata describing the operator
dtypesIfCPU
does not quite describe the operator. maybe Metadata defining the operator support
?
# 1) Metadata describing the operator, like "dtypesIfCPU", which describes | ||
# the dtypes the operator supports on the CPU. This metadata | ||
# is used by generated tests to understand what they should test | ||
# and what the expected results of the test should be. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe give the example of ref
here to indicate that operators can be compared to a function from another library
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh I see you mention it below.
# 2) That an operator's aliases, if any, perform the same computation. | ||
# 3) That an operator implements its gradient and second-order gradient | ||
# correctly. | ||
# 4) That an operators works when traced or scripted by the jit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And that functions in eager mode and when scripted produce the same output for a given input.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also tests JIT autodifferentiation and alias remapping
# to verify the operator computes what it's expected to. Even though there | ||
# are many linalg ops with OpInfos, for instance, there are still | ||
# comprehensive handwritten tests for these operators in test_linalg.py. | ||
# What doesn't need to handwritten testing are the propertes listed above, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# What doesn't need to handwritten testing are the propertes listed above, | |
# What doesn't need to be handwritten are the properties listed above, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anjali411, that suggested revision seems to convey incorrect information.
What about Validating the aforementioned properties doesn't require handwritten tests
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll tweak it; good grammar catch
# are many linalg ops with OpInfos, for instance, there are still | ||
# comprehensive handwritten tests for these operators in test_linalg.py. | ||
# What doesn't need to handwritten testing are the propertes listed above, | ||
# except in rare cases where the generated tests are insufficient or |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe give an example here?
# Adding an OpInfo may seem confusing because the base OpInfo class has | ||
# a lot of attributes, but luckily most OpInfos don't require all of them, | ||
# or even a majority of them, be changed from their defaults. | ||
# Looking at OpInfos for similar operators to the one you're adding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Looking at OpInfos for similar operators to the one you're adding | |
# Looking at OpInfos for the operators similar to the one you're adding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments, but looks great overall. Thanks @mruberry !
# PyTorch's "device generic test framework". See the developer Wiki article | ||
# above for more information on this test instantiation process. | ||
# | ||
# In addition to the OpInfo base class, there are subclasses of OpInfos, like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be useful to list all the OpInfo
subclasses in master at the time of writing, to show the breadth of operator coverage.
# Most OpInfos are collected in the "op_db" sequence, although some specialized | ||
# tests have their own OpInfo-based datastructures. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
although some specialized tests have their own OpInfo-based datastructures
A suggestion: having an example here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this note!
# automated test coverage by consolidating these lists into one structured and | ||
# documented list. | ||
# | ||
# Most tests that use every OpInfo are in test_ops.py. More correctly, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
every OpInfo in op_db
# 4) That an operators works when traced or scripted by the jit. | ||
# 5) That operators supporting out= do so correctly. | ||
# 6) That operators specify metadata, like which dtypes they support, | ||
# properly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would make sense to mention here that some (or all?) of these tests run only on the first element of tuple returned by sample_inputs_func
# 3) That an operator implements its gradient and second-order gradient | ||
# correctly. | ||
# 4) That an operators works when traced or scripted by the jit. | ||
# 5) That operators supporting out= do so correctly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
link to wiki on out
behavior?
# a lot of attributes, but luckily most OpInfos don't require all of them, | ||
# or even a majority of them, be changed from their defaults. | ||
# Looking at OpInfos for similar operators to the one you're adding | ||
# is usually a good way to start. OpInfo tests should also be designed so |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Existing OpInfo tests are designed"? Otherwise, this sentence may read as "If you are adding a new OpInfo test, it should be designed...", but this note doesn't give nearly enough information to do that, so don't go there.
# 2) Test directives, like "skips", which indicates that some generated | ||
# tests should be skipped for this operator. Test directives | ||
# directly control the behavior of generated tests. | ||
# 3) A "sample_inputs_func", a function that can generate valid inputs to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sample_inputs_func deserves more comments - does it provide several inputs cases? How one should go about deciding how many input variants to add? How are kwargs handled? How can inputs for inplace operation variants be filtered?
@mruberry has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
48c9c9b
to
84a12c4
Compare
@mruberry has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
@mruberry has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
Like the title says. The OpInfo pattern can be confusing when first encountered, so this note links the Developer Wiki and tracking issue, plus elaborates on the goals and structure of the OpInfo pattern.
cc @imaginary-person, who I can't add as a reviewer, unfortunately