Skip to content

Conversation

@SherlockNoMad
Copy link
Contributor

@SherlockNoMad SherlockNoMad commented Oct 7, 2022

Stack from ghstack (oldest at bottom):

This PR introduces an interface for user defined function that filters the matches in SubgraphRewriter. The function will have the following signature.

callable(match: InternalMatch, original_graph: Graph, pattern_graph: Graph) -> bool

This filter is applied after SubgraphMatcher returns the matches, and before replacement takes place.

@pytorch-bot
Copy link

pytorch-bot bot commented Oct 7, 2022

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/86430

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures, 1 Pending

As of commit d88b8c8:
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.


# Filter out matches that don't match the filter
if match_filter:
_matches = [m for m in _matches if match_filter(m, original_graph, pattern_graph)]
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need original_graph? I don't know how original_graph will be helpful in filtering the match since it won't know where to look

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want to keep the function signature general, so that I won't need to come back to this and add another field.
My guess is that original_graph might be useful for filtering out the matches, if it need to check the surrounding nodes of the match.



def _replace_pattern(gm: GraphModule, pattern: Callable, replacement: Callable,
match_filter: Optional[Callable[["InternalMatch", Graph, Graph], bool]] = None) -> List[Match]: # type: ignore[name-defined]
Copy link
Contributor

Choose a reason for hiding this comment

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

please fix the lint

Copy link
Contributor

@jerryzh168 jerryzh168 left a comment

Choose a reason for hiding this comment

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

thanks! lg overall, had a question about argument for filter

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 7, 2022
@jerryzh168
Copy link
Contributor

Stack from ghstack (oldest at bottom):

could you add a Summary and Test for the PR, would be useful for context and future reference, something like this: #86338 (comment)

SherlockNoMad added a commit that referenced this pull request Oct 7, 2022
ghstack-source-id: 17819d2
Pull Request resolved: #86430
@SherlockNoMad
Copy link
Contributor Author

Stack from ghstack (oldest at bottom):

could you add a Summary and Test for the PR, would be useful for context and future reference, something like this: #86338 (comment)

Updated. Thanks for reviewing this!

@SherlockNoMad
Copy link
Contributor Author

@pytorchbot merge -g

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks on your PR pass since you used the green (-g) flag (ETA: 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2022

Hey @SherlockNoMad.
You've committed this PR, but it does not have both a 'release notes: ...' and 'topics: ...' label. Please add one of each to the PR. The 'release notes: ...' label should represent the part of PyTorch that this PR changes (fx, autograd, distributed, etc) and the 'topics: ...' label should represent the kind of PR it is (not user facing, new feature, bug fix, perf improvement, etc). The list of valid labels can be found here for the 'release notes: ...' and here for the 'topics: ...'.
For changes that are 'topic: not user facing' there is no need for a release notes label.

facebook-github-bot pushed a commit that referenced this pull request Oct 10, 2022
Summary:
This PR introduces an interface for user defined function that filters the matches in SubgraphRewriter. The function will have the following signature.

callable(match: InternalMatch, original_graph: Graph, pattern_graph: Graph) -> bool

This filter is applied after SubgraphMatcher returns the matches, and before replacement takes place.

Pull Request resolved: #86430
Approved by: https://github.com/jerryzh168

Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/455b873919d928a073eb2d60e07d1c5b2de2d6c6

Reviewed By: seemethere

Differential Revision: D40196820

Pulled By: seemethere

fbshipit-source-id: 3c854843094f79c6b23501b513fa029e5adf60a8
@facebook-github-bot facebook-github-bot deleted the gh/SherlockNoMad/38/head branch June 8, 2023 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged release notes: fx release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants