yongwww commented on code in PR #14282:
URL: https://github.com/apache/tvm/pull/14282#discussion_r1142704214
##########
src/relax/transform/decompose_composite_ops.cc:
##########
@@ -110,21 +111,60 @@ class NormInferenceSimplifier : public ExprMutator {
Map<Expr, Expr> batch_norm_map_;
};
+class OpDecomposer : public ExprMutator {
+ public:
+ static Expr Decompose(Expr expr) { return OpDecomposer()(expr); }
+
+ private:
+ using ExprMutator::VisitExpr_;
+ Expr TensorToShape(const Call& call_node) {
+ ICHECK(call_node->args.size() == 1);
+ ICHECK(call_node->struct_info_.defined());
+ Expr expr = call_node->args[0];
+ const ShapeStructInfoNode* sinfo =
GetStructInfoAs<ShapeStructInfoNode>(call_node);
+ ICHECK(sinfo);
+ // call builtin function that converts tensor to shape tuple
+ Var call = builder_->Emit(Call(ExternFunc("vm.builtin.tensor_to_shape"),
{expr}, {},
Review Comment:
I think the Emit should be :
```c++
static const Op& tensor_to_shape_op =
Op::Get("relax.builtin.tensor_to_shape");
Var call = builder_->Emit(Call(tensor_to_shape_op, {expr}, {}, ...
```
##########
src/relax/backend/vm/vm_builtin_lower.cc:
##########
@@ -129,9 +129,23 @@ class VMBuiltinLowerMutator : public ExprMutator {
Expr Reshape(const Call& call_node) {
ICHECK(call_node->args.size() == 2);
ICHECK(call_node->struct_info_.defined());
- CHECK(call_node->args[1]->IsInstance<ShapeExprNode>())
- << "VMBuiltinLower expects the shape arg of reshape op to be a
ShapeExpr";
- return Call(builtin_reshape_, call_node->args, Attrs(),
{GetStructInfo(call_node)});
+ auto arg = call_node->args[1];
+ CHECK(arg->IsInstance<ShapeExprNode>() || arg->IsInstance<VarNode>())
+ << "VMBuiltinLower expects the shape arg of reshape op to be a
ShapeExpr or VarNode bound "
+ "to a ShapeExpr";
+
+ if (arg->IsInstance<ShapeExprNode>()) {
+ return Call(builtin_reshape_, call_node->args, Attrs(),
{GetStructInfo(call_node)});
+ }
+
+ ICHECK(arg->IsInstance<VarNode>());
Review Comment:
unnecessary ICHECK
##########
src/relax/transform/decompose_composite_ops.cc:
##########
@@ -110,21 +111,60 @@ class NormInferenceSimplifier : public ExprMutator {
Map<Expr, Expr> batch_norm_map_;
};
+class OpDecomposer : public ExprMutator {
+ public:
+ static Expr Decompose(Expr expr) { return OpDecomposer()(expr); }
+
+ private:
+ using ExprMutator::VisitExpr_;
+ Expr TensorToShape(const Call& call_node) {
+ ICHECK(call_node->args.size() == 1);
Review Comment:
seems the ICHECK is duplicate, the check in ReturnTensorToShapeStructInfo
should be good to cover this
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]