-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Implement IRParser. #16987
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
Implement IRParser. #16987
Conversation
eellison
left a comment
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.
Looks good!! Main comment is about when to parse the type of values. Block inputs should probably be added on this PR.
Follow-up PRs can handle more complex type parsing, and differentiable subgraphs / fusion groups.
torch/csrc/jit/irparser.cpp
Outdated
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 use AT_ASSERT instead ? abort isn't really used as a pattern and AT_ASSERT will give line number information / derive from common exception class.
torch/csrc/jit/irparser.cpp
Outdated
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.
Adding this type parser gives us a different type parser in type_parser.cpp, operator.cpp, annotations.py, and now irparser.cpp 🤪
I'm not sure if any of them can be unified but worth keeping track of...
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 the suggestion, I'll take a look at those parser and see what can be shared.
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 don't think it's possible currently, since we have types internally that are not user-exposed - CompleteTensorType, for example.
Maybe in the future if we expose annotating detailed Tensor Types than it might work. But as of now I'm not sure that much can be shared.
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.
We should not end up with a fourth type parser. I think it would be best to share the schema parser's std::pair<TypePtr, c10::optional<AliasInfo>> parseType(), which can be refactored to be a common component. It is the closest in syntax to what the IR printer prints, and we can add cases for DimensionedTensor and CompleteTensor that are feature-gated by a boolean. For now this code is fine, as long as the followup that merges it happens.
torch/csrc/jit/irparser.cpp
Outdated
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.
This will fail with something like:
%7 : float = prim::Constant[value=2]()
I would imagine you want to change the way float attributes are printed in ir.cpp to do something similar to what is done here
pytorch/aten/src/ATen/core/ivalue.cpp
Line 56 in 3f8fd19
| case IValue::Tag::Double: { |
torch/csrc/jit/irparser.cpp
Outdated
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 think to parse attribute you need the type annotation of the node. Otherwise there's no way to determine the attribute type of empty lists. This will also make it easier to parse floats...
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.
We probably can add optional annotation into IR to resolve these ambiguities, e.g.
%x : float = my::node[value=10 : float, someList=[] : string[]]()
Also, please note that the lists support is pretty limited in the parser at the moment, and that's something I plan to work on incrementally after this initial big diff lands.
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.
Simplest thing would be to use the attributes suffix on each token: 10i, []is
torch/csrc/jit/irparser.cpp
Outdated
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.
Yea maybe add an assertion that the name is contained, I think it should fail here
torch/csrc/jit/irparser.cpp
Outdated
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 don't think we need the block name, fyi
torch/csrc/jit/irparser.cpp
Outdated
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 parse operator name / op name? that's how it's referred to in the rest of the codebase.
torch/csrc/jit/irparser.cpp
Outdated
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 imagine we always want to have a block here. If you're inside a graph use g->block().
torch/csrc/jit/irparser.cpp
Outdated
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.
Stmt inputs won't have their type annotated, we just want to parse the value name and access the value in our map. See my comment at parseBlockOutputs.
torch/csrc/jit/irparser.cpp
Outdated
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.
Return statements won't have the type annotated
6b1029f to
43de00b
Compare
|
Currently this is based on another commit but it has multiple commits itself, so there is no way to comment on just these changes. Can it be rebased so that there is only one commit with the changes for this PR? |
43de00b to
65c79df
Compare
|
@ZolotukhinM I have a tool which can "stack" diffs appropriately, as zdevito is requesting, at https://github.com/ezyang/gh Let me know if you're interested in beta testing it. |
65c79df to
9203690
Compare
facebook-github-bot
left a comment
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.
@ZolotukhinM has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
zdevito
left a comment
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.
This looks good. I only have minor things.
torch/csrc/jit/irparser.cpp
Outdated
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.
Probably don't need no type, can't it just be "Tensor" (based on usage in this file)
torch/csrc/jit/irparser.cpp
Outdated
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.
We should not end up with a fourth type parser. I think it would be best to share the schema parser's std::pair<TypePtr, c10::optional<AliasInfo>> parseType(), which can be refactored to be a common component. It is the closest in syntax to what the IR printer prints, and we can add cases for DimensionedTensor and CompleteTensor that are feature-gated by a boolean. For now this code is fine, as long as the followup that merges it happens.
torch/csrc/jit/irparser.cpp
Outdated
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.
All the errors should use throw ErrorReport(token.range()) << "..." that way the error is reported with the right source information.
torch/csrc/jit/irparser.cpp
Outdated
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.
Symbol::attr(name) does the same thing.
torch/csrc/jit/irparser.cpp
Outdated
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.
these probably should be int64_t
torch/csrc/jit/irparser.cpp
Outdated
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.
Simplest thing would be to use the attributes suffix on each token: 10i, []is
torch/csrc/jit/irparser.cpp
Outdated
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.
nit: This code appears twice, refactor?
9203690 to
85bf090
Compare
facebook-github-bot
left a comment
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.
@ZolotukhinM has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
It might need some cleaning up and might be missing some features, but it should be already working for most cases.
85bf090 to
3f53b33
Compare
facebook-github-bot
left a comment
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.
@ZolotukhinM has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
facebook-github-bot
left a comment
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.
@ZolotukhinM has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
facebook-github-bot
left a comment
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.
@ZolotukhinM has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
It might need some cleaning up and might be missing some features, but it should be already working for most cases.
This PR is based on top of PR16986 (so please review only the last commit here).