diff --git a/docs/api/api_python/ops/mindspore.ops.func_pad.rst b/docs/api/api_python/ops/mindspore.ops.func_pad.rst index 9680a210a1b..4278476f1de 100644 --- a/docs/api/api_python/ops/mindspore.ops.func_pad.rst +++ b/docs/api/api_python/ops/mindspore.ops.func_pad.rst @@ -3,7 +3,7 @@ mindspore.ops.pad .. py:function:: mindspore.ops.pad(input_x, padding, mode='constant', value=None) - 根据参数 `paddings` 对输入进行填充。 + 根据参数 `padding` 对输入进行填充。 参数: - **input_x** (Tensor) - 输入Tensor,shape为 :math:`(N, *)`, :math:`*` 代表任意附加维度。 diff --git a/mindspore/python/mindspore/ops/function/nn_func.py b/mindspore/python/mindspore/ops/function/nn_func.py index d31ded39063..2d49dfc35a7 100644 --- a/mindspore/python/mindspore/ops/function/nn_func.py +++ b/mindspore/python/mindspore/ops/function/nn_func.py @@ -2396,7 +2396,7 @@ def _check_pad_inputs(padding): def pad(input_x, padding, mode='constant', value=None): r""" - Pads the input tensor according to the paddings. + Pads the input tensor according to the padding. Args: input_x (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of additional dimensions. @@ -2478,6 +2478,8 @@ def pad(input_x, padding, mode='constant', value=None): """ if not isinstance(input_x, Tensor): raise TypeError(f"For 'pad', the type of 'input_x' must be Tensor, but got {type(input_x)}.") + if (isinstance(padding, (tuple, list)) and not padding) or (isinstance(padding, Tensor) and padding.shape == (0,)): + return input_x if not isinstance(padding, Tensor): _check_pad_inputs(padding) padding = Tensor(padding)