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/06/24 09:32:47 UTC

[GitHub] [tvm] d-smirnov opened a new pull request #8325: FoldScaleAxis became non-recursive

d-smirnov opened a new pull request #8325:
URL: https://github.com/apache/tvm/pull/8325


   This PR migrates FoldScaleAxis optimization pass from ExprVisitor/ExprMutator to non-recursive MixedModeVisitor/MixedModeMutator. The specific transforming part itself is still recursive, however the underlying traversal machinery is now non-recursive.


-- 
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] d-smirnov edited a comment on pull request #8325: FoldScaleAxis became non-recursive

Posted by GitBox <gi...@apache.org>.
d-smirnov edited a comment on pull request #8325:
URL: https://github.com/apache/tvm/pull/8325#issuecomment-872393233


   @mbrookhart 
   >and it seems you've made some more complicated changes above moving it to mixed mode?
   
   There is an extra minor change related to not doing the optimization if there were no messages produced by preparation sub-passes.


-- 
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: commits-unsubscribe@tvm.apache.org

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



[GitHub] [tvm] d-smirnov commented on a change in pull request #8325: FoldScaleAxis became non-recursive

Posted by GitBox <gi...@apache.org>.
d-smirnov commented on a change in pull request #8325:
URL: https://github.com/apache/tvm/pull/8325#discussion_r666040121



##########
File path: src/relay/transforms/fold_scale_axis.cc
##########
@@ -735,25 +733,41 @@ class BackwardTransformer : public ObjectRef {
   }
   using ContainerType = BackwardTransformerNode;
 };
-
-Expr BackwardTransformerNode::Transform(const CallNode* call_node, Message message, Expr scale) {
-  static const auto& ftransform = Op::GetAttrMap<FBackwardTransform>("FScaleAxisBackwardTransform");
-  auto f = ftransform.get(call_node->op, nullptr);
-  if (f != nullptr) {
+/*!

Review comment:
       Added

##########
File path: src/relay/transforms/fold_scale_axis.cc
##########
@@ -735,25 +733,41 @@ class BackwardTransformer : public ObjectRef {
   }
   using ContainerType = BackwardTransformerNode;
 };
-
-Expr BackwardTransformerNode::Transform(const CallNode* call_node, Message message, Expr scale) {
-  static const auto& ftransform = Op::GetAttrMap<FBackwardTransform>("FScaleAxisBackwardTransform");
-  auto f = ftransform.get(call_node->op, nullptr);
-  if (f != nullptr) {
+/*!
+ * \brief Transform the expr to consider the scaling.
+ *
+ * \param expr The input expression.
+ * \param message The axes to scale.
+ * \param scale The scale applied to the axes.
+ * \return The result of transformation.
+ */
+Expr BackwardTransformerNode::Transform(const Expr& expr, Message message, Expr scale) {
+  if (const CallNode* call_node = expr.as<CallNode>()) {
+    static const auto& ftransform =
+        Op::GetAttrMap<FBackwardTransform>("FScaleAxisBackwardTransform");
+    auto f = ftransform.get(call_node->op, nullptr);
     const Call call = GetRef<Call>(call_node);
-    const auto it = memo_.find(call);
-    if (it != memo_.end()) {
-      return it->second;
+    // ignore if there is a message
+    if (!message.defined()) {
+      const auto it = memo_.find(call);
+      if (it != memo_.end()) {
+        return it->second;
+      }
+    }
+    Expr new_expr = NullValue<Expr>();
+    if (f != nullptr) {
+      new_expr = f(call, message, scale, GetRef<BackwardTransformer>(this));
+    } else {
+      ICHECK(!message.defined()) << "outstanding scale";
+      new_expr = NormalCallTransform(call.operator->());
     }
-    Expr new_expr = f(GetRef<Call>(call_node), message, scale, GetRef<BackwardTransformer>(this));
     memo_[call] = new_expr;
     return new_expr;
   } else {
     ICHECK(!message.defined()) << "outstanding scale";
-    return NormalCallTransform(call_node);
+    return this->Mutate(expr);
   }
 }
-

Review comment:
       Added




-- 
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: commits-unsubscribe@tvm.apache.org

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



[GitHub] [tvm] mbrookhart merged pull request #8325: FoldScaleAxis became non-recursive

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


   


-- 
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: commits-unsubscribe@tvm.apache.org

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



[GitHub] [tvm] vinx13 commented on a change in pull request #8325: FoldScaleAxis became non-recursive

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



##########
File path: src/relay/transforms/fold_scale_axis.cc
##########
@@ -735,25 +733,41 @@ class BackwardTransformer : public ObjectRef {
   }
   using ContainerType = BackwardTransformerNode;
 };
-
-Expr BackwardTransformerNode::Transform(const CallNode* call_node, Message message, Expr scale) {
-  static const auto& ftransform = Op::GetAttrMap<FBackwardTransform>("FScaleAxisBackwardTransform");
-  auto f = ftransform.get(call_node->op, nullptr);
-  if (f != nullptr) {
+/*!

Review comment:
       nit: add a blank line

##########
File path: src/relay/transforms/fold_scale_axis.cc
##########
@@ -735,25 +733,41 @@ class BackwardTransformer : public ObjectRef {
   }
   using ContainerType = BackwardTransformerNode;
 };
-
-Expr BackwardTransformerNode::Transform(const CallNode* call_node, Message message, Expr scale) {
-  static const auto& ftransform = Op::GetAttrMap<FBackwardTransform>("FScaleAxisBackwardTransform");
-  auto f = ftransform.get(call_node->op, nullptr);
-  if (f != nullptr) {
+/*!
+ * \brief Transform the expr to consider the scaling.
+ *
+ * \param expr The input expression.
+ * \param message The axes to scale.
+ * \param scale The scale applied to the axes.
+ * \return The result of transformation.
+ */
+Expr BackwardTransformerNode::Transform(const Expr& expr, Message message, Expr scale) {
+  if (const CallNode* call_node = expr.as<CallNode>()) {
+    static const auto& ftransform =
+        Op::GetAttrMap<FBackwardTransform>("FScaleAxisBackwardTransform");
+    auto f = ftransform.get(call_node->op, nullptr);
     const Call call = GetRef<Call>(call_node);
-    const auto it = memo_.find(call);
-    if (it != memo_.end()) {
-      return it->second;
+    // ignore if there is a message
+    if (!message.defined()) {
+      const auto it = memo_.find(call);
+      if (it != memo_.end()) {
+        return it->second;
+      }
+    }
+    Expr new_expr = NullValue<Expr>();
+    if (f != nullptr) {
+      new_expr = f(call, message, scale, GetRef<BackwardTransformer>(this));
+    } else {
+      ICHECK(!message.defined()) << "outstanding scale";
+      new_expr = NormalCallTransform(call.operator->());
     }
-    Expr new_expr = f(GetRef<Call>(call_node), message, scale, GetRef<BackwardTransformer>(this));
     memo_[call] = new_expr;
     return new_expr;
   } else {
     ICHECK(!message.defined()) << "outstanding scale";
-    return NormalCallTransform(call_node);
+    return this->Mutate(expr);
   }
 }
-

Review comment:
       nit: keep the blank line here




-- 
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: commits-unsubscribe@tvm.apache.org

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



[GitHub] [tvm] d-smirnov commented on pull request #8325: FoldScaleAxis became non-recursive

Posted by GitBox <gi...@apache.org>.
d-smirnov commented on pull request #8325:
URL: https://github.com/apache/tvm/pull/8325#issuecomment-875989905


   bump


-- 
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: commits-unsubscribe@tvm.apache.org

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



[GitHub] [tvm] mbrookhart commented on pull request #8325: FoldScaleAxis became non-recursive

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


   Sorry! Not sure how I lost this. I don't fully understand this pass, and it seems you've made some more complicated changes above moving it to mixed mode? I would appriciate @tqchen's review, since it was originally his code.


-- 
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: commits-unsubscribe@tvm.apache.org

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



[GitHub] [tvm] vinx13 commented on pull request #8325: FoldScaleAxis became non-recursive

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


   @d-smirnov There are some irrelevant errors on CI, Could you try again to get CI passed? Thanks


-- 
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: commits-unsubscribe@tvm.apache.org

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



[GitHub] [tvm] d-smirnov commented on pull request #8325: FoldScaleAxis became non-recursive

Posted by GitBox <gi...@apache.org>.
d-smirnov commented on pull request #8325:
URL: https://github.com/apache/tvm/pull/8325#issuecomment-872393233


   >and it seems you've made some more complicated changes above moving it to mixed mode?
   There is an extra minor change related to not doing the optimization if there were no messages produced by preparation sub-passes.


-- 
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: commits-unsubscribe@tvm.apache.org

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



[GitHub] [tvm] d-smirnov commented on pull request #8325: FoldScaleAxis became non-recursive

Posted by GitBox <gi...@apache.org>.
d-smirnov commented on pull request #8325:
URL: https://github.com/apache/tvm/pull/8325#issuecomment-868306457


   @mbrookhart 


-- 
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] tqchen commented on pull request #8325: FoldScaleAxis became non-recursive

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


   Would be great if @vinx13 can also help to take a look


-- 
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: commits-unsubscribe@tvm.apache.org

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



[GitHub] [tvm] mbrookhart commented on pull request #8325: FoldScaleAxis became non-recursive

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


   Thanks @d-smirnov @vinx13 @tqchen 


-- 
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: commits-unsubscribe@tvm.apache.org

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



[GitHub] [tvm] d-smirnov commented on pull request #8325: FoldScaleAxis became non-recursive

Posted by GitBox <gi...@apache.org>.
d-smirnov commented on pull request #8325:
URL: https://github.com/apache/tvm/pull/8325#issuecomment-871411336


   bump. also cc @tqchen 


-- 
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: commits-unsubscribe@tvm.apache.org

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