Skip to content

Commit 0a05129

Browse files
fix The first round of evaluation (#47256)
* 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 <[email protected]>
1 parent ae14bad commit 0a05129

File tree

5 files changed

+40
-13
lines changed

5 files changed

+40
-13
lines changed

python/paddle/framework/io.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ def save(obj, path, protocol=4, **configs):
669669
670670
Examples:
671671
.. code-block:: python
672+
:name: code-example-1
672673
673674
# example 1: dynamic graph
674675
import paddle
@@ -690,7 +691,11 @@ def save(obj, path, protocol=4, **configs):
690691
# save weight of emb
691692
paddle.save(emb.weight, "emb.weight.pdtensor")
692693
694+
.. code-block:: python
695+
:name: code-example-2
696+
693697
# example 2: Save multiple state_dict at the same time
698+
import paddle
694699
from paddle import nn
695700
from paddle.optimizer import Adam
696701
@@ -700,6 +705,8 @@ def save(obj, path, protocol=4, **configs):
700705
path = 'example/model.pdparams'
701706
paddle.save(obj, path)
702707
708+
.. code-block:: python
709+
:name: code-example-3
703710
704711
# example 3: static graph
705712
import paddle
@@ -728,6 +735,9 @@ def save(obj, path, protocol=4, **configs):
728735
path_state_dict = 'temp/model.pdparams'
729736
paddle.save(prog.state_dict("param"), path_tensor)
730737
738+
.. code-block:: python
739+
:name: code-example-4
740+
731741
# example 4: save program
732742
import paddle
733743
@@ -740,6 +750,8 @@ def save(obj, path, protocol=4, **configs):
740750
path = "example/main_program.pdmodel"
741751
paddle.save(main_program, path)
742752
753+
.. code-block:: python
754+
:name: code-example-5
743755
744756
# example 5: save object to memory
745757
from io import BytesIO
@@ -918,6 +930,7 @@ def load(path, **configs):
918930
919931
Examples:
920932
.. code-block:: python
933+
:name: code-example-1
921934
922935
# example 1: dynamic graph
923936
import paddle
@@ -946,8 +959,11 @@ def load(path, **configs):
946959
# load weight of emb
947960
load_weight = paddle.load("emb.weight.pdtensor")
948961
962+
.. code-block:: python
963+
:name: code-example-2
949964
950965
# example 2: Load multiple state_dict at the same time
966+
import paddle
951967
from paddle import nn
952968
from paddle.optimizer import Adam
953969
@@ -958,6 +974,8 @@ def load(path, **configs):
958974
paddle.save(obj, path)
959975
obj_load = paddle.load(path)
960976
977+
.. code-block:: python
978+
:name: code-example-3
961979
962980
# example 3: static graph
963981
import paddle
@@ -988,6 +1006,8 @@ def load(path, **configs):
9881006
paddle.save(prog.state_dict("param"), path_tensor)
9891007
load_state_dict = paddle.load(path_tensor)
9901008
1009+
.. code-block:: python
1010+
:name: code-example-4
9911011
9921012
# example 4: load program
9931013
import paddle
@@ -1003,6 +1023,8 @@ def load(path, **configs):
10031023
load_main = paddle.load(path)
10041024
print(load_main)
10051025
1026+
.. code-block:: python
1027+
:name: code-example-5
10061028
10071029
# example 5: save object to memory
10081030
from io import BytesIO

python/paddle/tensor/creation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ def triu(x, diagonal=0, name=None):
11741174

11751175
def meshgrid(*args, **kwargs):
11761176
"""
1177-
Takes a list of N tensors as input *args, each of which is 1-dimensional vector, and creates N-dimensional grids.
1177+
Takes a list of N tensors as input :attr:`*args`, each of which is 1-dimensional vector, and creates N-dimensional grids.
11781178
11791179
Args:
11801180
*args(Tensor|list of Tensor) : tensors (tuple(list) of tensor): the shapes of input k tensors are (N1,),

python/paddle/tensor/linalg.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ def matmul(x, y, transpose_x=False, transpose_y=False, name=None):
183183
Args:
184184
x (Tensor): The input tensor which is a Tensor.
185185
y (Tensor): The input tensor which is a Tensor.
186-
transpose_x (bool): Whether to transpose :math:`x` before multiplication.
187-
transpose_y (bool): Whether to transpose :math:`y` before multiplication.
188-
name(str|None): A name for this layer(optional). If set None, the layer
186+
transpose_x (bool, optional): Whether to transpose :math:`x` before multiplication.
187+
transpose_y (bool, optional): Whether to transpose :math:`y` before multiplication.
188+
name(str, optional): A name for this layer(optional). If set None, the layer
189189
will be named automatically.
190190
191191
Returns:
@@ -202,35 +202,35 @@ def matmul(x, y, transpose_x=False, transpose_y=False, name=None):
202202
y = paddle.rand([10])
203203
z = paddle.matmul(x, y)
204204
print(z.shape)
205-
# [1]
205+
# (1,)
206206
207207
# matrix * vector
208208
x = paddle.rand([10, 5])
209209
y = paddle.rand([5])
210210
z = paddle.matmul(x, y)
211211
print(z.shape)
212-
# [10]
212+
# (10,)
213213
214214
# batched matrix * broadcasted vector
215215
x = paddle.rand([10, 5, 2])
216216
y = paddle.rand([2])
217217
z = paddle.matmul(x, y)
218218
print(z.shape)
219-
# [10, 5]
219+
# (10, 5)
220220
221221
# batched matrix * batched matrix
222222
x = paddle.rand([10, 5, 2])
223223
y = paddle.rand([10, 2, 5])
224224
z = paddle.matmul(x, y)
225225
print(z.shape)
226-
# [10, 5, 5]
226+
# (10, 5, 5)
227227
228228
# batched matrix * broadcasted matrix
229229
x = paddle.rand([10, 1, 5, 2])
230230
y = paddle.rand([1, 3, 2, 5])
231231
z = paddle.matmul(x, y)
232232
print(z.shape)
233-
# [10, 3, 5, 5]
233+
# (10, 3, 5, 5)
234234
235235
"""
236236
if in_dygraph_mode():
@@ -639,9 +639,9 @@ def p_matrix_norm(input, porder=1.0, axis=axis, keepdim=False, name=None):
639639
def dist(x, y, p=2, name=None):
640640
r"""
641641
642-
This OP returns the p-norm of (x - y). It is not a norm in a strict sense, only as a measure
642+
Returns the p-norm of (x - y). It is not a norm in a strict sense, only as a measure
643643
of distance. The shapes of x and y must be broadcastable. The definition is as follows, for
644-
details, please refer to the `numpy's broadcasting <https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html>`_:
644+
details, please refer to the `Introduction to Tensor <../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor>`_:
645645
646646
- Each input has at least one dimension.
647647
- 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):
695695
x (Tensor): 1-D to 6-D Tensor, its data type is float32 or float64.
696696
y (Tensor): 1-D to 6-D Tensor, its data type is float32 or float64.
697697
p (float, optional): The norm to be computed, its data type is float32 or float64. Default: 2.
698+
name (str, optional): The default value is `None`. Normally there is no need for
699+
user to set this property. For more information, please refer to :ref:`api_guide_Name`.
698700
699701
Returns:
700702
Tensor: Tensor that is the p-norm of (x - y).

python/paddle/tensor/search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def nonzero(x, as_tuple=False):
384384
385385
Args:
386386
x (Tensor): The input tensor variable.
387-
as_tuple (bool): Return type, Tensor or tuple of Tensor.
387+
as_tuple (bool, optional): Return type, Tensor or tuple of Tensor.
388388
389389
Returns:
390390
Tensor. The data type is int64.

python/paddle/tensor/stat.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,11 @@ def std(x, axis=None, unbiased=True, keepdim=False, name=None):
206206
x = paddle.to_tensor([[1.0, 2.0, 3.0], [1.0, 4.0, 5.0]])
207207
out1 = paddle.std(x)
208208
# [1.63299316]
209-
out2 = paddle.std(x, axis=1)
209+
out2 = paddle.std(x, unbiased=False)
210+
# [1.49071205]
211+
out3 = paddle.std(x, axis=1)
210212
# [1. 2.081666]
213+
211214
"""
212215
if not paddle.in_dynamic_mode():
213216
check_variable_and_dtype(x, 'x', ['float32', 'float64'], 'std')

0 commit comments

Comments
 (0)