Skip to content

Conversation

@ZolotukhinM
Copy link

@ZolotukhinM ZolotukhinM commented Apr 16, 2019

Stack from ghstack:

Differential Revision: D14962182

@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Apr 16, 2019
@ZolotukhinM ZolotukhinM requested review from bwasti, duc0 and zdevito April 16, 2019 21:10
@ZolotukhinM
Copy link
Author

We can later add more features to this (e.g. nice iterators as in #17100). I'm putting this version for review now to unblock some of other work items.

Copy link
Contributor

@bwasti bwasti left a comment

Choose a reason for hiding this comment

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

looks very good -- well tested

}

/**
* Recursively try to match pattern with the actual graph starting from the
Copy link
Contributor

Choose a reason for hiding this comment

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

is this recursive?

Copy link
Author

Choose a reason for hiding this comment

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

is this recursive?

Yes, matchNodes call matchValues, and matchValues call matchNodes. The recursion stops when we reach Param nodes in the pattern or if we hit an already visited node/value.

while (!blocks_to_visit.empty()) {
const Block* block = blocks_to_visit.top();
blocks_to_visit.pop();
for (const Node* n : block->nodes()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe call out that this is a match on the imperative interpretation of the IR, and not the data flow graph

diamonds declared in different orders won't match, right?

Copy link
Author

Choose a reason for hiding this comment

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

Hm, they should match whatever the order is (I added a test for this). We do follow data flow graph, not the sequential list of nodes: matchNodes call matchValues for nodes' inputs, and matchValues proceed to values' defs calling matchNodes for them.

PS: This implementation lacks aliasing checks, which are required if we're going to replace matched subgraphs with something else - I don't forget about it, just plan to follow up on that separately.

Add minimalistic implementation of subgraph matcher.

gh-metadata: pytorch pytorch 19322 gh/ZolotukhinM/10/head
Copy link
Author

@ZolotukhinM ZolotukhinM 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 taking a look! I replied inline.

}

/**
* Recursively try to match pattern with the actual graph starting from the
Copy link
Author

Choose a reason for hiding this comment

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

is this recursive?

Yes, matchNodes call matchValues, and matchValues call matchNodes. The recursion stops when we reach Param nodes in the pattern or if we hit an already visited node/value.

while (!blocks_to_visit.empty()) {
const Block* block = blocks_to_visit.top();
blocks_to_visit.pop();
for (const Node* n : block->nodes()) {
Copy link
Author

Choose a reason for hiding this comment

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

Hm, they should match whatever the order is (I added a test for this). We do follow data flow graph, not the sequential list of nodes: matchNodes call matchValues for nodes' inputs, and matchValues proceed to values' defs calling matchNodes for them.

PS: This implementation lacks aliasing checks, which are required if we're going to replace matched subgraphs with something else - I don't forget about it, just plan to follow up on that separately.

Mikhail Zolotukhin added 3 commits April 19, 2019 11:11
Add minimalistic implementation of subgraph matcher.

gh-metadata: pytorch pytorch 19322 gh/ZolotukhinM/10/head
Add minimalistic implementation of subgraph matcher.

gh-metadata: pytorch pytorch 19322 gh/ZolotukhinM/10/head
Add minimalistic implementation of subgraph matcher.

gh-metadata: pytorch pytorch 19322 gh/ZolotukhinM/10/head
@zou3519 zou3519 deleted the gh/ZolotukhinM/10/head branch April 19, 2019 23:37
@facebook-github-bot
Copy link
Contributor

@ZolotukhinM merged this pull request in 9818c7c.

zhangguanheng66 pushed a commit to zhangguanheng66/pytorch that referenced this pull request May 6, 2019
Summary:
Pull Request resolved: pytorch#19322
ghimport-source-id: 93c713f829d1b2a9aa5d104cb1f30148dd37c967

Differential Revision: D14962182

Pulled By: ZolotukhinM

fbshipit-source-id: 3989fba06502011bed9c24f12648d0baa2a4480c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants