From 8e08bb11c627aa430c9fa83b32ec693bc5618e80 Mon Sep 17 00:00:00 2001 From: liuyang_655 Date: Fri, 29 Oct 2021 05:48:11 -0400 Subject: [PATCH] modify white error list --- mindspore/common/dtype.py | 4 +++- mindspore/common/initializer.py | 14 ++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/mindspore/common/dtype.py b/mindspore/common/dtype.py index 296e6847372..d0881b14057 100644 --- a/mindspore/common/dtype.py +++ b/mindspore/common/dtype.py @@ -182,7 +182,9 @@ def pytype_to_dtype(obj): obj = obj.type if isinstance(obj, typing.Type): return obj - if isinstance(obj, type) and obj in _simple_types: + if not isinstance(obj, type): + raise TypeError("The argument 'obj' must be a python type object, such as int, float, str, etc. But got type {}.".format(type(obj))) + elif obj in _simple_types: return _simple_types[obj] raise NotImplementedError(f"The python type {obj} cannot be converted to MindSpore type.") diff --git a/mindspore/common/initializer.py b/mindspore/common/initializer.py index 172ad6db588..31ca355cb6d 100644 --- a/mindspore/common/initializer.py +++ b/mindspore/common/initializer.py @@ -168,7 +168,7 @@ def _calculate_correct_fan(shape, mode): mode = mode.lower() valid_modes = ['fan_in', 'fan_out'] if mode not in valid_modes: - raise ValueError("Mode {} not supported, please use one of {}".format(mode, valid_modes)) + raise ValueError("'mode' {} not supported, please use one of {}".format(mode, valid_modes)) fan_in, fan_out = _calculate_fan_in_and_fan_out(shape) return fan_in if mode == 'fan_in' else fan_out @@ -198,12 +198,13 @@ def _calculate_gain(nonlinearity, param=None): # True/False are instances of int, hence check above negative_slope = param else: - raise ValueError("negative_slope {} is not a valid number. " - "It should be bool, int, or float type.".format(param)) + raise ValueError("'negative_slope' {} is not a valid number. When 'nonlinearity' has been set to " + "'leaky_relu', 'negative_slope' should be int or float type, but got " + "{}.".format(param, type(param))) res = math.sqrt(2.0 / (1 + negative_slope ** 2)) else: - raise ValueError("Unsupported nonlinearity {}, the argument 'nonlinearity' should be one of " - "'sigmoid', 'tanh', 'relu' or 'leaky_relu'.".format(nonlinearity)) + raise ValueError("The argument 'nonlinearity' should be one of ['sigmoid', 'tanh', 'relu' or 'leaky_relu'], " + "but got {}.".format(nonlinearity)) return res @@ -219,7 +220,8 @@ def _calculate_in_and_out(arr): """ dim = len(arr.shape) if dim < 2: - raise ValueError("If initialize data with xavier uniform, the dimension of data must be greater than 1.") + raise ValueError("If initialize data with xavier uniform, the dimension of data must be greater than 1, " + "but got {}.".format(dim)) n_in = arr.shape[1] n_out = arr.shape[0]