You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2020/01/17 07:21:22 UTC

[GitHub] [incubator-mxnet] haojin2 opened a new pull request #17358: np.broadcast_to extension

haojin2 opened a new pull request #17358: np.broadcast_to extension
URL: https://github.com/apache/incubator-mxnet/pull/17358
 
 
   ## Description ##
   Extending `broadcast_to` to infer shape from input tensor, useful under symbolic mode.
   
   ## Checklist ##
   ### Essentials ###
   Please feel free to remove inapplicable items for your PR.
   - [ ] The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant [JIRA issue](https://issues.apache.org/jira/projects/MXNET/issues) created (except PRs with tiny changes)
   - [ ] Changes are complete (i.e. I finished coding on this PR)
   - [ ] All changes have test coverage:
   - Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
   - Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
   - Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
   - [ ] Code is well-documented: 
   - For user-facing API changes, API doc string has been updated. 
   - For new C++ functions in header files, their functionalities and arguments are documented. 
   - For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
   - Check the API doc at https://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
   - [ ] To the best of my knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change
   
   ### Changes ###
   - [ ] Feature1, tests, (and when applicable, API doc)
   - [ ] Feature2, tests, (and when applicable, API doc)
   
   ## Comments ##
   FYI @szhengac @sxjscience @xidulu 

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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #17358: np.broadcast_to extension

Posted by GitBox <gi...@apache.org>.
haojin2 commented on a change in pull request #17358: np.broadcast_to extension
URL: https://github.com/apache/incubator-mxnet/pull/17358#discussion_r368143189
 
 

 ##########
 File path: src/operator/numpy/np_broadcast_reduce_op_value.cc
 ##########
 @@ -467,17 +467,21 @@ bool NumpyBroadcastToShape(const nnvm::NodeAttrs& attrs,
   mxnet::TShape& ishape = (*in_attrs)[0];
   if (!mxnet::shape_is_known(ishape)) return false;
   const BroadcastToParam& param = nnvm::get<BroadcastToParam>(attrs.parsed);
-  CHECK(mxnet::shape_is_known(param.shape))
-      << "the objective shape for broadcasting array must be known";
   CHECK_LE(ishape.ndim(), param.shape.ndim())
       << "shape " << ishape << " is not broadcastable to " << param.shape;
+  TShape pshape = param.shape;
   for (int i = param.shape.ndim() - 1; i >= 0; --i) {
     int j = i - param.shape.ndim() + ishape.ndim();
     if (j < 0) break;
-    CHECK(ishape[j] == param.shape[i] || ishape[j] == 1)
-        << "shape " << ishape << " is not broadcastable to " << param.shape;
+    if (pshape[i] == -2) {
+      pshape[i] = ishape[j];
+    }
+    CHECK(ishape[j] == pshape[i] || ishape[j] == 1)
+        << "shape " << ishape << " is not broadcastable to " << pshape;
   }
-  SHAPE_ASSIGN_CHECK(*out_attrs, 0, param.shape);
+  CHECK(mxnet::shape_is_known(pshape))
 
 Review comment:
   @szhengac Are you okay with changing the api to use -1 for copying a dim?

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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] haojin2 merged pull request #17358: np.broadcast_to extension

Posted by GitBox <gi...@apache.org>.
haojin2 merged pull request #17358: np.broadcast_to extension
URL: https://github.com/apache/incubator-mxnet/pull/17358
 
 
   

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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] szhengac commented on issue #17358: np.broadcast_to extension

Posted by GitBox <gi...@apache.org>.
szhengac commented on issue #17358: np.broadcast_to extension
URL: https://github.com/apache/incubator-mxnet/pull/17358#issuecomment-575507918
 
 
   Great!

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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] reminisce commented on a change in pull request #17358: np.broadcast_to extension

Posted by GitBox <gi...@apache.org>.
reminisce commented on a change in pull request #17358: np.broadcast_to extension
URL: https://github.com/apache/incubator-mxnet/pull/17358#discussion_r368206533
 
 

 ##########
 File path: src/operator/numpy/np_broadcast_reduce_op_value.cc
 ##########
 @@ -467,17 +467,21 @@ bool NumpyBroadcastToShape(const nnvm::NodeAttrs& attrs,
   mxnet::TShape& ishape = (*in_attrs)[0];
   if (!mxnet::shape_is_known(ishape)) return false;
   const BroadcastToParam& param = nnvm::get<BroadcastToParam>(attrs.parsed);
-  CHECK(mxnet::shape_is_known(param.shape))
-      << "the objective shape for broadcasting array must be known";
   CHECK_LE(ishape.ndim(), param.shape.ndim())
       << "shape " << ishape << " is not broadcastable to " << param.shape;
+  TShape pshape = param.shape;
   for (int i = param.shape.ndim() - 1; i >= 0; --i) {
     int j = i - param.shape.ndim() + ishape.ndim();
     if (j < 0) break;
-    CHECK(ishape[j] == param.shape[i] || ishape[j] == 1)
-        << "shape " << ishape << " is not broadcastable to " << param.shape;
+    if (pshape[i] == -2) {
+      pshape[i] = ishape[j];
+    }
+    CHECK(ishape[j] == pshape[i] || ishape[j] == 1)
+        << "shape " << ishape << " is not broadcastable to " << pshape;
   }
-  SHAPE_ASSIGN_CHECK(*out_attrs, 0, param.shape);
+  CHECK(mxnet::shape_is_known(pshape))
 
 Review comment:
   `-1` does not mean copying dim size in NumPy; it actually means deducing shape with the available information. The point is we should not `CHECK(mxnet::shape_is_known(pshape))` since it implies that the destination shape is unknown which is different from NumPy semantics.
   

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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] reminisce commented on a change in pull request #17358: np.broadcast_to extension

Posted by GitBox <gi...@apache.org>.
reminisce commented on a change in pull request #17358: np.broadcast_to extension
URL: https://github.com/apache/incubator-mxnet/pull/17358#discussion_r368206533
 
 

 ##########
 File path: src/operator/numpy/np_broadcast_reduce_op_value.cc
 ##########
 @@ -467,17 +467,21 @@ bool NumpyBroadcastToShape(const nnvm::NodeAttrs& attrs,
   mxnet::TShape& ishape = (*in_attrs)[0];
   if (!mxnet::shape_is_known(ishape)) return false;
   const BroadcastToParam& param = nnvm::get<BroadcastToParam>(attrs.parsed);
-  CHECK(mxnet::shape_is_known(param.shape))
-      << "the objective shape for broadcasting array must be known";
   CHECK_LE(ishape.ndim(), param.shape.ndim())
       << "shape " << ishape << " is not broadcastable to " << param.shape;
+  TShape pshape = param.shape;
   for (int i = param.shape.ndim() - 1; i >= 0; --i) {
     int j = i - param.shape.ndim() + ishape.ndim();
     if (j < 0) break;
-    CHECK(ishape[j] == param.shape[i] || ishape[j] == 1)
-        << "shape " << ishape << " is not broadcastable to " << param.shape;
+    if (pshape[i] == -2) {
+      pshape[i] = ishape[j];
+    }
+    CHECK(ishape[j] == pshape[i] || ishape[j] == 1)
+        << "shape " << ishape << " is not broadcastable to " << pshape;
   }
-  SHAPE_ASSIGN_CHECK(*out_attrs, 0, param.shape);
+  CHECK(mxnet::shape_is_known(pshape))
 
 Review comment:
   `-1` does not mean copying dim size in NumPy; it actually means deducing shape with the available information. The point is we should not `CHECK(mxnet::shape_is_known(pshape))` since it implies that the destination shape may be unknown which is different from NumPy semantics.
   

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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] reminisce commented on a change in pull request #17358: np.broadcast_to extension

Posted by GitBox <gi...@apache.org>.
reminisce commented on a change in pull request #17358: np.broadcast_to extension
URL: https://github.com/apache/incubator-mxnet/pull/17358#discussion_r367813005
 
 

 ##########
 File path: src/operator/numpy/np_broadcast_reduce_op_value.cc
 ##########
 @@ -467,17 +467,21 @@ bool NumpyBroadcastToShape(const nnvm::NodeAttrs& attrs,
   mxnet::TShape& ishape = (*in_attrs)[0];
   if (!mxnet::shape_is_known(ishape)) return false;
   const BroadcastToParam& param = nnvm::get<BroadcastToParam>(attrs.parsed);
-  CHECK(mxnet::shape_is_known(param.shape))
-      << "the objective shape for broadcasting array must be known";
   CHECK_LE(ishape.ndim(), param.shape.ndim())
       << "shape " << ishape << " is not broadcastable to " << param.shape;
+  TShape pshape = param.shape;
   for (int i = param.shape.ndim() - 1; i >= 0; --i) {
     int j = i - param.shape.ndim() + ishape.ndim();
     if (j < 0) break;
-    CHECK(ishape[j] == param.shape[i] || ishape[j] == 1)
-        << "shape " << ishape << " is not broadcastable to " << param.shape;
+    if (pshape[i] == -2) {
+      pshape[i] = ishape[j];
+    }
+    CHECK(ishape[j] == pshape[i] || ishape[j] == 1)
+        << "shape " << ishape << " is not broadcastable to " << pshape;
   }
-  SHAPE_ASSIGN_CHECK(*out_attrs, 0, param.shape);
+  CHECK(mxnet::shape_is_known(pshape))
 
 Review comment:
   I think `-1` is internally used as unknown dim size. It should be fine to use `-1` in  a destination shape set by users with similar meaning as in `npx.reshape`.

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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] szhengac commented on a change in pull request #17358: np.broadcast_to extension

Posted by GitBox <gi...@apache.org>.
szhengac commented on a change in pull request #17358: np.broadcast_to extension
URL: https://github.com/apache/incubator-mxnet/pull/17358#discussion_r368144410
 
 

 ##########
 File path: src/operator/numpy/np_broadcast_reduce_op_value.cc
 ##########
 @@ -467,17 +467,21 @@ bool NumpyBroadcastToShape(const nnvm::NodeAttrs& attrs,
   mxnet::TShape& ishape = (*in_attrs)[0];
   if (!mxnet::shape_is_known(ishape)) return false;
   const BroadcastToParam& param = nnvm::get<BroadcastToParam>(attrs.parsed);
-  CHECK(mxnet::shape_is_known(param.shape))
-      << "the objective shape for broadcasting array must be known";
   CHECK_LE(ishape.ndim(), param.shape.ndim())
       << "shape " << ishape << " is not broadcastable to " << param.shape;
+  TShape pshape = param.shape;
   for (int i = param.shape.ndim() - 1; i >= 0; --i) {
     int j = i - param.shape.ndim() + ishape.ndim();
     if (j < 0) break;
-    CHECK(ishape[j] == param.shape[i] || ishape[j] == 1)
-        << "shape " << ishape << " is not broadcastable to " << param.shape;
+    if (pshape[i] == -2) {
+      pshape[i] = ishape[j];
+    }
+    CHECK(ishape[j] == pshape[i] || ishape[j] == 1)
+        << "shape " << ishape << " is not broadcastable to " << pshape;
   }
-  SHAPE_ASSIGN_CHECK(*out_attrs, 0, param.shape);
+  CHECK(mxnet::shape_is_known(pshape))
 
 Review comment:
   `-1` is for shape inference, which is different from copy. So I do not think we should use `-1`.

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


With regards,
Apache Git Services