-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[Relay] Extract intermediate node by its expression ID #12646
Conversation
Hi @masahi ! Do you think we need such an analysis pass? Thank you! |
I think such pass is useful indeed, but I don't have a good idea on how to identify the intermediate node that will become the output node in the extracted subgraph. Your approach that requests an integer ID from users and incrementing the count as we go through ops is probably ok for chain-like models, but for more general models where there is no clear ordering on nodes, this would not work. |
Hi masashi, thanks for your reply.
The integer ID that I request is the number that |
ok, I agree that using the order from print works in practice. I don't like the name "DumpOPByName". How about this signature: |
btw, have you used |
I agree I have used |
Hi masahi, when I use |
I see, that makes sense (that Please rebase against |
I see, CI has passed now, please review again when you have free time. Thank you! |
ah yeah this is related to what we discussed a few weeks at community meeting. There hasn't been a follow-on edge ID proposal yet. |
|
||
This function is used for extracting Relay Expr | ||
by the local variable number of the main function | ||
that we can see in `print(mod["main"])`. |
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 be nice to have an example here. local variable number
is not a word in TVM, we should just refer to them as expression ID or something.
---------- | ||
mod : tvm.IRModule | ||
|
||
expr_id : the Expr Number that we want to extract |
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.
Number -> ID
249d34b
to
49aeb26
Compare
-------- | ||
.. code-block:: python | ||
|
||
# Supposed our module is printed like this: |
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.
Suppose
|
||
|
||
def extract_intermdeiate_expr(mod, expr_id): | ||
"""Extract Relay Expr by the expression ID |
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.
the -> its
IRModule Extract() { | ||
VisitExpr(this->mod_->Lookup("main")); | ||
|
||
// ensure the target op num we want to dump is valid. |
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.
num -> id
dump -> extract
using MixedModeVisitor::VisitExpr_; | ||
|
||
const IRModule mod_; | ||
/*! \brief the OP Number that we want to dump. */ |
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.
OP Number -> expression ID
dump -> extract
@sisleyli More doc comments, but otherwise looks good |
Hi @masahi, CI shows that |
@tvm-bot rerun |
modify doc comments
fbc9d5a
to
710ecfa
Compare
Hi @masahi , I see that CI has passed. is it able to be merged, or need more work? Thank you! |
[Relay] Extract Intermediate Expr by relay expr ID for analysis modify doc comments Co-authored-by: Bin Li <binli1@amd.com>
Hi,
When I actually develop operators for some models, I often need to do some verification.
And when I encounter a situation where the input and output values of the entire model do not match the golden values, I often need to dump some intermediate nodes to confirm which node the problem starts from.
As we know, we can easily print Relay IR by
print(mod["main"])
,Relay IR represents each node as "%xx %10 %20", I feel comfortable if we can dump nodes with "%xx" as a parameter.
So I develop a pass that can dump op by
dump_op_by_num(mod,xx)
.Because we generally use dump OP for analysis purposes, I set it as an
relay.analysis
API.What do you think? Do we need such an API?
I am looking forward to your reply. Thank you!