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 2022/08/02 09:48:14 UTC

[GitHub] [incubator-mxnet] Kacper-Pietkun opened a new pull request, #21112: [BUGFIX] _npi_repeats with swap

Kacper-Pietkun opened a new pull request, #21112:
URL: https://github.com/apache/incubator-mxnet/pull/21112

   ## Description ##
   _npi_repeats gave correct outputs only when repetition happened on 0th axis. That's why swapaxes function was called before and after triggering _npi_repeats operator. swapaxes() was called from python side, thus when _npi_repeats was a node in a computational graph it resulted in wrong output (swapaxes wasn't called in that case).
   
   ## Solution ##
   Trigger SwapAxis operator directrly by _npi_repeats operator.
   
   ## Checklist ##
   ### Essentials ###
   - [x] PR's title starts with a category (e.g. [BUGFIX], [MODEL], [TUTORIAL], [FEATURE], [DOC], etc)
   - [x] Changes are complete (i.e. I finished coding on this PR)
   - [x] All changes have test coverage
   - [x] Code is well-documented
   
   ## Comments ##
   - Added check for repeats parameter - it throws ValueError when length of the list is not equal to the number of elements on the axis that is going to be repeated (numpy compatibility)
   


-- 
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@mxnet.apache.org

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


[GitHub] [incubator-mxnet] mxnet-bot commented on pull request #21112: [BUGFIX] _npi_repeats with swap

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

   Jenkins CI successfully triggered : [website, 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.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

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


[GitHub] [incubator-mxnet] Kacper-Pietkun commented on pull request #21112: [BUGFIX] _npi_repeats with swap

Posted by GitBox <gi...@apache.org>.
Kacper-Pietkun commented on PR #21112:
URL: https://github.com/apache/incubator-mxnet/pull/21112#issuecomment-1204837534

   @mxnet-bot run ci [centos-gpu, unix-gpu, website]


-- 
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@mxnet.apache.org

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


[GitHub] [incubator-mxnet] mxnet-bot commented on pull request #21112: [BUGFIX] _npi_repeats with swap

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

   Jenkins CI successfully triggered : [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.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

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


[GitHub] [incubator-mxnet] Kacper-Pietkun commented on pull request #21112: [BUGFIX] _npi_repeats with swap

Posted by GitBox <gi...@apache.org>.
Kacper-Pietkun commented on PR #21112:
URL: https://github.com/apache/incubator-mxnet/pull/21112#issuecomment-1204021528

   @mxnet-bot run ci [centos-gpu, unix-gpu, website]


-- 
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@mxnet.apache.org

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


[GitHub] [incubator-mxnet] mxnet-bot commented on pull request #21112: [BUGFIX] _npi_repeats with swap

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

   Jenkins CI successfully triggered : [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.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

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


[GitHub] [incubator-mxnet] bgawrych commented on a diff in pull request #21112: [BUGFIX] _npi_repeats with swap

Posted by GitBox <gi...@apache.org>.
bgawrych commented on code in PR #21112:
URL: https://github.com/apache/incubator-mxnet/pull/21112#discussion_r935664043


##########
src/operator/numpy/np_repeat_op-inl.h:
##########
@@ -219,15 +225,86 @@ void NumpyRepeatsOpForward(const nnvm::NodeAttrs& attrs,
       stride *= ishape[i];
     }
 
-    MSHADOW_TYPE_SWITCH(inputs[0].type_flag_, IType, {
-      MSHADOW_TYPE_SWITCH(outputs[0].type_flag_, OType, {
+    MSHADOW_TYPE_SWITCH_EXT_WITH_BOOL(inputs[0].type_flag_, IType, {
+      MSHADOW_TYPE_SWITCH_EXT_WITH_BOOL(outputs[0].type_flag_, OType, {
         mxnet_op::Kernel<repeat_axis_fwd, xpu>::Launch(
             s, out_data.Size(), out_data.dptr<OType>(), in_data.dptr<IType>(), ind, stride);
       });
     });
   }
 }
 
+template <typename xpu>
+void NumpyRepeatsOpForward(const nnvm::NodeAttrs& attrs,
+                           const OpContext& ctx,
+                           const std::vector<TBlob>& inputs,
+                           const std::vector<OpReqType>& req,
+                           const std::vector<TBlob>& outputs) {
+  using namespace mshadow;
+  const mxnet::TShape& ishape = inputs[0].shape_;
+  int repeats                 = 0;
+  int axis                    = -1;
+  dmlc::optional<int> axisOpt;
+  const RepeatsParam& param = nnvm::get<RepeatsParam>(attrs.parsed);
+  GetRepeatsParams(param, ishape, &repeats, &axisOpt, &axis);
+
+  if (!shape_is_known(ishape) || repeats == 0)
+    return;
+
+  mxnet::Tuple<int> repts = param.repeats.value();
+  if (repts.ndim() == 1) {
+    int len = static_cast<bool>(axisOpt) ? ishape[axis] : ishape.Size();
+    std::vector<int> temp(len, repeats);
+    repts = mxnet::Tuple<int>(temp);
+  }
+
+  // If axis was specified then perform swapaxis before and after calling repeat function
+  if (axisOpt.has_value() && axisOpt.value() != 0) {
+    int type_size          = mshadow_sizeof(inputs[0].type_flag_);
+    size_t total_temp_size = inputs[0].shape_.Size() * type_size +
+                             outputs[0].shape_.Size() * type_size + repts.ndim() * sizeof(int);
+    Tensor<xpu, 1, char> temp_space = ctx.requested[0].get_space_typed<xpu, 1, char>(
+        Shape1(total_temp_size), ctx.get_stream<xpu>());
+    void* swap_output_tmp_dptr   = temp_space.dptr_;
+    void* repeat_output_tmp_dptr = temp_space.dptr_ + inputs[0].shape_.Size() * type_size;
+    int* repeat_tmp_dptr =
+        reinterpret_cast<int*>(temp_space.dptr_ + inputs[0].shape_.Size() * type_size +

Review Comment:
   ```suggestion
           reinterpret_cast<int*>(repeat_output_tmp_dptr +
   ```



-- 
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@mxnet.apache.org

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


[GitHub] [incubator-mxnet] bgawrych merged pull request #21112: [BUGFIX] _npi_repeats with swap

Posted by GitBox <gi...@apache.org>.
bgawrych merged PR #21112:
URL: https://github.com/apache/incubator-mxnet/pull/21112


-- 
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@mxnet.apache.org

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


[GitHub] [incubator-mxnet] Kacper-Pietkun commented on pull request #21112: [BUGFIX] _npi_repeats with swap

Posted by GitBox <gi...@apache.org>.
Kacper-Pietkun commented on PR #21112:
URL: https://github.com/apache/incubator-mxnet/pull/21112#issuecomment-1203729874

   @mxnet-bot run ci [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.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

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


[GitHub] [incubator-mxnet] mxnet-bot commented on pull request #21112: [BUGFIX] _npi_repeats with swap

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

   Jenkins CI successfully triggered : [website]


-- 
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@mxnet.apache.org

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


[GitHub] [incubator-mxnet] Kacper-Pietkun commented on pull request #21112: [BUGFIX] _npi_repeats with swap

Posted by GitBox <gi...@apache.org>.
Kacper-Pietkun commented on PR #21112:
URL: https://github.com/apache/incubator-mxnet/pull/21112#issuecomment-1208987038

   @mxnet-bot run ci [website]


-- 
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@mxnet.apache.org

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


[GitHub] [incubator-mxnet] mxnet-bot commented on pull request #21112: [BUGFIX] _npi_repeats with swap

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

   Jenkins CI successfully triggered : [unix-gpu, centos-gpu, website]


-- 
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@mxnet.apache.org

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


[GitHub] [incubator-mxnet] mxnet-bot commented on pull request #21112: [BUGFIX] _npi_repeats with swap

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

   Jenkins CI successfully triggered : [unix-gpu, centos-gpu, website]


-- 
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@mxnet.apache.org

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


[GitHub] [incubator-mxnet] bartekkuncer commented on a diff in pull request #21112: [BUGFIX] _npi_repeats with swap

Posted by GitBox <gi...@apache.org>.
bartekkuncer commented on code in PR #21112:
URL: https://github.com/apache/incubator-mxnet/pull/21112#discussion_r937911565


##########
src/operator/numpy/np_repeat_op-inl.h:
##########
@@ -102,6 +103,14 @@ inline bool RepeatsOpShape(const nnvm::NodeAttrs& attrs,
     return true;
   }
 
+  mxnet::Tuple<int> repts = param.repeats.value();

Review Comment:
   Can you use more descriptive variable names? Without abbreviations if possible.



##########
src/operator/numpy/np_repeat_op-inl.h:
##########
@@ -153,26 +162,27 @@ struct repeat_axis_fwd {
 };
 
 template <typename xpu>
-void NumpyRepeatsOpForward(const nnvm::NodeAttrs& attrs,
-                           const OpContext& ctx,
-                           const std::vector<TBlob>& inputs,
-                           const std::vector<OpReqType>& req,
-                           const std::vector<TBlob>& outputs) {
+void NumpyRepeatsAxisZeroOpForward(const nnvm::NodeAttrs& attrs,

Review Comment:
   Please add brief description of this function.



##########
src/operator/numpy/np_repeat_op-inl.h:
##########
@@ -153,26 +162,27 @@ struct repeat_axis_fwd {
 };
 
 template <typename xpu>
-void NumpyRepeatsOpForward(const nnvm::NodeAttrs& attrs,
-                           const OpContext& ctx,
-                           const std::vector<TBlob>& inputs,
-                           const std::vector<OpReqType>& req,
-                           const std::vector<TBlob>& outputs) {
+void NumpyRepeatsAxisZeroOpForward(const nnvm::NodeAttrs& attrs,
+                                   const OpContext& ctx,
+                                   const std::vector<TBlob>& inputs,
+                                   const std::vector<OpReqType>& req,
+                                   const std::vector<TBlob>& outputs,
+                                   int* ind) {
   using namespace mshadow;
   const TBlob& iTBlob         = inputs[0];
   const mxnet::TShape& ishape = iTBlob.shape_;
-  if (!shape_is_known(ishape))
-    return;
-  Stream<xpu>* s = ctx.get_stream<xpu>();
-
-  int repeats = 0;
+  int repeats                 = 0;
   dmlc::optional<int> axisOpt;
-  int axis                  = -1;
+  // axis is always set to zero, because before calling this function target axis of the repeat
+  // function is swapped with 0th axis
+  int axis                  = 0;

Review Comment:
   constexpr



##########
src/operator/swapaxis-inl.h:
##########
@@ -156,7 +156,7 @@ void SwapAxisCompute(const nnvm::NodeAttrs& attrs,
                      const std::vector<OpReqType>& req,
                      const std::vector<TBlob>& out_data) {
   using namespace mshadow;
-  MSHADOW_TYPE_SWITCH(in_data[swapaxisenum::kData].type_flag_, DType, {
+  MSHADOW_TYPE_SWITCH_EXT_WITH_BOOL(in_data[swapaxisenum::kData].type_flag_, DType, {

Review Comment:
   Maybe it is good time to change swapaxisenum to just swapaxis as it is for other ops?



-- 
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@mxnet.apache.org

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


[GitHub] [incubator-mxnet] mxnet-bot commented on pull request #21112: [BUGFIX] _npi_repeats with swap

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

   Hey @Kacper-Pietkun , 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**: [centos-cpu, miscellaneous, windows-cpu, website, unix-cpu, centos-gpu, edge, sanity, windows-gpu, clang, unix-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.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

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


[GitHub] [incubator-mxnet] Kacper-Pietkun commented on pull request #21112: [BUGFIX] _npi_repeats with swap

Posted by GitBox <gi...@apache.org>.
Kacper-Pietkun commented on PR #21112:
URL: https://github.com/apache/incubator-mxnet/pull/21112#issuecomment-1203671065

   @mxnet-bot run ci [unix-gpu, website]


-- 
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@mxnet.apache.org

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


[GitHub] [incubator-mxnet] mxnet-bot commented on pull request #21112: [BUGFIX] _npi_repeats with swap

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

   Jenkins CI successfully triggered : [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.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

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


[GitHub] [incubator-mxnet] Kacper-Pietkun commented on pull request #21112: [BUGFIX] _npi_repeats with swap

Posted by GitBox <gi...@apache.org>.
Kacper-Pietkun commented on PR #21112:
URL: https://github.com/apache/incubator-mxnet/pull/21112#issuecomment-1203645903

   @mxnet-bot run ci [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.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

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


[GitHub] [incubator-mxnet] Kacper-Pietkun commented on pull request #21112: [BUGFIX] _npi_repeats with swap

Posted by GitBox <gi...@apache.org>.
Kacper-Pietkun commented on PR #21112:
URL: https://github.com/apache/incubator-mxnet/pull/21112#issuecomment-1205020416

   @mxnet-bot run ci [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.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

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