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/04/14 14:48:48 UTC

[GitHub] [incubator-mxnet] CassiniXu opened a new pull request #18053: [Numpy] New FFIs for Operator: pad, prod

CassiniXu opened a new pull request #18053: [Numpy] New FFIs for Operator: pad, prod
URL: https://github.com/apache/incubator-mxnet/pull/18053
 
 
   ## Description ##
   (Brief description on what this PR is about)
   
   ## 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 ##
   - If this change is a backward incompatible change, why must this change be made.
   - Interesting edge cases to note 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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] hzfan commented on a change in pull request #18053: [Numpy] New FFIs for Operator: pad, prod

Posted by GitBox <gi...@apache.org>.
hzfan commented on a change in pull request #18053: [Numpy] New FFIs for Operator: pad, prod
URL: https://github.com/apache/incubator-mxnet/pull/18053#discussion_r409992467
 
 

 ##########
 File path: src/operator/numpy/np_pad_op-inl.h
 ##########
 @@ -122,6 +143,18 @@ struct NumpyPadParam : public dmlc::Parameter<NumpyPadParam> {
                   "the extended part of the array is created by subtracting the "
                   "reflected values from two times the edge value.");
   }
+  // Added SetAttrDict function here
+  void SetAttrDict(std::unordered_map<std::string, std::string>* dict) {
+    std::ostringstream pad_width_s, mode_s, constant_values_s, reflect_type_s;
+    pad_width_s << pad_width;
+    // mode_s << mode;
 
 Review comment:
   Remove dead 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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] CassiniXu commented on issue #18053: [Numpy] New FFIs for Operator: pad, prod

Posted by GitBox <gi...@apache.org>.
CassiniXu commented on issue #18053: [Numpy] New FFIs for Operator: pad, prod
URL: https://github.com/apache/incubator-mxnet/pull/18053#issuecomment-614407240
 
 
   @mxnet-bot run ci [unix-cpu, unix-gpu, windows-gpu, centos-gpu]

----------------------------------------------------------------
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] mxnet-bot commented on issue #18053: [Numpy] New FFIs for Operator: pad, prod

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #18053: [Numpy] New FFIs for Operator: pad, prod
URL: https://github.com/apache/incubator-mxnet/pull/18053#issuecomment-613487610
 
 
   Hey @CassiniXu , Thanks for submitting the PR 
   All tests are already queued to run once. If tests fail, you can trigger one or more tests again with the following commands: 
   - To trigger all jobs: @mxnet-bot run ci [all] 
   - To trigger specific jobs: @mxnet-bot run ci [job1, job2] 
   *** 
   **CI supported jobs**: [sanity, unix-cpu, windows-cpu, miscellaneous, unix-gpu, clang, edge, windows-gpu, centos-cpu, website, centos-gpu]
   *** 
   _Note_: 
    Only following 3 categories can trigger CI :PR Author, MXNet Committer, Jenkins Admin. 
   All CI tests must pass before the PR can be 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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] mxnet-bot commented on issue #18053: [Numpy] New FFIs for Operator: pad, prod

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #18053: [Numpy] New FFIs for Operator: pad, prod
URL: https://github.com/apache/incubator-mxnet/pull/18053#issuecomment-614407283
 
 
   Jenkins CI successfully triggered : [unix-gpu, windows-gpu, centos-gpu, unix-cpu]

----------------------------------------------------------------
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] hzfan commented on a change in pull request #18053: [Numpy] New FFIs for Operator: pad, prod

Posted by GitBox <gi...@apache.org>.
hzfan commented on a change in pull request #18053: [Numpy] New FFIs for Operator: pad, prod
URL: https://github.com/apache/incubator-mxnet/pull/18053#discussion_r409992007
 
 

 ##########
 File path: src/api/operator/numpy/np_pad_op.cc
 ##########
 @@ -0,0 +1,85 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * \file np_pad_op.cc
+ * \brief Implementation of the API of functions in src/operator/numpy/np_pad_op.cc
+ */
+#include <dmlc/optional.h>
+#include <mxnet/api_registry.h>
+#include <mxnet/runtime/packed_func.h>
+#include "../utils.h"
+#include "../../../operator/numpy/np_pad_op-inl.h"
+
+namespace mxnet {
+
+inline int String2MXNetPadType(const std::string& s) {
+  using namespace op;
+  if (s == "constant") {
+    return pad_enum::kConstant;
+  } else if (s == "edge") {
+    return pad_enum::kEdge;
+  } else if (s == "reflect") {
+    return pad_enum::kReflect;
+  } else if (s == "symmetric") {
+    return pad_enum::kSymmetric;
+  } else if (s == "maximum") {
+    return pad_enum::kMaximum;
+  } else if (s == "minimum") {
+    return pad_enum::kMinimum;
+  } else {
+    LOG(FATAL) << "unknown type " << s;
+  }
+  LOG(FATAL) << "should not reach here ";
+  return 0;
+}
+
+MXNET_REGISTER_API("_npi.pad")
+.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) {
+  using namespace runtime;
+  const nnvm::Op* op = Op::Get("_npi_pad");
+  nnvm::NodeAttrs attrs;
+  op::NumpyPadParam param;
+  ADT adt = Downcast<ADT, ObjectRef>(args[1].operator ObjectRef());
+  int ndim = adt.size();
+  std::vector<mxnet::Tuple<int>> temp;
+  int counter = 0;
+  for (counter = 0; counter < ndim; counter++) {
+    temp.emplace_back(mxnet::Tuple<int>(adt[counter]));
+  }
+  param.pad_width = Tuple<Tuple<int>>(temp.begin(), temp.end());
+  param.mode = String2MXNetPadType(args[2].operator std::string());
+  if (args[3].type_code() != kNull) {
+    param.constant_values = args[3].operator double();
+  }
+  if (args[4].type_code() != kNull) {
+    param.reflect_type = args[4].operator std::string();
+  }
+  attrs.op = op;
+  attrs.parsed = std::move(param);
+  SetAttrDict<op::NumpyPadParam>(&attrs);
+  int num_inputs = 1;
+  int num_outputs = 1;
 
 Review comment:
   `num_outputs` should be 0. It is the number of outputs provided by the user, not the number of outputs yielded by the op.

----------------------------------------------------------------
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 issue #18053: [Numpy] New FFIs for Operator: pad, prod

Posted by GitBox <gi...@apache.org>.
haojin2 commented on issue #18053: [Numpy] New FFIs for Operator: pad, prod
URL: https://github.com/apache/incubator-mxnet/pull/18053#issuecomment-613611193
 
 
   @hzfan 

----------------------------------------------------------------
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] hzfan commented on a change in pull request #18053: [Numpy] New FFIs for Operator: pad, prod

Posted by GitBox <gi...@apache.org>.
hzfan commented on a change in pull request #18053: [Numpy] New FFIs for Operator: pad, prod
URL: https://github.com/apache/incubator-mxnet/pull/18053#discussion_r409988276
 
 

 ##########
 File path: python/mxnet/numpy/multiarray.py
 ##########
 @@ -10363,7 +10364,154 @@ def pad(x, pad_width=None, mode="constant", **kwargs): # pylint: disable=too-man
            [10, 10, 10, 10, 10, 10, 10],
            [10, 10, 10, 10, 10, 10, 10]])
     """
-    return _mx_nd_np.pad(x, pad_width, mode, **kwargs)
+    if not _np.asarray(pad_width).dtype.kind == 'i':
 
 Review comment:
   Seems that we have checks in `_mx_nd_np.pad`? Why not simply invoke 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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] mxnet-bot commented on pull request #18053: [Numpy] New FFIs for Operator: pad, prod

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on pull request #18053:
URL: https://github.com/apache/incubator-mxnet/pull/18053#issuecomment-619564592


   Jenkins CI successfully triggered : [windows-gpu]


----------------------------------------------------------------
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-mxnet] hzfan commented on a change in pull request #18053: [Numpy] New FFIs for Operator: pad, prod

Posted by GitBox <gi...@apache.org>.
hzfan commented on a change in pull request #18053: [Numpy] New FFIs for Operator: pad, prod
URL: https://github.com/apache/incubator-mxnet/pull/18053#discussion_r409993623
 
 

 ##########
 File path: src/api/operator/numpy/np_broadcast_reduce_op_value.cc
 ##########
 @@ -89,4 +89,50 @@ MXNET_REGISTER_API("_npi.mean")
   }
 });
 
+MXNET_REGISTER_API("_npi.prod")
+.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) {
+  using namespace runtime;
+  const nnvm::Op* op = Op::Get("_npi_prod");
+  nnvm::NodeAttrs attrs;
+  op::NumpyReduceAxesParam param;
+  if (args[1].type_code() == kNull) {
+    param.axis = dmlc::optional<mxnet::Tuple<int>>();
+  } else if (args[1].type_code() == kDLInt) {
+    param.axis = Tuple<int>(1, args[1].operator int64_t());
+  } else {
+    param.axis = Tuple<int>(args[1].operator ObjectRef());
+  }
+  if (args[2].type_code() == kNull) {
+    param.dtype = dmlc::optional<int>();
+  } else {
+    param.dtype = String2MXNetTypeWithBool(args[2].operator std::string());
+  }
+  if (args[3].type_code() == kNull) {
+    param.keepdims = false;
+  } else {
+    param.keepdims = args[3].operator bool();
+  }
+  if (args[4].type_code() == kNull) {
+    param.initial = dmlc::optional<double>();
+  } else {
+    param.initial = args[4].operator double();
+  }
+  attrs.op = op;
+  attrs.parsed = std::move(param);
+  SetAttrDict<op::NumpyReduceAxesParam>(&attrs);
+  // inputs
+  NDArray* inputs[] = {args[0].operator mxnet::NDArray*()};
+  int num_inputs = 1;
+  // outputs
+  NDArray* out = args[5].operator mxnet::NDArray*();
+  NDArray** outputs = out == nullptr ? nullptr : &out;
+  int num_outputs = out != nullptr;
+  auto ndoutputs = Invoke(op, &attrs, num_inputs, inputs, &num_outputs, outputs);
+  if (out) {
+    *ret = PythonArg(3);
 
 Review comment:
   `PythonArg(5)`. Here we specify the argument in `_api_intenral.prod` instead of `_op.prod`

----------------------------------------------------------------
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] CassiniXu commented on pull request #18053: [Numpy] New FFIs for Operator: pad, prod

Posted by GitBox <gi...@apache.org>.
CassiniXu commented on pull request #18053:
URL: https://github.com/apache/incubator-mxnet/pull/18053#issuecomment-619724370


   @hzfan 


----------------------------------------------------------------
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-mxnet] mxnet-bot commented on pull request #18053: [Numpy] New FFIs for Operator: pad, prod

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on pull request #18053:
URL: https://github.com/apache/incubator-mxnet/pull/18053#issuecomment-620977921


   Jenkins CI successfully triggered : [sanity]


----------------------------------------------------------------
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-mxnet] mxnet-bot commented on issue #18053: [Numpy] New FFIs for Operator: pad, prod

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #18053:
URL: https://github.com/apache/incubator-mxnet/pull/18053#issuecomment-618433511


   Jenkins CI successfully triggered : [unix-gpu, windows-gpu, unix-cpu]


----------------------------------------------------------------
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-mxnet] CassiniXu commented on pull request #18053: [Numpy] New FFIs for Operator: pad, prod

Posted by GitBox <gi...@apache.org>.
CassiniXu commented on pull request #18053:
URL: https://github.com/apache/incubator-mxnet/pull/18053#issuecomment-618768586


   @mxnet-bot run ci [unix-gpu]


----------------------------------------------------------------
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-mxnet] CassiniXu commented on pull request #18053: [Numpy] New FFIs for Operator: pad, prod

Posted by GitBox <gi...@apache.org>.
CassiniXu commented on pull request #18053:
URL: https://github.com/apache/incubator-mxnet/pull/18053#issuecomment-619731511


   @yzhliu 


----------------------------------------------------------------
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-mxnet] CassiniXu commented on pull request #18053: [Numpy] New FFIs for Operator: pad, prod

Posted by GitBox <gi...@apache.org>.
CassiniXu commented on pull request #18053:
URL: https://github.com/apache/incubator-mxnet/pull/18053#issuecomment-619486110


   @hzfan 


----------------------------------------------------------------
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-mxnet] CassiniXu commented on pull request #18053: [Numpy] New FFIs for Operator: pad, prod

Posted by GitBox <gi...@apache.org>.
CassiniXu commented on pull request #18053:
URL: https://github.com/apache/incubator-mxnet/pull/18053#issuecomment-619564575


   @mxnet-bot run ci [windows-gpu]


----------------------------------------------------------------
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-mxnet] mxnet-bot commented on pull request #18053: [Numpy] New FFIs for Operator: pad, prod

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on pull request #18053:
URL: https://github.com/apache/incubator-mxnet/pull/18053#issuecomment-618768645


   Jenkins CI successfully triggered : [unix-gpu]


----------------------------------------------------------------
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-mxnet] CassiniXu commented on pull request #18053: [Numpy] New FFIs for Operator: pad, prod

Posted by GitBox <gi...@apache.org>.
CassiniXu commented on pull request #18053:
URL: https://github.com/apache/incubator-mxnet/pull/18053#issuecomment-620977909


   @mxnet-bot run ci [sanity]


----------------------------------------------------------------
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-mxnet] CassiniXu commented on pull request #18053: [Numpy] New FFIs for Operator: pad, prod

Posted by GitBox <gi...@apache.org>.
CassiniXu commented on pull request #18053:
URL: https://github.com/apache/incubator-mxnet/pull/18053#issuecomment-619033640


   @hzfan


----------------------------------------------------------------
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-mxnet] CassiniXu commented on issue #18053: [Numpy] New FFIs for Operator: pad, prod

Posted by GitBox <gi...@apache.org>.
CassiniXu commented on issue #18053:
URL: https://github.com/apache/incubator-mxnet/pull/18053#issuecomment-618433403


   @mxnet-bot run ci [unix-cpu, unix-gpu, windows-gpu]


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