You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2021/04/12 08:57:01 UTC

[GitHub] [tvm] hgt312 opened a new pull request #7827: [Relay][Pass] SimplifyCastLike/Cast and ConcretizeFullLikeRewrite rewrites for SimplifyExpr

hgt312 opened a new pull request #7827:
URL: https://github.com/apache/tvm/pull/7827


   - `ConcretizeFullLikeRewrite`: `full_like` -> `full` when known shape
   - `SimplifyCastLike/Cast`: `cast(data, dtype)` or `cast_like(data, dtype_like)` -> `data`, when the input and output have the same dtype
   
   @yzhliu @comaniac @altanh 


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] comaniac commented on pull request #7827: [Relay][Pass] SimplifyCastLike/Cast and ConcretizeFullLikeRewrite rewrites for SimplifyExpr

Posted by GitBox <gi...@apache.org>.
comaniac commented on pull request #7827:
URL: https://github.com/apache/tvm/pull/7827#issuecomment-819206424


   Thanks @hgt312 @altanh 


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] hgt312 commented on a change in pull request #7827: [Relay][Pass] SimplifyCastLike/Cast and ConcretizeFullLikeRewrite rewrites for SimplifyExpr

Posted by GitBox <gi...@apache.org>.
hgt312 commented on a change in pull request #7827:
URL: https://github.com/apache/tvm/pull/7827#discussion_r612136157



##########
File path: src/relay/backend/build_module.cc
##########
@@ -300,6 +300,7 @@ class RelayBuildModule : public runtime::ModuleNode {
       }
     });
     pass_seqs.push_back(transform::EliminateCommonSubexpr(fskip));
+    pass_seqs.push_back(transform::InferType());

Review comment:
       Emmm... I dont know why Ci fails, just try it




-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] comaniac merged pull request #7827: [Relay][Pass] SimplifyCastLike/Cast and ConcretizeFullLikeRewrite rewrites for SimplifyExpr

Posted by GitBox <gi...@apache.org>.
comaniac merged pull request #7827:
URL: https://github.com/apache/tvm/pull/7827


   


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] comaniac commented on a change in pull request #7827: [Relay][Pass] SimplifyCastLike/Cast and ConcretizeFullLikeRewrite rewrites for SimplifyExpr

Posted by GitBox <gi...@apache.org>.
comaniac commented on a change in pull request #7827:
URL: https://github.com/apache/tvm/pull/7827#discussion_r612126834



##########
File path: src/relay/backend/build_module.cc
##########
@@ -300,6 +300,7 @@ class RelayBuildModule : public runtime::ModuleNode {
       }
     });
     pass_seqs.push_back(transform::EliminateCommonSubexpr(fskip));
+    pass_seqs.push_back(transform::InferType());

Review comment:
       Do we really need this? InferType is already in the requirement of SimplifyExpr. Other existing patterns also refer to checked_type_ so it should be fine.




-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] comaniac commented on a change in pull request #7827: [Relay][Pass] SimplifyCastLike/Cast and ConcretizeFullLikeRewrite rewrites for SimplifyExpr

Posted by GitBox <gi...@apache.org>.
comaniac commented on a change in pull request #7827:
URL: https://github.com/apache/tvm/pull/7827#discussion_r611784815



##########
File path: src/relay/transforms/simplify_expr.cc
##########
@@ -75,6 +75,59 @@ class SimplifyReshape : public DFPatternRewrite {
   DFPattern x_;
 };
 
+/*!
+ * \brief SimplifyCastLike matches the pattern of cast data to the same dtype.
+ */
+class SimplifyCastLike : public DFPatternRewrite {
+ public:
+  SimplifyCastLike() {
+    data_pat_ = IsWildcard();
+    like_pat_ = IsWildcard();
+    pattern_ = IsOp("cast_like")({data_pat_, like_pat_});
+  }
+
+  Expr Callback(const Expr& pre, const Expr& post,
+                const Map<DFPattern, Array<Expr>>& node_map) const override {
+    auto data = node_map[data_pat_][0];
+    const TensorTypeNode* data_ty = data->checked_type().as<TensorTypeNode>();
+    const TensorTypeNode* like_ty = pre->checked_type().as<TensorTypeNode>();
+    if (like_ty->dtype == data_ty->dtype) {
+      return data;
+    }
+    return post;
+  }
+
+ protected:
+  DFPattern data_pat_;
+  DFPattern like_pat_;
+};
+
+/*!
+ * \brief SimplifyCast matches the pattern of cast data to the same dtype.
+ */
+class SimplifyCast : public DFPatternRewrite {

Review comment:
       Seems like these two patterns be merged to one?
   ```
   pattern_ = IsOp("cast_like")({data_pat_, like_pat_}) || IsOp("cast")({data_pat_});
   ```
   And both patterns can use `like_ty = pre->checked_type().as<TensorTypeNode>();`.




-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] comaniac commented on a change in pull request #7827: [Relay][Pass] SimplifyCastLike/Cast and ConcretizeFullLikeRewrite rewrites for SimplifyExpr

Posted by GitBox <gi...@apache.org>.
comaniac commented on a change in pull request #7827:
URL: https://github.com/apache/tvm/pull/7827#discussion_r612182877



##########
File path: src/relay/backend/build_module.cc
##########
@@ -300,6 +300,7 @@ class RelayBuildModule : public runtime::ModuleNode {
       }
     });
     pass_seqs.push_back(transform::EliminateCommonSubexpr(fskip));
+    pass_seqs.push_back(transform::InferType());

Review comment:
       From the CI it does look like the type is missing. Since InferType is executed before and after SimplifyExpr, one possibility is your `data` is already mutated by previous patterns in this pass and that callback didn't manually specify the type.




-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org