Browse Source

!25718 optimize implicit convert error message

Merge pull request !25718 from chujinjin/optimize_implicit_convert_error_msg
tags/v1.6.0
i-robot Gitee 4 years ago
parent
commit
2828f317f7
2 changed files with 5 additions and 5 deletions
  1. +4
    -4
      mindspore/ccsrc/pipeline/pynative/pynative_execute.cc
  2. +1
    -1
      tests/ut/python/pynative_mode/test_implicit_conversion.py

+ 4
- 4
mindspore/ccsrc/pipeline/pynative/pynative_execute.cc View File

@@ -1271,10 +1271,10 @@ void ForwardExecutor::DoSignatrueCast(const PrimitivePyPtr &prim,
}

if (!py::isinstance<tensor::Tensor>(obj) && !py::isinstance<py::int_>(obj) && !py::isinstance<py::float_>(obj)) {
MS_EXCEPTION(TypeError) << "For '" << prim->name() << "', the " << i
<< "th input is a not support implicit conversion type: "
<< py::cast<std::string>(obj.attr("__class__").attr("__name__")) << ", and the value is "
<< py::cast<py::str>(obj) << ".";
MS_EXCEPTION(TypeError) << "For '" << prim->name() << "', the " << i << "th input " << signature[i].name
<< " is a not support implicit conversion. "
<< "Its type is " << py::cast<std::string>(obj.attr("__class__").attr("__name__"))
<< ", and the value is " << py::cast<py::str>(obj) << ". Only support Tensor or Scalar.";
}
py::object cast_output = DoAutoCast(input_args[i], it->second, op_exec_info->op_name, i);
input_args[i] = cast_output;


+ 1
- 1
tests/ut/python/pynative_mode/test_implicit_conversion.py View File

@@ -111,7 +111,7 @@ def test_float_tensor_and_str_add():
y = "ok"
with pytest.raises(TypeError) as er:
ret = x + y
assert "For 'Add', the 1th input is a not support implicit conversion type: str" in str(er.value)
assert "For 'Add', the 1th input var is a not support implicit conversion. Its type is" in str(er.value)


def test_float_tensor_and_tuple_add():


Loading…
Cancel
Save