Optimize error message

This commit is contained in:
Margaret_wangrui 2022-01-06 20:15:56 +08:00
parent 64bbece74c
commit 7d1f3d71ba
7 changed files with 12 additions and 17 deletions

View File

@ -769,7 +769,7 @@ FuncGraphPtr GradOperation::GenerateFuncGraph(const AbstractBasePtrList &args_sp
MS_EXCEPTION_IF_NULL(args_spec_list[0]);
AbstractFunctionPtr fn = dyn_cast<AbstractFunction>(args_spec_list[0]);
if (fn == nullptr) {
MS_LOG(EXCEPTION) << "'GradOperation' arg0 must be a 'Function' or 'Cell', but got "
MS_LOG(EXCEPTION) << "For 'GradOperation', the first argument must be a 'Function' or 'Cell', but got "
<< args_spec_list[0]->ToString();
}

View File

@ -55,7 +55,7 @@ void ProcessDefault(const std::string &func_name, size_t actual_param_number, co
for (size_t i = actual_param_number; i < sig_size; ++i) {
auto default_value = signature[i].default_value;
if (default_value == nullptr) {
MS_LOG(EXCEPTION) << "The size of input in the operator should be " << sig_size << ", but got "
MS_LOG(EXCEPTION) << "For '" << func_name << "', the size of input should be " << sig_size << ", but got "
<< actual_param_number << ". Please check inputs of the operator.";
} else {
(*op_inputs).push_back(NewValueNode(default_value));

View File

@ -109,7 +109,7 @@ AnfNodePtr Map::FullMakeList(const std::shared_ptr<List> &type, const FuncGraphP
}
}
if (is_not_same) {
MS_LOG(EXCEPTION) << "The length of lists in Map must be the same. " << oss.str();
MS_LOG(EXCEPTION) << "For 'Map', the length of lists must be the same. " << oss.str();
}
constexpr size_t kPrimHoldLen = 1;
@ -170,7 +170,7 @@ AnfNodePtr Map::FullMakeTuple(const std::shared_ptr<Tuple> &type, const FuncGrap
}
}
if (is_not_same) {
MS_LOG(EXCEPTION) << "The length of tuples in Map must be the same. " << oss.str();
MS_LOG(EXCEPTION) << "For 'Map', the length of tuples must be the same. " << oss.str();
}
constexpr size_t kPrimHoldLen = 1;

View File

@ -631,7 +631,8 @@ AbstractBasePtr InferImplMakeRange(const AnalysisEnginePtr &, const PrimitivePtr
if (slide.step <= 0) {
MS_LOG(EXCEPTION) << "For 'range', while the argument 'start' " << slide.start
<< " is less than or equal to the argument 'stop' " << slide.stop << ", "
<< "the argument 'step' must be more than 0, but the argument 'step' is " << slide.step << ".";
<< "the argument 'step' must be greater than 0, but the argument 'step' is " << slide.step
<< ".";
}
for (int64_t i = slide.start; i < slide.stop; i += slide.step) {
@ -643,7 +644,7 @@ AbstractBasePtr InferImplMakeRange(const AnalysisEnginePtr &, const PrimitivePtr
}
} else {
if (slide.step >= 0) {
MS_LOG(EXCEPTION) << "For 'range', while the argument 'start' " << slide.start << " is more than the argument "
MS_LOG(EXCEPTION) << "For 'range', while the argument 'start' " << slide.start << " is greater than the argument "
<< "'stop' " << slide.stop << ", the argument 'step' must be less than 0, "
<< "but the argument 'step' is " << slide.step << ".";
}
@ -773,7 +774,7 @@ AbstractBasePtr InferImplMakeRecord(const AnalysisEnginePtr &, const PrimitivePt
const AbstractBasePtrList &args_spec_list) {
// Inputs: at lease two objects of a subclass of AbstractBase.
if (args_spec_list.size() < 2) {
MS_LOG(EXCEPTION) << "The size of arguments of MakeRecord operator must more than 1, but the input size is "
MS_LOG(EXCEPTION) << "The size of arguments of MakeRecord operator must greater than 1, but the input size is "
<< args_spec_list.size() << ".";
}

View File

@ -118,7 +118,7 @@ def test_map_args_full_make_list_same_length():
input_me_y = Tensor(np.random.randn(2, 3, 4, 5).astype(np.float32))
net = MapNet()
with pytest.raises(Exception, match="The length of lists in Map must be the same"):
with pytest.raises(Exception, match="For 'Map', the length of lists must be the same."):
ret = net([input_me_x], [input_me_y, input_me_y])
print("ret:", ret)
@ -142,7 +142,7 @@ def test_map_args_full_make_tuple_same_length():
input_me_y = Tensor(np.random.randn(2, 3, 4, 5).astype(np.float32))
net = MapNet()
with pytest.raises(Exception, match="The length of tuples in Map must be the same."):
with pytest.raises(Exception, match="For 'Map', the length of tuples must be the same."):
ret = net((input_me_x, input_me_x), (input_me_y, input_me_y, input_me_y))
print("ret:", ret)

View File

@ -84,7 +84,7 @@ def test_inner_scalar_mod_args_length():
x = Tensor(2, dtype=ms.int32)
net = Net()
with pytest.raises(Exception, match="The size of input in the operator should be 2"):
with pytest.raises(Exception, match="For 'S-Prim-Mod', the size of input should be 2"):
ret = net(x)
print("ret:", ret)

View File

@ -154,9 +154,6 @@ def test_second_grad_with_j_primitive():
def test_ad_fv_cnode_order():
context.set_context(mode=context.GRAPH_MODE)
class Net(nn.Cell):
def __init__(self):
super(Net, self).__init__()
# cnode xay is not being MapMorphism when cnode second_level() is being MapMorphism and
# BackPropagateFv as MapMorphism is started from output node and from left to right order.
def construct(self, x, y):
@ -256,9 +253,6 @@ def test_limit_lift_fv_scope():
def test_same_primal_used_by_multi_j():
class Net(nn.Cell):
def __init__(self):
super(Net, self).__init__()
def construct(self, x):
return x
@ -466,7 +460,7 @@ def test_grad_net_is_none():
try:
GradNetWrtX(Net())(x, y)
except Exception as e:
assert "'GradOperation' arg0 must be a 'Function' or 'Cell', but got" in str(e)
assert "For 'GradOperation', the first argument must be a 'Function' or 'Cell', but got" in str(e)
def test_grad_missing_net():