From 46f0433b749cf026899366d74b703033415d0f5e Mon Sep 17 00:00:00 2001 From: small1945 <2387491899@qq.com> Date: Mon, 4 Jul 2022 10:07:35 +0800 Subject: [PATCH 1/7] Modify some file and add test --- oneflow/user/ops/randperm_op.cpp | 4 +- oneflow/user/ops/reduce_like_ops.cpp | 21 ++++++-- oneflow/user/ops/relu_op.cpp | 6 ++- oneflow/user/ops/reshape_like_op.cpp | 8 +++- .../test/exceptions/test_randperm_op.py | 34 +++++++++++++ .../test/exceptions/test_reduce_like_ops.py | 48 +++++++++++++++++++ .../test/exceptions/test_reshape_like_op.py | 36 ++++++++++++++ 7 files changed, 148 insertions(+), 9 deletions(-) create mode 100644 python/oneflow/test/exceptions/test_randperm_op.py create mode 100644 python/oneflow/test/exceptions/test_reduce_like_ops.py create mode 100644 python/oneflow/test/exceptions/test_reshape_like_op.py diff --git a/oneflow/user/ops/randperm_op.cpp b/oneflow/user/ops/randperm_op.cpp index aa6103a2f0d..2b09adfbad5 100644 --- a/oneflow/user/ops/randperm_op.cpp +++ b/oneflow/user/ops/randperm_op.cpp @@ -29,7 +29,9 @@ namespace oneflow { /*static*/ Maybe RandpermOp::InferLogicalTensorDesc(user_op::InferContext* ctx) { Shape* out_shape = ctx->OutputShape("out", 0); int32_t n = ctx->Attr("n"); - CHECK_GE_OR_RETURN(n, 0); + CHECK_GE_OR_RETURN(n, 0) << Error::RuntimeError() + << "Expected the value of n greater than or equal to zero, " + << "but got " << n; *out_shape = Shape({n}); return Maybe::Ok(); } diff --git a/oneflow/user/ops/reduce_like_ops.cpp b/oneflow/user/ops/reduce_like_ops.cpp index 898e81ade46..960cd6191e0 100644 --- a/oneflow/user/ops/reduce_like_ops.cpp +++ b/oneflow/user/ops/reduce_like_ops.cpp @@ -28,10 +28,16 @@ namespace oneflow { const auto& reduced_axes = ctx->Attr>("axis"); ReduceSbpUtil::GetRegularAxes(num_axes, reduced_axes, &conf_axes); } + const auto& like_num_axes = ctx->LogicalTensorDesc4InputArgNameAndIndex("like", 0).shape().NumAxes(); const bool keep_dims = (num_axes == like_num_axes); - if (!keep_dims) { CHECK_EQ_OR_RETURN(conf_axes.size(), num_axes - like_num_axes); } + if (!keep_dims) { + CHECK_EQ_OR_RETURN(conf_axes.size(), num_axes - like_num_axes) + << Error::RuntimeError() + << "The size of axis list must be equal to the difference of the dimension " + << "between x tensor and like tensor"; + } auto IsReducedAxis = ReduceSbpUtil::MakePredicatorIsReducedAxis(conf_axes, num_axes); int64_t num_reduced_axes = 0; FOR_RANGE(int64_t, i, 0, num_axes) { @@ -67,7 +73,13 @@ namespace oneflow { const user_op::TensorDesc& x_tensor = ctx->InputTensorDesc("x", 0); const user_op::TensorDesc& like_tensor = ctx->InputTensorDesc("like", 0); const auto& axis = ctx->Attr>("axis"); - if (axis.empty()) { CHECK_EQ_OR_RETURN(x_tensor.shape(), like_tensor.shape()); } + if (axis.empty()) { + CHECK_EQ_OR_RETURN(x_tensor.shape(), like_tensor.shape()) + << Error::RuntimeError() + << "The shape of the x tensor must be consistent to the shape of the like tensor" + << " when input empty axis list "; + } + user_op::TensorDesc* y_tensor = ctx->OutputTensorDesc("y", 0); *y_tensor->mut_shape() = like_tensor.shape(); *y_tensor->mut_is_dynamic() = like_tensor.is_dynamic(); @@ -79,14 +91,15 @@ namespace oneflow { /*static*/ Maybe ReduceSumLikeOp::InferDataType(user_op::InferContext* ctx) { const user_op::TensorDesc& x_tensor = ctx->InputTensorDesc("x", 0); const user_op::TensorDesc& like_tensor = ctx->InputTensorDesc("like", 0); - CHECK_EQ_OR_RETURN(x_tensor.data_type(), like_tensor.data_type()); + CHECK_EQ_OR_RETURN(x_tensor.data_type(), like_tensor.data_type()) + << Error::TypeError() << "Tensors x and like must have the same type"; *ctx->OutputDType("y", 0) = like_tensor.data_type(); return Maybe::Ok(); } /*static*/ Maybe ReduceSumLikeOp::ModifyInputArg( const GetInputArgModifier& GetInputArgModifierFn, const user_op::UserOpConfWrapper&) { user_op::InputArgModifier* like_arg_modifier = GetInputArgModifierFn("like", 0); - CHECK_OR_RETURN(like_arg_modifier != nullptr); + CHECK_OR_RETURN(like_arg_modifier != nullptr); // NOLINT(maybe-need-error-msg) like_arg_modifier->set_requires_grad(false); return Maybe::Ok(); } diff --git a/oneflow/user/ops/relu_op.cpp b/oneflow/user/ops/relu_op.cpp index 52fb55fdc22..38e4f58328a 100644 --- a/oneflow/user/ops/relu_op.cpp +++ b/oneflow/user/ops/relu_op.cpp @@ -54,7 +54,8 @@ namespace oneflow { const Shape& y_shape = ctx->InputShape("y", 0); const Shape& dy_shape = ctx->InputShape("dy", 0); Shape* dx_shape = ctx->OutputShape("dx", 0); - CHECK_OR_RETURN(dy_shape == y_shape); + CHECK_OR_RETURN(dy_shape == y_shape) + << Error::RuntimeError() << "Tensors y and dy must have the same shape"; *dx_shape = dy_shape; return Maybe::Ok(); } @@ -63,7 +64,8 @@ namespace oneflow { } /*static*/ Maybe ReluGradOp::InferDataType(user_op::InferContext* ctx) { const DataType& data_type = ctx->InputDType("y", 0); - CHECK_EQ_OR_RETURN(ctx->InputDType("dy", 0), data_type); + CHECK_EQ_OR_RETURN(ctx->InputDType("dy", 0), data_type) + << Error::TypeError() << "Tensors dy and y must have the same type"; *ctx->OutputDType("dx", 0) = data_type; return Maybe::Ok(); } diff --git a/oneflow/user/ops/reshape_like_op.cpp b/oneflow/user/ops/reshape_like_op.cpp index 923e31899da..33efa9733dc 100644 --- a/oneflow/user/ops/reshape_like_op.cpp +++ b/oneflow/user/ops/reshape_like_op.cpp @@ -39,7 +39,11 @@ namespace oneflow { /*static*/ Maybe ReshapeLikeOp::InferLogicalTensorDesc(user_op::InferContext* ctx) { const Shape& in_shape = ctx->InputShape("in", 0); const Shape& like_shape = ctx->InputShape("like", 0); - CHECK_EQ_OR_RETURN(in_shape.elem_cnt(), like_shape.elem_cnt()); + CHECK_EQ_OR_RETURN(in_shape.elem_cnt(), like_shape.elem_cnt()) + << Error::RuntimeError() + << "The element number of in tensor must be equal to the element number of " + "like tensor, " + << "but got " << in_shape.elem_cnt() << " and " << like_shape.elem_cnt(); *ctx->OutputShape("out", 0) = like_shape; return Maybe::Ok(); } @@ -53,7 +57,7 @@ namespace oneflow { /*static*/ Maybe ReshapeLikeOp::ModifyInputArg( const GetInputArgModifier& GetInputArgModifierFn, const user_op::UserOpConfWrapper&) { user_op::InputArgModifier* like_modifier = GetInputArgModifierFn("like", 0); - CHECK_NOTNULL_OR_RETURN(like_modifier); + CHECK_NOTNULL_OR_RETURN(like_modifier); // NOLINT(maybe-need-error-msg) like_modifier->set_requires_grad(false); return Maybe::Ok(); } diff --git a/python/oneflow/test/exceptions/test_randperm_op.py b/python/oneflow/test/exceptions/test_randperm_op.py new file mode 100644 index 00000000000..66f379ea0ba --- /dev/null +++ b/python/oneflow/test/exceptions/test_randperm_op.py @@ -0,0 +1,34 @@ +""" +Copyright 2020 The OneFlow Authors. All rights reserved. + +Licensed 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. +""" + +import unittest + +import oneflow as flow +import oneflow.unittest + + +class TestRandpermOp(flow.unittest.TestCase): + def test_n_value_err_mes(test_case): + with test_case.assertRaises(RuntimeError) as ctx: + a = flow.randperm(-1) + test_case.assertTrue( + "Expected the value of n greater than or equal to zero" + in str(ctx.exception) + ) + + +if __name__ == "__main__": + unittest.main() diff --git a/python/oneflow/test/exceptions/test_reduce_like_ops.py b/python/oneflow/test/exceptions/test_reduce_like_ops.py new file mode 100644 index 00000000000..af1efd7f446 --- /dev/null +++ b/python/oneflow/test/exceptions/test_reduce_like_ops.py @@ -0,0 +1,48 @@ +""" +Copyright 2020 The OneFlow Authors. All rights reserved. + +Licensed 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. +""" + +import unittest + +import oneflow as flow +import oneflow.unittest + + +class TestReduceLikeOps(flow.unittest.TestCase): + def test_empty_axis_case_err(test_case): + a = flow.tensor([1, 1]) + b = flow.tensor([1, 1, 1]) + with test_case.assertRaises(RuntimeError) as ctx: + flow._C.reduce_sum_like(a, b, []) + test_case.assertTrue( + "The shape of the x tensor must be consistent to the shape of the like tensor" + in str(ctx.exception) + ) + + def test_tensor_type_err(test_case): + a = flow.tensor([1, 1], dtype=flow.int64) + b = flow.tensor([1, 1], dtype=flow.float64) + with test_case.assertRaises(TypeError) as ctx: + flow._C.reduce_sum_like(a, b, [1]) + test_case.assertTrue( + "Tensors x and like must have the same type" + in str(ctx.exception) + ) + + + + +if __name__ == "__main__": + unittest.main() diff --git a/python/oneflow/test/exceptions/test_reshape_like_op.py b/python/oneflow/test/exceptions/test_reshape_like_op.py new file mode 100644 index 00000000000..10aff7c88b5 --- /dev/null +++ b/python/oneflow/test/exceptions/test_reshape_like_op.py @@ -0,0 +1,36 @@ +""" +Copyright 2020 The OneFlow Authors. All rights reserved. + +Licensed 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. +""" + +import unittest + +import oneflow as flow +import oneflow.unittest + + +class TestReshapeLikeOp(flow.unittest.TestCase): + def test_element_number_match_err(test_case): + a = flow.tensor([1, 1]) + b = flow.tensor([[1, 1, 1], [1, 1, 1]]) + with test_case.assertRaises(RuntimeError) as ctx: + flow._C.reshape_like(a, b) + test_case.assertTrue( + "The element number of in tensor must be equal to the element number of like tensor" + in str(ctx.exception) + ) + + +if __name__ == "__main__": + unittest.main() From 673bce2de07f5b8a9bcd242cc929c53d54d49542 Mon Sep 17 00:00:00 2001 From: Zhimin Yang <76760002+small1945@users.noreply.github.com> Date: Mon, 4 Jul 2022 16:08:22 +0800 Subject: [PATCH 2/7] modify the content --- oneflow/user/ops/reduce_like_ops.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oneflow/user/ops/reduce_like_ops.cpp b/oneflow/user/ops/reduce_like_ops.cpp index 960cd6191e0..64d5db36a67 100644 --- a/oneflow/user/ops/reduce_like_ops.cpp +++ b/oneflow/user/ops/reduce_like_ops.cpp @@ -77,7 +77,7 @@ namespace oneflow { CHECK_EQ_OR_RETURN(x_tensor.shape(), like_tensor.shape()) << Error::RuntimeError() << "The shape of the x tensor must be consistent to the shape of the like tensor" - << " when input empty axis list "; + << " when the input axis list is empty"; } user_op::TensorDesc* y_tensor = ctx->OutputTensorDesc("y", 0); From 8e04da3f9e821737464e83db6377179fbcfbbac0 Mon Sep 17 00:00:00 2001 From: small1945 <2387491899@qq.com> Date: Mon, 4 Jul 2022 16:57:21 +0800 Subject: [PATCH 3/7] modify the format and test function name --- oneflow/user/ops/reduce_like_ops.cpp | 4 ++-- oneflow/user/ops/reshape_like_op.cpp | 2 +- python/oneflow/test/exceptions/test_randperm_op.py | 2 +- python/oneflow/test/exceptions/test_reduce_like_ops.py | 8 +++----- python/oneflow/test/exceptions/test_reshape_like_op.py | 5 +++-- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/oneflow/user/ops/reduce_like_ops.cpp b/oneflow/user/ops/reduce_like_ops.cpp index 960cd6191e0..d10ebb744db 100644 --- a/oneflow/user/ops/reduce_like_ops.cpp +++ b/oneflow/user/ops/reduce_like_ops.cpp @@ -77,7 +77,7 @@ namespace oneflow { CHECK_EQ_OR_RETURN(x_tensor.shape(), like_tensor.shape()) << Error::RuntimeError() << "The shape of the x tensor must be consistent to the shape of the like tensor" - << " when input empty axis list "; + << " when the input axis list is empty"; } user_op::TensorDesc* y_tensor = ctx->OutputTensorDesc("y", 0); @@ -92,7 +92,7 @@ namespace oneflow { const user_op::TensorDesc& x_tensor = ctx->InputTensorDesc("x", 0); const user_op::TensorDesc& like_tensor = ctx->InputTensorDesc("like", 0); CHECK_EQ_OR_RETURN(x_tensor.data_type(), like_tensor.data_type()) - << Error::TypeError() << "Tensors x and like must have the same type"; + << Error::TypeError() << "X and like must have the same type"; *ctx->OutputDType("y", 0) = like_tensor.data_type(); return Maybe::Ok(); } diff --git a/oneflow/user/ops/reshape_like_op.cpp b/oneflow/user/ops/reshape_like_op.cpp index 33efa9733dc..7b11d6de6f0 100644 --- a/oneflow/user/ops/reshape_like_op.cpp +++ b/oneflow/user/ops/reshape_like_op.cpp @@ -41,7 +41,7 @@ namespace oneflow { const Shape& like_shape = ctx->InputShape("like", 0); CHECK_EQ_OR_RETURN(in_shape.elem_cnt(), like_shape.elem_cnt()) << Error::RuntimeError() - << "The element number of in tensor must be equal to the element number of " + << "The element number of the in tensor must be equal to the element number of the " "like tensor, " << "but got " << in_shape.elem_cnt() << " and " << like_shape.elem_cnt(); *ctx->OutputShape("out", 0) = like_shape; diff --git a/python/oneflow/test/exceptions/test_randperm_op.py b/python/oneflow/test/exceptions/test_randperm_op.py index 66f379ea0ba..02b402821bc 100644 --- a/python/oneflow/test/exceptions/test_randperm_op.py +++ b/python/oneflow/test/exceptions/test_randperm_op.py @@ -21,7 +21,7 @@ class TestRandpermOp(flow.unittest.TestCase): - def test_n_value_err_mes(test_case): + def test_randperm_n_value_err_mes(test_case): with test_case.assertRaises(RuntimeError) as ctx: a = flow.randperm(-1) test_case.assertTrue( diff --git a/python/oneflow/test/exceptions/test_reduce_like_ops.py b/python/oneflow/test/exceptions/test_reduce_like_ops.py index af1efd7f446..abefaab4f67 100644 --- a/python/oneflow/test/exceptions/test_reduce_like_ops.py +++ b/python/oneflow/test/exceptions/test_reduce_like_ops.py @@ -21,7 +21,7 @@ class TestReduceLikeOps(flow.unittest.TestCase): - def test_empty_axis_case_err(test_case): + def test_reduce_like_empty_axis_case_err(test_case): a = flow.tensor([1, 1]) b = flow.tensor([1, 1, 1]) with test_case.assertRaises(RuntimeError) as ctx: @@ -31,17 +31,15 @@ def test_empty_axis_case_err(test_case): in str(ctx.exception) ) - def test_tensor_type_err(test_case): + def test_reduce_like_type_err(test_case): a = flow.tensor([1, 1], dtype=flow.int64) b = flow.tensor([1, 1], dtype=flow.float64) with test_case.assertRaises(TypeError) as ctx: flow._C.reduce_sum_like(a, b, [1]) test_case.assertTrue( - "Tensors x and like must have the same type" + "X and like must have the same type" in str(ctx.exception) ) - - if __name__ == "__main__": diff --git a/python/oneflow/test/exceptions/test_reshape_like_op.py b/python/oneflow/test/exceptions/test_reshape_like_op.py index 10aff7c88b5..e89921384a0 100644 --- a/python/oneflow/test/exceptions/test_reshape_like_op.py +++ b/python/oneflow/test/exceptions/test_reshape_like_op.py @@ -21,13 +21,14 @@ class TestReshapeLikeOp(flow.unittest.TestCase): - def test_element_number_match_err(test_case): + def test_reshape_like_size_match_err(test_case): a = flow.tensor([1, 1]) b = flow.tensor([[1, 1, 1], [1, 1, 1]]) with test_case.assertRaises(RuntimeError) as ctx: flow._C.reshape_like(a, b) + print(str(ctx.exception)) test_case.assertTrue( - "The element number of in tensor must be equal to the element number of like tensor" + "The element number of the in tensor must be equal to the element number of the like tensor" in str(ctx.exception) ) From 0bbf62bcea14f9ad45bd3329c7f6117d784bb577 Mon Sep 17 00:00:00 2001 From: small1945 <2387491899@qq.com> Date: Mon, 4 Jul 2022 18:05:02 +0800 Subject: [PATCH 4/7] modify the format and aligned with pytorch --- oneflow/user/ops/randperm_op.cpp | 4 ++-- oneflow/user/ops/reduce_like_ops.cpp | 2 +- python/oneflow/test/exceptions/test_randperm_op.py | 2 +- python/oneflow/test/exceptions/test_reduce_like_ops.py | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/oneflow/user/ops/randperm_op.cpp b/oneflow/user/ops/randperm_op.cpp index 2b09adfbad5..956902154ae 100644 --- a/oneflow/user/ops/randperm_op.cpp +++ b/oneflow/user/ops/randperm_op.cpp @@ -30,8 +30,8 @@ namespace oneflow { Shape* out_shape = ctx->OutputShape("out", 0); int32_t n = ctx->Attr("n"); CHECK_GE_OR_RETURN(n, 0) << Error::RuntimeError() - << "Expected the value of n greater than or equal to zero, " - << "but got " << n; + << "Trying to create tensor with negative dimension " << n << ":" + << " [" << n << "]"; *out_shape = Shape({n}); return Maybe::Ok(); } diff --git a/oneflow/user/ops/reduce_like_ops.cpp b/oneflow/user/ops/reduce_like_ops.cpp index d10ebb744db..64d5db36a67 100644 --- a/oneflow/user/ops/reduce_like_ops.cpp +++ b/oneflow/user/ops/reduce_like_ops.cpp @@ -92,7 +92,7 @@ namespace oneflow { const user_op::TensorDesc& x_tensor = ctx->InputTensorDesc("x", 0); const user_op::TensorDesc& like_tensor = ctx->InputTensorDesc("like", 0); CHECK_EQ_OR_RETURN(x_tensor.data_type(), like_tensor.data_type()) - << Error::TypeError() << "X and like must have the same type"; + << Error::TypeError() << "Tensors x and like must have the same type"; *ctx->OutputDType("y", 0) = like_tensor.data_type(); return Maybe::Ok(); } diff --git a/python/oneflow/test/exceptions/test_randperm_op.py b/python/oneflow/test/exceptions/test_randperm_op.py index 02b402821bc..665e103257c 100644 --- a/python/oneflow/test/exceptions/test_randperm_op.py +++ b/python/oneflow/test/exceptions/test_randperm_op.py @@ -25,7 +25,7 @@ def test_randperm_n_value_err_mes(test_case): with test_case.assertRaises(RuntimeError) as ctx: a = flow.randperm(-1) test_case.assertTrue( - "Expected the value of n greater than or equal to zero" + "Trying to create tensor with negative dimension" in str(ctx.exception) ) diff --git a/python/oneflow/test/exceptions/test_reduce_like_ops.py b/python/oneflow/test/exceptions/test_reduce_like_ops.py index abefaab4f67..959e6d23c6d 100644 --- a/python/oneflow/test/exceptions/test_reduce_like_ops.py +++ b/python/oneflow/test/exceptions/test_reduce_like_ops.py @@ -31,13 +31,13 @@ def test_reduce_like_empty_axis_case_err(test_case): in str(ctx.exception) ) - def test_reduce_like_type_err(test_case): + def test_reduce_sum_like_type_err(test_case): a = flow.tensor([1, 1], dtype=flow.int64) b = flow.tensor([1, 1], dtype=flow.float64) with test_case.assertRaises(TypeError) as ctx: flow._C.reduce_sum_like(a, b, [1]) test_case.assertTrue( - "X and like must have the same type" + "Tensors x and like must have the same type" in str(ctx.exception) ) From 2e515591aed367d084de78e5280c8a4a736ace5e Mon Sep 17 00:00:00 2001 From: Zhimin Yang <76760002+small1945@users.noreply.github.com> Date: Tue, 5 Jul 2022 09:37:25 +0800 Subject: [PATCH 5/7] delete print --- python/oneflow/test/exceptions/test_reshape_like_op.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/oneflow/test/exceptions/test_reshape_like_op.py b/python/oneflow/test/exceptions/test_reshape_like_op.py index e89921384a0..cd60fa54e37 100644 --- a/python/oneflow/test/exceptions/test_reshape_like_op.py +++ b/python/oneflow/test/exceptions/test_reshape_like_op.py @@ -26,7 +26,6 @@ def test_reshape_like_size_match_err(test_case): b = flow.tensor([[1, 1, 1], [1, 1, 1]]) with test_case.assertRaises(RuntimeError) as ctx: flow._C.reshape_like(a, b) - print(str(ctx.exception)) test_case.assertTrue( "The element number of the in tensor must be equal to the element number of the like tensor" in str(ctx.exception) From 7d3f6f1330a9d9d10c6dfab2df736c9ecf0b2301 Mon Sep 17 00:00:00 2001 From: Zhimin Yang <76760002+small1945@users.noreply.github.com> Date: Tue, 5 Jul 2022 09:43:40 +0800 Subject: [PATCH 6/7] modity the function name --- python/oneflow/test/exceptions/test_reduce_like_ops.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/oneflow/test/exceptions/test_reduce_like_ops.py b/python/oneflow/test/exceptions/test_reduce_like_ops.py index 959e6d23c6d..17c992be6d1 100644 --- a/python/oneflow/test/exceptions/test_reduce_like_ops.py +++ b/python/oneflow/test/exceptions/test_reduce_like_ops.py @@ -20,8 +20,8 @@ import oneflow.unittest -class TestReduceLikeOps(flow.unittest.TestCase): - def test_reduce_like_empty_axis_case_err(test_case): +class TestReduceSumLikeOps(flow.unittest.TestCase): + def test_reduce_sum_like_empty_axis_case_err(test_case): a = flow.tensor([1, 1]) b = flow.tensor([1, 1, 1]) with test_case.assertRaises(RuntimeError) as ctx: From e36581566da0445cd4edfb2dcca9ec5c8c82ac4f Mon Sep 17 00:00:00 2001 From: oneflow-ci-bot Date: Tue, 5 Jul 2022 01:59:33 +0000 Subject: [PATCH 7/7] auto format by CI --- python/oneflow/test/exceptions/test_randperm_op.py | 3 +-- python/oneflow/test/exceptions/test_reduce_like_ops.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/python/oneflow/test/exceptions/test_randperm_op.py b/python/oneflow/test/exceptions/test_randperm_op.py index 665e103257c..2a62bf4101e 100644 --- a/python/oneflow/test/exceptions/test_randperm_op.py +++ b/python/oneflow/test/exceptions/test_randperm_op.py @@ -25,8 +25,7 @@ def test_randperm_n_value_err_mes(test_case): with test_case.assertRaises(RuntimeError) as ctx: a = flow.randperm(-1) test_case.assertTrue( - "Trying to create tensor with negative dimension" - in str(ctx.exception) + "Trying to create tensor with negative dimension" in str(ctx.exception) ) diff --git a/python/oneflow/test/exceptions/test_reduce_like_ops.py b/python/oneflow/test/exceptions/test_reduce_like_ops.py index 17c992be6d1..8de8504923d 100644 --- a/python/oneflow/test/exceptions/test_reduce_like_ops.py +++ b/python/oneflow/test/exceptions/test_reduce_like_ops.py @@ -37,8 +37,7 @@ def test_reduce_sum_like_type_err(test_case): with test_case.assertRaises(TypeError) as ctx: flow._C.reduce_sum_like(a, b, [1]) test_case.assertTrue( - "Tensors x and like must have the same type" - in str(ctx.exception) + "Tensors x and like must have the same type" in str(ctx.exception) )