-
Notifications
You must be signed in to change notification settings - Fork 58
[IR][Bugfix] Improvements to the normalizer and well-formed checker #288
Changes from all commits
bf883e0
6c28418
04bd8f0
c972ac7
b700e84
726dbe6
8443430
95cdded
cacd586
83d03df
be32741
06dcab6
a4d5543
b36899c
175e7f4
b7441f8
f3d6df6
d5e5f49
9b0b3a5
6c3a828
b3a4eab
20da866
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,9 @@ void FunctionFrameNode::ExitWithScope() { | |
// Step 1: Create the function. | ||
CHECK(output.defined()) << "ValueError: A Relax function must have a return value. Please use " | ||
"`return` to return an Expr"; | ||
// Normalizing a second time could result in false hits to the memo | ||
// TODO(relax-team): We should fix the memoization not to require this | ||
this->block_builder->ResetMemo(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: I had to include this seemingly strange step after getting some bizarre errors when normalizing Manually resetting the memo like this is not a good solution, IMO. I think it might make more sense to restructure the memo in the normalizer to be tied to the scope, since the block builder is already tracking the scope. It should not be possible for the memo to return a var that is not currently in scope. (Debugged thanks to the help of @yongwww and @YuchenJin) |
||
Expr body = this->block_builder->Normalize(tvm::relax::SeqExpr(binding_blocks, output.value())); | ||
Expr func_shape = ret_shape.value_or(tvm::relax::RuntimeDepShape()); | ||
if (func_shape->IsInstance<tvm::relax::RuntimeDepShapeNode>()) { | ||
|
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.
@junrushao @YuchenJin This is a good reason to decouple the Relax AST from the Relay one 😅 (see also the change I needed for
TupleGetItem
).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.
Totally agree we should decouple the AST from Relay someday!
Currently we directly added a
shape_
field toRelayExpr
: https://github.com/tlc-pack/relax/blob/relax/include/tvm/ir/expr.h#L377, so before the AST decoupling, we can still rely on that the AST nodes borrowed from Relay have ashape_
field.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.
Odd, not sure why I was getting failures then. It would throw an exception saying that there was no
shape_
defined.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.
Example:
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's because we forgot to add
shape_
to itsVisitAttrs
(just noticed now 😄 ): https://github.com/tlc-pack/relax/blob/relax/include/tvm/relay/expr.h#L565, so theshape_
attribute is not reflected in the Python class side. See CallNode has its shape_ visited: https://github.com/tlc-pack/relax/blob/relax/include/tvm/relay/expr.h#L334.Given we will decouple the Relax AST from Relay AST soon (#292), we can leave it as is, and we fix it in a batch.
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.
Okay, great. Happy to update the printer alongside those changes, just let me know