yzhliu commented on a change in pull request #5357:
URL: https://github.com/apache/incubator-tvm/pull/5357#discussion_r415164446



##########
File path: src/relay/transforms/fold_scale_axis.cc
##########
@@ -314,6 +318,42 @@ class ForwardPrep : private ExprVisitor {
   }
 };
 
+static bool IsIntInArray(const Array<Integer>& axis, int v) {
+  for (size_t i = 0; i < axis.size(); i++) {
+    if (axis[i] == v)
+      return true;
+  }
+  return false;
+}
+
+static Expr ReshapeToMatchAxis(Expr scale, const Array<PrimExpr>& shape,
+  const Array<Integer>& axis) {
+  Array<Integer> arr;
+  for (size_t i = 0; i < shape.size(); i++) {
+    if (IsIntInArray(axis, i)) {
+      auto node = shape[i].as<IntImmNode>();
+      if (!node) {
+        // if the shape is not a constant, use normal transform
+        return Expr();

Review comment:
       this will cause failure as you later do `CHECK(scale.defined());` ?

##########
File path: src/relay/transforms/fold_scale_axis.cc
##########
@@ -39,6 +39,10 @@ namespace relay {
  *
  * Use namespace to reduce potential naming conflict.
  */
+
+extern Expr MakeReshape(Expr data,
+                 Array<Integer> newshape);

Review comment:
       can we move it to .h?

##########
File path: src/relay/transforms/fold_scale_axis.cc
##########
@@ -518,13 +564,30 @@ Expr Conv2DForwardRewrite(const Call& ref_call,
 
   // match the ic_axis
   if (is_depthwise_conv2d) {
-    Expr scale = ExpandBiasToMatchAxis(
-        sdata->scale, kernel_layout.ndim(), {big_oc_axis});
-    weight = Multiply(weight, scale);
+    if (is_simple) {
+      Expr scale = ExpandBiasToMatchAxis(
+          sdata->scale, kernel_layout.ndim(), {big_ko_axis});
+      weight = Multiply(weight, scale);
+    } else {
+      weight = Multiply(weight, ReshapeToMatchAxis(sdata->scale,
+          weight->type_as<TensorTypeNode>()->shape,
+          {big_ko_axis, small_ko_axis}));
+      if (!weight.defined())
+        return Expr();

Review comment:
       would this cause problem?




----------------------------------------------------------------
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:
[email protected]


Reply via email to