From e3a2adebf1f0c981055cbf015e7040b3c4d39286 Mon Sep 17 00:00:00 2001 From: kshitij12345 Date: Mon, 12 Aug 2019 22:30:04 +0530 Subject: [PATCH 01/10] support nullop transpose --- src/operator/tensor/matrix_op-inl.h | 3 +++ src/operator/tensor/matrix_op.cc | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/operator/tensor/matrix_op-inl.h b/src/operator/tensor/matrix_op-inl.h index cd98cb020c6b..984f4077e818 100644 --- a/src/operator/tensor/matrix_op-inl.h +++ b/src/operator/tensor/matrix_op-inl.h @@ -324,6 +324,9 @@ void Transpose(const nnvm::NodeAttrs& attrs, const std::vector& inputs, const std::vector& req, const std::vector& outputs) { + if (req[0] == kNullOp) { + return; + } const TransposeParam& param = nnvm::get(attrs.parsed); CHECK_EQ(req[0], kWriteTo) << "Transpose does not support inplace"; if (param.axes.ndim() == 0) { diff --git a/src/operator/tensor/matrix_op.cc b/src/operator/tensor/matrix_op.cc index e78050aec009..3c4b6f3f3e51 100644 --- a/src/operator/tensor/matrix_op.cc +++ b/src/operator/tensor/matrix_op.cc @@ -321,6 +321,9 @@ static void TransposeComputeExCPU(const nnvm::NodeAttrs& attrs, const std::vector& inputs, const std::vector& req, const std::vector& outputs) { + if (req[0] == kNullOp) { + return; + } const TransposeParam& param = nnvm::get(attrs.parsed); CHECK_EQ(req[0], kWriteTo) << "Transpose does not support inplace"; CHECK_EQ(inputs.size(), 1U); From 2328ad88a34ecd6542f98a95be7657aafb389ad2 Mon Sep 17 00:00:00 2001 From: kshitij12345 Date: Mon, 12 Aug 2019 22:31:45 +0530 Subject: [PATCH 02/10] add relevant test --- tests/python/unittest/test_symbol.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/python/unittest/test_symbol.py b/tests/python/unittest/test_symbol.py index 963b32493b44..59c574c1bc6c 100644 --- a/tests/python/unittest/test_symbol.py +++ b/tests/python/unittest/test_symbol.py @@ -389,6 +389,22 @@ def test_children_same_name(): for c in b.get_children(): pass + +def test_transpose_nullop(): + for dim in range(1, 7): + a = mx.sym.Variable('a') + b = mx.sym.transpose(a, axes=tuple(np.random.permutation(dim))) + c = mx.sym.zeros_like(b) + + shape = rand_shape_nd(dim) + nd_a = mx.nd.random.normal(shape=shape) + c_out = c.eval(ctx=mx.cpu(), a=nd_a) + b_out = b.eval(ctx=mx.cpu(), a=nd_a) + + assert mx.test_utils.same(c_out[0].asnumpy(), + np.zeros_like(b_out[0].asnumpy())) + + if __name__ == '__main__': import nose nose.runmodule() From 68dfdc46bce63c13eea15e8c03d0da03d57cf168 Mon Sep 17 00:00:00 2001 From: kshitij12345 Date: Tue, 13 Aug 2019 09:05:53 +0530 Subject: [PATCH 03/10] retrigger CI From 04bf42c6f3608d7256f242a51ccb996fb4da8d41 Mon Sep 17 00:00:00 2001 From: kshitij12345 Date: Tue, 13 Aug 2019 19:07:11 +0530 Subject: [PATCH 04/10] update error message --- src/operator/tensor/matrix_op-inl.h | 2 +- src/operator/tensor/matrix_op.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/operator/tensor/matrix_op-inl.h b/src/operator/tensor/matrix_op-inl.h index 984f4077e818..39f7fabbb0ae 100644 --- a/src/operator/tensor/matrix_op-inl.h +++ b/src/operator/tensor/matrix_op-inl.h @@ -328,7 +328,7 @@ void Transpose(const nnvm::NodeAttrs& attrs, return; } const TransposeParam& param = nnvm::get(attrs.parsed); - CHECK_EQ(req[0], kWriteTo) << "Transpose does not support inplace"; + CHECK_EQ(req[0], kWriteTo) << "Transpose does not support kWriteInplace and kAddTo"; if (param.axes.ndim() == 0) { mxnet::TShape axes(inputs[0].ndim(), -1); for (int i = 0; i < axes.ndim(); ++i) { diff --git a/src/operator/tensor/matrix_op.cc b/src/operator/tensor/matrix_op.cc index 3c4b6f3f3e51..75ba20b15f98 100644 --- a/src/operator/tensor/matrix_op.cc +++ b/src/operator/tensor/matrix_op.cc @@ -325,7 +325,7 @@ static void TransposeComputeExCPU(const nnvm::NodeAttrs& attrs, return; } const TransposeParam& param = nnvm::get(attrs.parsed); - CHECK_EQ(req[0], kWriteTo) << "Transpose does not support inplace"; + CHECK_EQ(req[0], kWriteTo) << "Transpose does not support kWriteInplace and kAddTo"; CHECK_EQ(inputs.size(), 1U); CHECK_EQ(outputs.size(), 1U); From 115397da89e5f319524c9931ea801ae304470675 Mon Sep 17 00:00:00 2001 From: kshitij12345 Date: Tue, 20 Aug 2019 23:05:13 +0530 Subject: [PATCH 05/10] retrigger CI From a83ea2598902d6eb5e580b02c7d6e1981b215aef Mon Sep 17 00:00:00 2001 From: kshitij12345 Date: Wed, 21 Aug 2019 22:21:35 +0530 Subject: [PATCH 06/10] retrigger CI From 7878d157a98bb3d346a93f9da982c83f386190c1 Mon Sep 17 00:00:00 2001 From: kshitij12345 Date: Tue, 27 Aug 2019 08:09:11 +0530 Subject: [PATCH 07/10] retrigger CI From 38d1afcf0aaac51e88298952695873a162e610db Mon Sep 17 00:00:00 2001 From: kshitij12345 Date: Wed, 28 Aug 2019 21:56:35 +0530 Subject: [PATCH 08/10] retrigger CI From 7f94226346109370ad6b909b8b2ded8527861a64 Mon Sep 17 00:00:00 2001 From: kshitij12345 Date: Thu, 29 Aug 2019 08:37:37 +0530 Subject: [PATCH 09/10] retrigger CI From e661e6721ea20a767071f1b16a58591d28fb79c9 Mon Sep 17 00:00:00 2001 From: kshitij12345 Date: Fri, 30 Aug 2019 21:36:40 +0530 Subject: [PATCH 10/10] retrigger CI