Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix The first round of evaluation #47256 中文文档问题 #5409

Merged
merged 20 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/api/paddle/dist_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
dist
-------------------------------

.. py:function:: paddle.dist(x, y, p=2)
.. py:function:: paddle.dist(x, y, p=2, name=None)

计算 `(x-y)` 的 p 范数(p-norm),需要注意这不是严格意义上的范数,仅作为距离的度量。输入 `x` 和 `y` 的形状(shape)必须是可广播的(broadcastable)。其含义如下,详情请参考 `numpy 的广播概念 <https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html>`_ :
计算 `(x-y)` 的 p 范数(p-norm),需要注意这不是严格意义上的范数,仅作为距离的度量。输入 `x` 和 `y` 的形状(shape)必须是可广播的(broadcastable)。其含义如下,详情请参考 `Tensor 的广播机制 <../../guides/beginner/tensor_cn.html#id7>`_ :

- 每个输入都至少有 1 维
- 对两个输入的维度从后向前匹配,两个输入每一维的大小需要满足 3 个条件中的任意一个:相等、其中一个为 1 或者其中一个不存在。
Expand Down Expand Up @@ -53,6 +53,7 @@ z (4-D Tensor): 8 x 7 x 6 x 5
- **x** (Tensor) - 1-D 到 6-D Tensor,数据类型为 float32 或 float64。
- **y** (Tensor) - 1-D 到 6-D Tensor,数据类型为 float32 或 float64。
- **p** (float,可选) - 用于设置需要计算的范数,数据类型为 float32 或 float64。默认值为 2。
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为 None。



Expand Down
24 changes: 22 additions & 2 deletions docs/api/paddle/load_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,27 @@ load
:::::::::
Object,一个可以在 paddle 中使用的对象实例。

代码示例
代码示例 1
:::::::::

COPY-FROM: paddle.load
COPY-FROM: paddle.load:code-example-1

代码示例 2
:::::::::

COPY-FROM: paddle.load:code-example-2

代码示例 3
:::::::::

COPY-FROM: paddle.load:code-example-3

代码示例 4
:::::::::

COPY-FROM: paddle.load:code-example-4

代码示例 5
:::::::::

COPY-FROM: paddle.load:code-example-5
87 changes: 14 additions & 73 deletions docs/api/paddle/save_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,86 +35,27 @@ save
:::::::::

代码示例
代码示例 1
:::::::::

.. code-block:: python
COPY-FROM: paddle.save:code-example-1

# example 1: dynamic graph
import paddle
emb = paddle.nn.Embedding(10, 10)
layer_state_dict = emb.state_dict()

# save state_dict of emb
paddle.save(layer_state_dict, "emb.pdparams")

scheduler = paddle.optimizer.lr.NoamDecay(
d_model=0.01, warmup_steps=100, verbose=True)
adam = paddle.optimizer.Adam(
learning_rate=scheduler,
parameters=emb.parameters())
opt_state_dict = adam.state_dict()

# save state_dict of optimizer
paddle.save(opt_state_dict, "adam.pdopt")
# save weight of emb
paddle.save(emb.weight, "emb.weight.pdtensor")


.. code-block:: python

# example 2: Save multiple state_dict at the same time
import paddle
from paddle import nn
from paddle.optimizer import Adam

layer = paddle.nn.Linear(3, 4)
adam = Adam(learning_rate=0.001, parameters=layer.parameters())
obj = {'model': layer.state_dict(), 'opt': adam.state_dict(), 'epoch': 100}
path = 'example/model.pdparams'
paddle.save(obj, path)


.. code-block:: python

# example 3: static graph
import paddle
import paddle.static as static

paddle.enable_static()

# create network
x = paddle.static.data(name="x", shape=[None, 224], dtype='float32')
z = paddle.static.nn.fc(x, 10)

place = paddle.CPUPlace()
exe = paddle.static.Executor(place)
exe.run(paddle.static.default_startup_program())
prog = paddle.static.default_main_program()
for var in prog.list_vars():
if list(var.shape) == [224, 10]:
tensor = var.get_value()
break
代码示例 2
:::::::::

# save/load tensor
path_tensor = 'temp/tensor.pdtensor'
paddle.save(tensor, path_tensor)
COPY-FROM: paddle.save:code-example-2

# save/load state_dict
path_state_dict = 'temp/model.pdparams'
paddle.save(prog.state_dict("param"), path_tensor)
代码示例 3
:::::::::

COPY-FROM: paddle.save:code-example-3

.. code-block:: python
代码示例 4
:::::::::

# example 4: save program
import paddle
COPY-FROM: paddle.save:code-example-4

paddle.enable_static()
代码示例 5
:::::::::

data = paddle.static.data(
name='x_static_save', shape=(None, 224), dtype='float32')
y_static = z = paddle.static.nn.fc(data, 10)
main_program = paddle.static.default_main_program()
path = "example/main_program.pdmodel"
paddle.save(main_program, path)
COPY-FROM: paddle.save:code-example-5