From f9a88a01bc2f3fdac7d2b564f9cf3dc54e4b4039 Mon Sep 17 00:00:00 2001 From: Margaret_wangrui Date: Mon, 20 Dec 2021 17:11:17 +0800 Subject: [PATCH] [ME] Optimize the error message of the operator module --- .../operator/composite/do_signature.cc | 9 ++++----- tests/syntax/simple_expression/test_map.py | 3 +-- .../pynative_mode/test_implicit_conversion.py | 18 ++---------------- 3 files changed, 7 insertions(+), 23 deletions(-) diff --git a/mindspore/ccsrc/frontend/operator/composite/do_signature.cc b/mindspore/ccsrc/frontend/operator/composite/do_signature.cc index d3b9d0da7e6..5bf2e39bc0e 100644 --- a/mindspore/ccsrc/frontend/operator/composite/do_signature.cc +++ b/mindspore/ccsrc/frontend/operator/composite/do_signature.cc @@ -347,11 +347,10 @@ FuncGraphPtr DoSignatureMetaFuncGraph::GenerateFuncGraph(const AbstractBasePtrLi void RaiseExceptionForConvertRefDtype(const std::string &func_name, const std::string &ref_type, const std::string &target_type) { - MS_LOG(EXCEPTION) << "For '" << func_name << "' operator, " - << "the type of writable argument is '" << ref_type << "', " - << "but the largest type in the same SignatureEnumDType is '" << target_type - << "'. The writable arg type is not equal to the largest type, " - << "so can not cast automatically."; + MS_LOG(EXCEPTION) << "Data type conversion of parameter is not supported, so data type " << ref_type + << " cannot be converted to data type " << target_type << " by inserting cast automatically.\n" + << "For more details, please refer at " + << "https://www.mindspore.cn/docs/note/zh-CN/master/operator_list_implicit.html."; } void RaiseExceptionForCheckParameter(const std::string &func_name, size_t i, const std::string &source_type) { MS_EXCEPTION(TypeError) << "Function " << func_name << "'s input " << i << " should be a Parameter, but " diff --git a/tests/syntax/simple_expression/test_map.py b/tests/syntax/simple_expression/test_map.py index 242bf6e50d6..d11d153c90a 100644 --- a/tests/syntax/simple_expression/test_map.py +++ b/tests/syntax/simple_expression/test_map.py @@ -165,7 +165,6 @@ def test_map_param_cast(): input_me_x = Tensor(np.random.randn(2, 3, 4, 5).astype(np.float64)) net = MapNet() - with pytest.raises(Exception, match="For 'S-Prim-Assign' operator, " - "the type of writable argument is 'float32'"): + with pytest.raises(Exception, match="Data type conversion of parameter is not supported"): ret = net(input_me_x) print("ret:", ret) diff --git a/tests/ut/python/pynative_mode/test_implicit_conversion.py b/tests/ut/python/pynative_mode/test_implicit_conversion.py index 9757a86126d..46d634ba8a3 100644 --- a/tests/ut/python/pynative_mode/test_implicit_conversion.py +++ b/tests/ut/python/pynative_mode/test_implicit_conversion.py @@ -132,9 +132,6 @@ def test_float_tensor_and_list_add(): def test_float_tensor_and_bool_tensors_add_grad(): class Net(nn.Cell): - def __init__(self): - super(Net, self).__init__() - def construct(self, x, y): return x + y @@ -160,9 +157,6 @@ def test_float_tensor_and_bool_tensors_add_grad(): def test_float_tensor_and_int_tensors_sub_grad(): class Net(nn.Cell): - def __init__(self): - super(Net, self).__init__() - def construct(self, x, y): return x - y @@ -188,9 +182,6 @@ def test_float_tensor_and_int_tensors_sub_grad(): def test_float16_tensor_and_float32_tensors_sub_grad(): class Net(nn.Cell): - def __init__(self): - super(Net, self).__init__() - def construct(self, x, y): return x - y @@ -216,9 +207,6 @@ def test_float16_tensor_and_float32_tensors_sub_grad(): def test_float_tensor_and_int_add_grad(): class Net(nn.Cell): - def __init__(self): - super(Net, self).__init__() - def construct(self, x): return x + 2 @@ -241,9 +229,6 @@ def test_float_tensor_and_int_add_grad(): def test_int8_tensor_and_uint8_tensors_add_grad(): class Net(nn.Cell): - def __init__(self): - super(Net, self).__init__() - def construct(self, x, y): return x + y @@ -266,6 +251,7 @@ def test_int8_tensor_and_uint8_tensors_add_grad(): assert (ret[0].asnumpy() == sens.asnumpy()).all() assert (ret[1].asnumpy() == sens.asnumpy()).all() + class AssignCheck(nn.Cell): """ NetWithNDarray definition """ @@ -285,4 +271,4 @@ def test_assign_check_in_sig(): y = Tensor(3, ms.uint8) with pytest.raises(RuntimeError) as e: net(x, y) - assert "can not cast automatically" in e.value.args[0] + assert "Data type conversion of parameter is not supported" in e.value.args[0]