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 2020/11/04 23:02:13 UTC

[GitHub] [incubator-tvm] altanh opened a new pull request #6851: [RELAY][OP] Support MXNet-style attributes for reshape_like

altanh opened a new pull request #6851:
URL: https://github.com/apache/incubator-tvm/pull/6851


   This PR adds MXNet-style shape slicing attributes for `reshape_like`, to enable reshaping part of a shape (using part of another shape). In particular, this adds `lhs_begin, lhs_end, rhs_begin, rhs_end`.
   
   cc @kevinthesun @icemelon9 @junrushao1994 
   


----------------------------------------------------------------
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] [incubator-tvm] electriclilies commented on a change in pull request #6851: [RELAY][OP] Support MXNet-style attributes for reshape_like

Posted by GitBox <gi...@apache.org>.
electriclilies commented on a change in pull request #6851:
URL: https://github.com/apache/incubator-tvm/pull/6851#discussion_r518231059



##########
File path: src/relay/op/tensor/transform.cc
##########
@@ -641,11 +642,45 @@ bool ReshapeRel(const Array<Type>& types, int num_inputs, const Attrs& attrs,
   return true;
 }
 
+Array<PrimExpr> infer_reshape_like(const Array<PrimExpr>& lhs_shape,
+                                   const Array<PrimExpr>& rhs_shape, const Attrs& attrs) {
+  const auto* like_attrs = attrs.as<ReshapeLikeAttrs>();
+  CHECK(!like_attrs->lhs_end.defined() || like_attrs->lhs_end.as<IntImmNode>())

Review comment:
       Can you add some line breaks in this function? It is a bit difficult to read.




----------------------------------------------------------------
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] [incubator-tvm] altanh commented on a change in pull request #6851: [RELAY][OP] Support MXNet-style attributes for reshape_like

Posted by GitBox <gi...@apache.org>.
altanh commented on a change in pull request #6851:
URL: https://github.com/apache/incubator-tvm/pull/6851#discussion_r518289388



##########
File path: tests/python/relay/test_op_level3.py
##########
@@ -316,17 +316,36 @@ def test_reshape_like_infer_type():
     zz = run_infer_type(z)
     assert zz.checked_type == relay.TensorType((1, 8, 8), "float32")
 
+    # partial reshaping
+    x = relay.var("x", relay.TensorType((1, 2, 3, 4), "float32"))
+    y = relay.var("y", relay.TensorType((1, 6, 5), "float32"))
+    z = relay.reshape_like(x, y, lhs_begin=1, lhs_end=3, rhs_begin=1, rhs_end=2)
+    zz = run_infer_type(z)
+    assert zz.checked_type == relay.TensorType((1, 6, 4), "float32")
+
+    # symbolic partial reshaping
+    n, c, h, w = te.size_var("n"), 2, 3, te.size_var("w")
+    x = relay.var("x", relay.TensorType((n, c, h, w), "float32"))
+    y = relay.var("y", relay.TensorType((5, 6), "float32"))
+    z = relay.var("z", relay.TensorType((4,), "float32"))
+    w = relay.reshape_like(x, y, lhs_end=3)
+    w = relay.reshape_like(w, z, lhs_begin=2)

Review comment:
       done




----------------------------------------------------------------
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] [incubator-tvm] junrushao1994 merged pull request #6851: [RELAY][OP] Support MXNet-style attributes for reshape_like

Posted by GitBox <gi...@apache.org>.
junrushao1994 merged pull request #6851:
URL: https://github.com/apache/incubator-tvm/pull/6851


   


----------------------------------------------------------------
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] [incubator-tvm] tkonolige commented on a change in pull request #6851: [RELAY][OP] Support MXNet-style attributes for reshape_like

Posted by GitBox <gi...@apache.org>.
tkonolige commented on a change in pull request #6851:
URL: https://github.com/apache/incubator-tvm/pull/6851#discussion_r518431122



##########
File path: python/tvm/relay/op/transform.py
##########
@@ -308,28 +308,45 @@ def scatter_add(data, indices, updates, axis):
     return _make.scatter_add(data, indices, updates, axis)
 
 
-def reshape_like(data, shape_like):
-    """Reshapes the input array by the size of another array.
-    For an input array with shape ``(d1, d2, ..., dk)``, `reshape_like` operation reshapes
-    the input array into an output array with the same shape as the second input array.
+def reshape_like(data, shape_like, lhs_begin=0, lhs_end=None, rhs_begin=0, rhs_end=None):
+    """Reshapes the input tensor by the size of another tensor.

Review comment:
       Would it be possible to add an example to 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.

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



[GitHub] [incubator-tvm] altanh commented on a change in pull request #6851: [RELAY][OP] Support MXNet-style attributes for reshape_like

Posted by GitBox <gi...@apache.org>.
altanh commented on a change in pull request #6851:
URL: https://github.com/apache/incubator-tvm/pull/6851#discussion_r518257417



##########
File path: src/relay/op/make_op.h
##########
@@ -62,6 +62,9 @@ Expr MakeRepeat(Expr data, int repeats, int axis);
 
 Expr MakeReshape(Expr data, Array<Integer> newshape);
 
+Expr MakeReshapeLike(Expr lhs, Expr rhs, int64_t lhs_begin, Integer lhs_end, int64_t rhs_begin,

Review comment:
       I did this because the beginning index (in both cases) must always be an integer, but the end index can be `None` which means I must use a nullable `Integer` wrapper. I could make everything `Integer` and check that beginning is always defined. I did feel a bit weird using `int64_t` directly since everything else seem to use `int` but the value wrapped by `Integer` is `int64_t` so that's why I chose 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] [incubator-tvm] altanh commented on a change in pull request #6851: [RELAY][OP] Support MXNet-style attributes for reshape_like

Posted by GitBox <gi...@apache.org>.
altanh commented on a change in pull request #6851:
URL: https://github.com/apache/incubator-tvm/pull/6851#discussion_r518445194



##########
File path: python/tvm/relay/op/transform.py
##########
@@ -308,28 +308,45 @@ def scatter_add(data, indices, updates, axis):
     return _make.scatter_add(data, indices, updates, axis)
 
 
-def reshape_like(data, shape_like):
-    """Reshapes the input array by the size of another array.
-    For an input array with shape ``(d1, d2, ..., dk)``, `reshape_like` operation reshapes
-    the input array into an output array with the same shape as the second input array.
+def reshape_like(data, shape_like, lhs_begin=0, lhs_end=None, rhs_begin=0, rhs_end=None):
+    """Reshapes the input tensor by the size of another tensor.

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.

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



[GitHub] [incubator-tvm] giuseros commented on a change in pull request #6851: [RELAY][OP] Support MXNet-style attributes for reshape_like

Posted by GitBox <gi...@apache.org>.
giuseros commented on a change in pull request #6851:
URL: https://github.com/apache/incubator-tvm/pull/6851#discussion_r517953448



##########
File path: python/tvm/relay/op/transform.py
##########
@@ -308,7 +308,7 @@ def scatter_add(data, indices, updates, axis):
     return _make.scatter_add(data, indices, updates, axis)
 
 
-def reshape_like(data, shape_like):
+def reshape_like(data, shape_like, lhs_begin=0, lhs_end=None, rhs_begin=0, rhs_end=None):

Review comment:
       Could you add the additional parameters (lhs_begin, lhs_end, rhs_begin, rhs_end) in the docstring description?

##########
File path: src/relay/op/make_op.h
##########
@@ -62,6 +62,9 @@ Expr MakeRepeat(Expr data, int repeats, int axis);
 
 Expr MakeReshape(Expr data, Array<Integer> newshape);
 
+Expr MakeReshapeLike(Expr lhs, Expr rhs, int64_t lhs_begin, Integer lhs_end, int64_t rhs_begin,

Review comment:
       Why {lhs,rhs}_begin is int64_t and {lhs,rhs}_end is Integer?

##########
File path: tests/python/relay/test_op_level3.py
##########
@@ -316,17 +316,36 @@ def test_reshape_like_infer_type():
     zz = run_infer_type(z)
     assert zz.checked_type == relay.TensorType((1, 8, 8), "float32")
 
+    # partial reshaping
+    x = relay.var("x", relay.TensorType((1, 2, 3, 4), "float32"))
+    y = relay.var("y", relay.TensorType((1, 6, 5), "float32"))
+    z = relay.reshape_like(x, y, lhs_begin=1, lhs_end=3, rhs_begin=1, rhs_end=2)
+    zz = run_infer_type(z)
+    assert zz.checked_type == relay.TensorType((1, 6, 4), "float32")
+
+    # symbolic partial reshaping
+    n, c, h, w = te.size_var("n"), 2, 3, te.size_var("w")
+    x = relay.var("x", relay.TensorType((n, c, h, w), "float32"))
+    y = relay.var("y", relay.TensorType((5, 6), "float32"))
+    z = relay.var("z", relay.TensorType((4,), "float32"))
+    w = relay.reshape_like(x, y, lhs_end=3)
+    w = relay.reshape_like(w, z, lhs_begin=2)

Review comment:
       Could you also add a test with only rhs_end/rhs_begin?




----------------------------------------------------------------
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] [incubator-tvm] junrushao1994 commented on pull request #6851: [RELAY][OP] Support MXNet-style attributes for reshape_like

Posted by GitBox <gi...@apache.org>.
junrushao1994 commented on pull request #6851:
URL: https://github.com/apache/incubator-tvm/pull/6851#issuecomment-723258939


   Thanks @altanh @tkonolige @electriclilies @jroesch @giuseros! It is now merged :-)


----------------------------------------------------------------
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] [incubator-tvm] altanh commented on a change in pull request #6851: [RELAY][OP] Support MXNet-style attributes for reshape_like

Posted by GitBox <gi...@apache.org>.
altanh commented on a change in pull request #6851:
URL: https://github.com/apache/incubator-tvm/pull/6851#discussion_r518289598



##########
File path: src/relay/op/tensor/transform.cc
##########
@@ -641,11 +642,45 @@ bool ReshapeRel(const Array<Type>& types, int num_inputs, const Attrs& attrs,
   return true;
 }
 
+Array<PrimExpr> infer_reshape_like(const Array<PrimExpr>& lhs_shape,
+                                   const Array<PrimExpr>& rhs_shape, const Attrs& attrs) {
+  const auto* like_attrs = attrs.as<ReshapeLikeAttrs>();
+  CHECK(!like_attrs->lhs_end.defined() || like_attrs->lhs_end.as<IntImmNode>())

Review comment:
       done




----------------------------------------------------------------
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] [incubator-tvm] altanh commented on a change in pull request #6851: [RELAY][OP] Support MXNet-style attributes for reshape_like

Posted by GitBox <gi...@apache.org>.
altanh commented on a change in pull request #6851:
URL: https://github.com/apache/incubator-tvm/pull/6851#discussion_r518260340



##########
File path: src/relay/op/make_op.h
##########
@@ -62,6 +62,9 @@ Expr MakeRepeat(Expr data, int repeats, int axis);
 
 Expr MakeReshape(Expr data, Array<Integer> newshape);
 
+Expr MakeReshapeLike(Expr lhs, Expr rhs, int64_t lhs_begin, Integer lhs_end, int64_t rhs_begin,

Review comment:
       I noticed that the Attrs I defined uses `int` and not `int64_t` so I'll probably just use `int` since other code mostly uses 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