From 0a051297858bb73fcd2850b0b87f73f18978038f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B6=85=E7=BA=A7=E7=A0=81=E7=89=9B?= <54444805+SuperCodebull@users.noreply.github.com> Date: Wed, 9 Nov 2022 11:25:32 +0800 Subject: [PATCH] fix The first round of evaluation (#47256) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix paddle.get_default_dtype Chinese and English return values are inconsistent * fix paddle.matmul 文档评估 #4407 把函数的输出改成正确的 * fix paddle.std文档评估 #4370 增加了一个unbiased=False的代码示例,没有增加numpy,怕引起误会。 * fix paddle.load文档测评 #4455 只把代码拆分了5段 * try * try * try * Update io.py * Update io.py * Update creation.py * Update creation.py * [Docs]add name description * [Docs]fix broadcasting issue Co-authored-by: Ligoml <39876205+Ligoml@users.noreply.github.com> --- python/paddle/framework/io.py | 22 ++++++++++++++++++++++ python/paddle/tensor/creation.py | 2 +- python/paddle/tensor/linalg.py | 22 ++++++++++++---------- python/paddle/tensor/search.py | 2 +- python/paddle/tensor/stat.py | 5 ++++- 5 files changed, 40 insertions(+), 13 deletions(-) diff --git a/python/paddle/framework/io.py b/python/paddle/framework/io.py index 0052c1fe655..758f734dd9a 100644 --- a/python/paddle/framework/io.py +++ b/python/paddle/framework/io.py @@ -669,6 +669,7 @@ def save(obj, path, protocol=4, **configs): Examples: .. code-block:: python + :name: code-example-1 # example 1: dynamic graph import paddle @@ -690,7 +691,11 @@ def save(obj, path, protocol=4, **configs): # save weight of emb paddle.save(emb.weight, "emb.weight.pdtensor") + .. code-block:: python + :name: code-example-2 + # example 2: Save multiple state_dict at the same time + import paddle from paddle import nn from paddle.optimizer import Adam @@ -700,6 +705,8 @@ def save(obj, path, protocol=4, **configs): path = 'example/model.pdparams' paddle.save(obj, path) + .. code-block:: python + :name: code-example-3 # example 3: static graph import paddle @@ -728,6 +735,9 @@ def save(obj, path, protocol=4, **configs): path_state_dict = 'temp/model.pdparams' paddle.save(prog.state_dict("param"), path_tensor) + .. code-block:: python + :name: code-example-4 + # example 4: save program import paddle @@ -740,6 +750,8 @@ def save(obj, path, protocol=4, **configs): path = "example/main_program.pdmodel" paddle.save(main_program, path) + .. code-block:: python + :name: code-example-5 # example 5: save object to memory from io import BytesIO @@ -918,6 +930,7 @@ def load(path, **configs): Examples: .. code-block:: python + :name: code-example-1 # example 1: dynamic graph import paddle @@ -946,8 +959,11 @@ def load(path, **configs): # load weight of emb load_weight = paddle.load("emb.weight.pdtensor") + .. code-block:: python + :name: code-example-2 # example 2: Load multiple state_dict at the same time + import paddle from paddle import nn from paddle.optimizer import Adam @@ -958,6 +974,8 @@ def load(path, **configs): paddle.save(obj, path) obj_load = paddle.load(path) + .. code-block:: python + :name: code-example-3 # example 3: static graph import paddle @@ -988,6 +1006,8 @@ def load(path, **configs): paddle.save(prog.state_dict("param"), path_tensor) load_state_dict = paddle.load(path_tensor) + .. code-block:: python + :name: code-example-4 # example 4: load program import paddle @@ -1003,6 +1023,8 @@ def load(path, **configs): load_main = paddle.load(path) print(load_main) + .. code-block:: python + :name: code-example-5 # example 5: save object to memory from io import BytesIO diff --git a/python/paddle/tensor/creation.py b/python/paddle/tensor/creation.py index 32f63c6f236..cf04a44cb02 100644 --- a/python/paddle/tensor/creation.py +++ b/python/paddle/tensor/creation.py @@ -1174,7 +1174,7 @@ def triu(x, diagonal=0, name=None): def meshgrid(*args, **kwargs): """ - Takes a list of N tensors as input *args, each of which is 1-dimensional vector, and creates N-dimensional grids. + Takes a list of N tensors as input :attr:`*args`, each of which is 1-dimensional vector, and creates N-dimensional grids. Args: *args(Tensor|list of Tensor) : tensors (tuple(list) of tensor): the shapes of input k tensors are (N1,), diff --git a/python/paddle/tensor/linalg.py b/python/paddle/tensor/linalg.py index 655e34de779..41166b71a0c 100644 --- a/python/paddle/tensor/linalg.py +++ b/python/paddle/tensor/linalg.py @@ -183,9 +183,9 @@ def matmul(x, y, transpose_x=False, transpose_y=False, name=None): Args: x (Tensor): The input tensor which is a Tensor. y (Tensor): The input tensor which is a Tensor. - transpose_x (bool): Whether to transpose :math:`x` before multiplication. - transpose_y (bool): Whether to transpose :math:`y` before multiplication. - name(str|None): A name for this layer(optional). If set None, the layer + transpose_x (bool, optional): Whether to transpose :math:`x` before multiplication. + transpose_y (bool, optional): Whether to transpose :math:`y` before multiplication. + name(str, optional): A name for this layer(optional). If set None, the layer will be named automatically. Returns: @@ -202,35 +202,35 @@ def matmul(x, y, transpose_x=False, transpose_y=False, name=None): y = paddle.rand([10]) z = paddle.matmul(x, y) print(z.shape) - # [1] + # (1,) # matrix * vector x = paddle.rand([10, 5]) y = paddle.rand([5]) z = paddle.matmul(x, y) print(z.shape) - # [10] + # (10,) # batched matrix * broadcasted vector x = paddle.rand([10, 5, 2]) y = paddle.rand([2]) z = paddle.matmul(x, y) print(z.shape) - # [10, 5] + # (10, 5) # batched matrix * batched matrix x = paddle.rand([10, 5, 2]) y = paddle.rand([10, 2, 5]) z = paddle.matmul(x, y) print(z.shape) - # [10, 5, 5] + # (10, 5, 5) # batched matrix * broadcasted matrix x = paddle.rand([10, 1, 5, 2]) y = paddle.rand([1, 3, 2, 5]) z = paddle.matmul(x, y) print(z.shape) - # [10, 3, 5, 5] + # (10, 3, 5, 5) """ if in_dygraph_mode(): @@ -639,9 +639,9 @@ def norm(x, p='fro', axis=None, keepdim=False, name=None): def dist(x, y, p=2, name=None): r""" - This OP returns the p-norm of (x - y). It is not a norm in a strict sense, only as a measure + Returns the p-norm of (x - y). It is not a norm in a strict sense, only as a measure of distance. The shapes of x and y must be broadcastable. The definition is as follows, for - details, please refer to the `numpy's broadcasting `_: + details, please refer to the `Introduction to Tensor <../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor>`_: - Each input has at least one dimension. - Match the two input dimensions from back to front, the dimension sizes must either be equal, one of them is 1, or one of them does not exist. @@ -695,6 +695,8 @@ def dist(x, y, p=2, name=None): x (Tensor): 1-D to 6-D Tensor, its data type is float32 or float64. y (Tensor): 1-D to 6-D Tensor, its data type is float32 or float64. p (float, optional): The norm to be computed, its data type is float32 or float64. Default: 2. + name (str, optional): The default value is `None`. Normally there is no need for + user to set this property. For more information, please refer to :ref:`api_guide_Name`. Returns: Tensor: Tensor that is the p-norm of (x - y). diff --git a/python/paddle/tensor/search.py b/python/paddle/tensor/search.py index 62509aaedf8..f8c6861d48c 100644 --- a/python/paddle/tensor/search.py +++ b/python/paddle/tensor/search.py @@ -384,7 +384,7 @@ def nonzero(x, as_tuple=False): Args: x (Tensor): The input tensor variable. - as_tuple (bool): Return type, Tensor or tuple of Tensor. + as_tuple (bool, optional): Return type, Tensor or tuple of Tensor. Returns: Tensor. The data type is int64. diff --git a/python/paddle/tensor/stat.py b/python/paddle/tensor/stat.py index f77c5a5a962..8fc5fe42cbd 100644 --- a/python/paddle/tensor/stat.py +++ b/python/paddle/tensor/stat.py @@ -206,8 +206,11 @@ def std(x, axis=None, unbiased=True, keepdim=False, name=None): x = paddle.to_tensor([[1.0, 2.0, 3.0], [1.0, 4.0, 5.0]]) out1 = paddle.std(x) # [1.63299316] - out2 = paddle.std(x, axis=1) + out2 = paddle.std(x, unbiased=False) + # [1.49071205] + out3 = paddle.std(x, axis=1) # [1. 2.081666] + """ if not paddle.in_dynamic_mode(): check_variable_and_dtype(x, 'x', ['float32', 'float64'], 'std') -- GitLab