-
Notifications
You must be signed in to change notification settings - Fork 76
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
[Op][Trans1] Reshape, Transpose, ExpandDims, Squeeze, Flatten #78
[Op][Trans1] Reshape, Transpose, ExpandDims, Squeeze, Flatten #78
Conversation
88d6097
to
d81032e
Compare
include/tvm/relax/op_attr_types.h
Outdated
@@ -325,6 +325,50 @@ struct ReduceAttrs : public tvm::AttrsNode<ReduceAttrs> { | |||
} | |||
}; // struct ReduceAttrs | |||
|
|||
/*! \brief Attributes used in reshape operator */ | |||
struct ReshapeAttrs : public tvm::AttrsNode<ReshapeAttrs> { | |||
Array<PrimExpr> new_shape; |
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.
Because we now support ShapeExpr as first class, let us make reshape take Expr as the second argument and expects a ShapeStructInfo
Note that this would require us to enable negative values in shape, which is OK.
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 would require some special checkings for -1 in ShapeExpr.
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.
Perhaps an implicit op, relax.builtin.prepare_reshape_shape(src_tensor, shape)
for the most general case
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.
My consideration of making this attribute is that having negative values in ShapeExpr doesn’t sound perfectly right. -1 is only used in Reshape. And any other case where non-positive values appear in ShapeExpr or ShapeStructInfo should be regarded as invalid (I’m even thinking about adding a check to ShapeExpr constructor to enforce this).
Since the -1 inference is only for reshape, I think it’s reasonable to make Reshape treat the input specially, compared with other ops (like full/ones/zeros in #79), because those ops require normal input shape, where any non-positive value is not allowed.
Allowing -1 to appear in ShapeExpr brings the implication that we will need to check “if the input ShapeExpr contains -1” in all other use site of ShapeExpr, which does not worth IMHO.
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.
One of the main problem in this case is to have PrimExpr appear as an Attrs, which breaks our abstraction level (Attrs should always remain constant).
In this case, having constant reshape is fine. But we won't be able to update the prim expression if the IR get mutated(say we want to remap n into some other shape variables) because the assumption is that Attrs only contans constant(and won't get updated).
So having symbolic new_shape as Attr is not ideal from that pov. We can have new_shape as constant int.
As another alternative, perhaps we should just require this as ShapeExpr, and provide helper conversion to construct such shape Expr in reshape implementation in construction time.
Expr MakeReshape(x, Array<PrimExpr> shape) {
ShapeExpr new_shape
if (shape.as<Array<PrimExpr>>()) {
// check -1, check x.shape and construct such a ShapeExpr when constructing the call
}
return Call(reshape, {x, new_shape});
}
This of course is also not perfect but restricts the use-cases to where we can handle.
Some general remarks
|
@tqchen Addressed most of your comments, with the last commit dedicated to rename API names and categorize per DataAPI. |
61bbfa8
to
1cac3f4
Compare
Thanks @MasterJH5574 , see my followup comment on reshape. In this case, I think we can make new_shape a ShapeExpr and do some best effort -1 deduction at construction time for now. |
3643e99
to
765fd5a
Compare
765fd5a
to
946c5ca
Compare
Thanks @tqchen . Doing -1 inference upon construction does fit better in our case, and I just update in this way. Still have a couple of notes here:
|
LGTM! |
* Enable tests. * Updated. * Updated. * Updated.
* Enable tests. * Updated. * Updated. * Updated.
* Enable tests. * Updated. * Updated. * Updated.
This PR introduces transformation operators to the latest StructInfo codebase. It is part of our operator migration efforts as listed in #62.
Again, we split the migration into multiple parts and PRs for transformation ops, due to the large amount of operators. This PR includes the following operators:
Most LOC comes from the test file