diff --git a/python/paddle/framework/io.py b/python/paddle/framework/io.py index 0052c1fe6555891249bce6b9e635c26de2a45f1a..758f734dd9ac73c77b5777922c7fa0ebbeaa507d 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 32f63c6f236a2d15d20575aeacbe8c34bbefa920..cf04a44cb02fbedaccf78cff8da9bb09201e9592 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 655e34de779383cec89e7e54ac5ce07bd5902e66..41166b71a0cf67648953c02e6a3765d98f8590d0 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 62509aaedf8af44260a691a2ea98fb98aa94cb67..f8c6861d48c84fcabc2201fd0fb0bbde613dd51c 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 f77c5a5a962713c91d42e14b24543a94da9c3d13..8fc5fe42cbd9b5c89992ae5c10d861476a942e2b 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')