!17076 fix log error for pynative mode

From: @chujinjin
Reviewed-by: @zhoufeng54,@kisnwang
Signed-off-by: @kisnwang
This commit is contained in:
mindspore-ci-bot 2021-05-31 09:22:29 +08:00 committed by Gitee
commit 04341b1dbc
2 changed files with 3 additions and 3 deletions

View File

@ -97,8 +97,8 @@ py::tuple check_bprop_out(const py::object &grads_obj, const py::tuple &py_args)
grads = py::cast<py::tuple>(grads_obj);
}
if (grads.size() != py_args.size() - 2) {
MS_EXCEPTION(ValueError) << "For user define net bprop, the gradients number: " << grads.size()
<< " is not equal to the args number: " << py_args.size() - 2 << ".";
MS_EXCEPTION(TypeError) << "For user define net bprop, the gradients number: " << grads.size()
<< " is not equal to the args number: " << py_args.size() - 2 << ".";
}
if (MsContext::GetInstance()->get_param<bool>(MS_CTX_CHECK_BPROP_FLAG)) {
for (size_t i = 0; i < grads.size(); i++) {

View File

@ -207,6 +207,6 @@ def test_user_define_bprop_check_number():
context.set_context(mode=context.PYNATIVE_MODE, check_bprop=True)
net = Net()
grad_net = GradNet(net)
with pytest.raises(ValueError) as ex:
with pytest.raises(TypeError) as ex:
ret = grad_net(x, y, sens)
assert "For user define net bprop, the gradients number: 1 is not equal to the args number: 2." in str(ex.value)