Skip to content
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

Closed
wants to merge 2 commits into from
Closed

Adds an OpInfo note #57428

wants to merge 2 commits into from

Conversation

mruberry
Copy link
Collaborator

@mruberry mruberry commented May 2, 2021

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

@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented May 2, 2021

💊 CI failures summary and remediations

As 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.

Click here to manually regenerate this comment.

Copy link
Collaborator

@kshitij12345 kshitij12345 left a 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()"
Copy link
Collaborator

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)

Copy link
Collaborator

@pmeier pmeier left a 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.

Copy link
Contributor

@heitorschueroff heitorschueroff left a 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
Copy link
Contributor

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.
Copy link
Contributor

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

Copy link
Contributor

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.
Copy link
Contributor

@anjali411 anjali411 May 3, 2021

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.

Copy link
Contributor

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,
Copy link
Contributor

@anjali411 anjali411 May 3, 2021

Choose a reason for hiding this comment

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

Suggested change
# What doesn't need to handwritten testing are the propertes listed above,
# What doesn't need to be handwritten are the properties listed above,

Copy link
Contributor

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?

Copy link
Collaborator Author

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
Copy link
Contributor

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
Copy link
Contributor

@anjali411 anjali411 May 3, 2021

Choose a reason for hiding this comment

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

Suggested change
# 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

Copy link
Contributor

@anjali411 anjali411 left a 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
Copy link
Contributor

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.

Comment on lines 170 to 171
# Most OpInfos are collected in the "op_db" sequence, although some specialized
# tests have their own OpInfo-based datastructures.
Copy link
Contributor

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.

Copy link
Collaborator

@ngimel ngimel left a 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,
Copy link
Collaborator

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.
Copy link
Collaborator

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.
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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?

@facebook-github-bot
Copy link
Contributor

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

@facebook-github-bot
Copy link
Contributor

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

@facebook-github-bot
Copy link
Contributor

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

@facebook-github-bot
Copy link
Contributor

@mruberry merged this pull request in 5609c2e.

@mruberry mruberry deleted the op_info_comment branch January 14, 2022 20:12
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.

None yet

8 participants