diff --git a/mindspore/nn/layer/normalization.py b/mindspore/nn/layer/normalization.py index 65df2d78ed0..fc08744ccdc 100644 --- a/mindspore/nn/layer/normalization.py +++ b/mindspore/nn/layer/normalization.py @@ -149,6 +149,8 @@ class _BatchNorm(Cell): def construct(self, x): if self.input_dims == '2d': _shape_check(self.shape(x)) + if self.input_dims == '1d': + _shape_check_2d(self.shape(x)) if self.use_batch_statistics is None: flag = self.training else: @@ -200,6 +202,12 @@ def _channel_check(channel, num_channel): raise ValueError("the input channel is not equal with num_channel") +@constexpr +def _shape_check_2d(input_shape): + if len(input_shape) != 2: + raise ValueError("The input must has 2 dims.") + + @constexpr def _shape_check(in_shape): if len(in_shape) != 4: diff --git a/mindspore/ops/_grad/grad_math_ops.py b/mindspore/ops/_grad/grad_math_ops.py index ae0b06745e3..bae9034c620 100755 --- a/mindspore/ops/_grad/grad_math_ops.py +++ b/mindspore/ops/_grad/grad_math_ops.py @@ -980,7 +980,8 @@ def get_bprop_scalar_accumulatenv2(self): dx = () for _ in range(len(x)): dx = dx + (dout,) - return dx + return (dx,) + return bprop @@ -992,7 +993,7 @@ def get_bprop_scalar_addn(self): dx = () for _ in range(len(x)): dx = dx + (dout,) - return dx + return (dx,) return bprop diff --git a/tests/ut/python/ops/test_ops.py b/tests/ut/python/ops/test_ops.py index ef5b0953362..debc47185eb 100755 --- a/tests/ut/python/ops/test_ops.py +++ b/tests/ut/python/ops/test_ops.py @@ -1671,13 +1671,11 @@ test_case_array_ops = [ ('AddN', { 'block': NetForTupleInput(P.AddN()), 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]], - 'desc_bprop': [[2, 3, 3, 5]], - 'skip': ['backward']}), + 'desc_bprop': [[2, 3, 3, 5]]}), ('AccumulateNV2', { 'block': NetForTupleInput(P.AccumulateNV2()), 'desc_inputs': [[2, 3, 3, 5], [2, 3, 3, 5]], - 'desc_bprop': [[2, 3, 3, 5]], - 'skip': ['backward']}), + 'desc_bprop': [[2, 3, 3, 5]]}), ('Shape', { 'block': P.Shape(), 'desc_inputs': [[3, 3, 2, 2]], diff --git a/tests/ut/python/pynative_mode/nn/test_batchnorm.py b/tests/ut/python/pynative_mode/nn/test_batchnorm.py index 08f84f2fe36..a0fda8bd5e2 100644 --- a/tests/ut/python/pynative_mode/nn/test_batchnorm.py +++ b/tests/ut/python/pynative_mode/nn/test_batchnorm.py @@ -67,10 +67,10 @@ def test_bn2d(): def test_bn1d(): """ut of nn.BatchNorm1d""" bn = nn.BatchNorm1d(3) - input_data = Tensor(np.random.randint(0, 1, [1, 3, 100, 100]).astype(np.float32)) + input_data = Tensor(np.random.randint(0, 1, [1, 3]).astype(np.float32)) output = bn(input_data) output_np = output.asnumpy() - assert isinstance(output_np[0][0][0][0], (np.float32, np.float64)) + assert isinstance(output_np[0][0], (np.float32, np.float64)) def test_bn2d_train():