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

modify some cn doc #2706

Closed
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
16 changes: 10 additions & 6 deletions doc/fluid/api_cn/fluid_cn/in_dygraph_mode_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
in_dygraph_mode
-------------------------------

.. py:function:: paddle.fluid.in_dygraph_mode()
.. py:function:: paddle.in_dynamic_mode()




该接口检查程序是否在动态图模式中运行。
从paddle2.0开始,默认开启动态图模式。
可以通过 ``fluid.dygraph.guard`` 接口开启动态图模式。

注意:
``paddle.in_dynamic_mode`` 是 ``fluid.in_dygraph_mode`` 的別名,
我们推荐使用 ``paddle.in_dynamic_mode。

返回:如果程序是在动态图模式下运行的,则返回 ``True``。

返回类型:bool
Expand All @@ -19,11 +24,10 @@ in_dygraph_mode

.. code-block:: python

import paddle.fluid as fluid
import paddle

fluid.enable_dygraph() # 现在进入 dygragh 模式
print(fluid.in_dygraph_mode()) # True
fluid.disable_dygraph()
print(fluid.in_dygraph_mode()) # False
print(paddle.in_dynamic_mode()) # True
paddle.enable_static()
print(paddle.in_dynamic_mode()) # False


12 changes: 6 additions & 6 deletions doc/fluid/api_cn/layers_cn/bilinear_tensor_product_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ bilinear_tensor_product
-------------------------------


.. py:function:: paddle.fluid.layers.bilinear_tensor_product(x, y, size, act=None, name=None, param_attr=None, bias_attr=None)
.. py:function:: paddle.static.nn.bilinear_tensor_product(x, y, size, act=None, name=None, param_attr=None, bias_attr=None)

:api_attr: 声明式编程模式(静态图)

Expand Down Expand Up @@ -41,11 +41,11 @@ bilinear_tensor_product

.. code-block:: python

import paddle.fluid as fluid
layer1 = fluid.layers.data("t1", shape=[-1, 5], dtype="float32")
layer2 = fluid.layers.data("t2", shape=[-1, 4], dtype="float32")
tensor = fluid.layers.bilinear_tensor_product(x=layer1, y=layer2, size=1000)

import paddle
paddle.enable_static()
layer1 = paddle.static.data("t1", shape=[-1, 5], dtype="float32")
layer2 = paddle.static.data("t2", shape=[-1, 4], dtype="float32")
tensor = paddle.static.nn.bilinear_tensor_product(x=layer1, y=layer2, size=1000)



11 changes: 5 additions & 6 deletions doc/fluid/api_cn/unique_name_cn/generate_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
generate
-------------------------------

.. py:function:: paddle.fluid.unique_name.generate(key)
.. py:function:: paddle.util.unique_name.generate(key)



Expand All @@ -21,9 +21,8 @@ generate

.. code-block:: python

import paddle.fluid as fluid
name1 = fluid.unique_name.generate('fc')
name2 = fluid.unique_name.generate('fc')
print(name1, name2) # fc_0, fc_1

import paddle
name1 = paddle.utils.unique_name.generate('fc')
name2 = paddle.utils.unique_name.generate('fc')
print(name1, name2) # fc_0, fc_1

26 changes: 13 additions & 13 deletions doc/fluid/api_cn/unique_name_cn/guard_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
guard
-------------------------------

.. py:function:: paddle.fluid.unique_name.guard(new_generator=None)
.. py:function:: paddle.util.unique_name.guard(new_generator=None)



Expand All @@ -19,17 +19,17 @@ guard

.. code-block:: python

import paddle.fluid as fluid
with fluid.unique_name.guard():
name_1 = fluid.unique_name.generate('fc')
with fluid.unique_name.guard():
name_2 = fluid.unique_name.generate('fc')
print(name_1, name_2) # fc_0, fc_0
with fluid.unique_name.guard('A'):
name_1 = fluid.unique_name.generate('fc')
with fluid.unique_name.guard('B'):
name_2 = fluid.unique_name.generate('fc')
print(name_1, name_2) # Afc_0, Bfc_0
import paddle
with paddle.utils.unique_name.guard():
name_1 = paddle.utils.unique_name.generate('fc')
with paddle.utils.unique_name.guard():
name_2 = paddle.utils.unique_name.generate('fc')
print(name_1, name_2) # fc_0, fc_0

with paddle.utils.unique_name.guard('A'):
name_1 = paddle.utils.unique_name.generate('fc')
with paddle.utils.unique_name.guard('B'):
name_2 = paddle.utils.unique_name.generate('fc')
print(name_1, name_2) # Afc_0, Bfc_0


26 changes: 13 additions & 13 deletions doc/fluid/api_cn/unique_name_cn/switch_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
switch
-------------------------------

.. py:function:: paddle.fluid.unique_name.switch(new_generator=None)
.. py:function:: paddle.util.unique_name.switch(new_generator=None)



Expand All @@ -21,15 +21,15 @@ switch

.. code-block:: python

import paddle.fluid as fluid
name1 = fluid.unique_name.generate('fc')
name2 = fluid.unique_name.generate('fc')
print(name1, name2) # fc_0, fc_1
pre_generator = fluid.unique_name.switch() # 切换到新命名空间
name2 = fluid.unique_name.generate('fc')
print(name2) # fc_0

fluid.unique_name.switch(pre_generator) # 切换回原命名空间
name3 = fluid.unique_name.generate('fc')
print(name3) # fc_2, 因为原命名空间已生成fc_0, fc_1
import paddle
name1 = paddle.utils.unique_name.generate('fc')
name2 = paddle.utils.unique_name.generate('fc')
print(name1, name2) # fc_0, fc_1

pre_generator, pre_dygraph_name_checker = paddle.utils.unique_name.switch() # switch to a new anonymous namespace.
name2 = paddle.utils.unique_name.generate('fc')
print(name2) # fc_0

paddle.utils.unique_name.switch(pre_generator, pre_dygraph_name_checker) # switch back to pre_generator.
name3 = paddle.utils.unique_name.generate('fc')
print(name3) # fc_2, since pre_generator has generated fc_0, fc_1
13 changes: 6 additions & 7 deletions doc/paddle/api/paddle/fluid/dygraph/container/LayerList_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@ LayerList用于保存子层列表,它包含的子层将被正确地注册和

.. code-block:: python

import paddle.fluid as fluid
import paddle
import numpy as np

class MyLayer(fluid.Layer):
class MyLayer(paddle.nn.Layer):
def __init__(self):
super(MyLayer, self).__init__()
self.linears = fluid.dygraph.LayerList(
[fluid.dygraph.Linear(10, 10) for i in range(10)])
self.linears = paddle.nn.LayerList(
[paddle.nn.Linear(10, 10) for i in range(10)])

def forward(self, x):
# LayerList可以像iterable一样迭代,也可以使用int索引
# LayerList can act as an iterable, or be indexed using ints
for i, l in enumerate(self.linears):
x = self.linears[i // 2](x) + l(x)
return x


44 changes: 22 additions & 22 deletions doc/paddle/api/paddle/fluid/dygraph/container/ParameterList_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ ParameterList

.. code-block:: python

import paddle.fluid as fluid
import paddle
import numpy as np

class MyLayer(fluid.Layer):
class MyLayer(paddle.nn.Layer):
def __init__(self, num_stacked_param):
super(MyLayer, self).__init__()
# 使用可迭代的 Parameters 创建 ParameterList
self.params = fluid.dygraph.ParameterList(
[fluid.layers.create_parameter(
# create ParameterList with iterable Parameters
self.params = paddle.nn.ParameterList(
[paddle.create_parameter(
shape=[2, 2], dtype='float32')] * num_stacked_param)

def forward(self, x):
for i, p in enumerate(self.params):
tmp = self._helper.create_variable_for_type_inference('float32')
Expand All @@ -38,25 +39,24 @@ ParameterList
"Y": p},
outputs={"Out": tmp},
attrs={"x_num_col_dims": 1,
"y_num_col_dims": 1})
"y_num_col_dims": 1})
x = tmp
return x

data_np = np.random.uniform(-1, 1, [5, 2]).astype('float32')
with fluid.dygraph.guard():
x = fluid.dygraph.to_variable(data_np)
num_stacked_param = 4
model = MyLayer(num_stacked_param)
print(len(model.params)) # 4
res = model(x)
print(res.shape) # [5, 2]
replaced_param = fluid.layers.create_parameter(shape=[2, 3], dtype='float32')
model.params[num_stacked_param - 1] = replaced_param # 替换最后一个参数
res = model(x)
print(res.shape) # [5, 3]
model.params.append(fluid.layers.create_parameter(shape=[3, 4], dtype='float32')) # 添加参数
print(len(model.params)) # 5
res = model(x)
print(res.shape) # [5, 4]

x = paddle.to_tensor(data_np)
num_stacked_param = 4
model = MyLayer(num_stacked_param)
print(len(model.params)) # 4
res = model(x)
print(res.shape) # [5, 2]

replaced_param = paddle.create_parameter(shape=[2, 3], dtype='float32')
model.params[num_stacked_param - 1] = replaced_param # replace last param
res = model(x)
print(res.shape) # [5, 3]
model.params.append(paddle.create_parameter(shape=[3, 4], dtype='float32')) # append param
print(len(model.params)) # 5
res = model(x)
print(res.shape) # [5, 4]

38 changes: 19 additions & 19 deletions doc/paddle/api/paddle/fluid/dygraph/container/Sequential_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Sequential
-------------------------------

.. py:class:: paddle.fluid.dygraph.Sequential(*layers)
.. py:class:: paddle.nn.Sequential(*layers)



Expand All @@ -19,24 +19,24 @@ Sequential

.. code-block:: python

import paddle.fluid as fluid
import paddle
import numpy as np
data = np.random.uniform(-1, 1, [30, 10]).astype('float32')
with fluid.dygraph.guard():
data = fluid.dygraph.to_variable(data)
# 使用 iterable Layers 创建 Sequential 容器
model1 = fluid.dygraph.Sequential(
fluid.Linear(10, 1), fluid.Linear(1, 2)
)
model1[0] # 访问第一个子层
res1 = model1(data) # 顺序执行
# 使用 iterable name Layer 对创建 Sequential 容器
model2 = fluid.dygraph.Sequential(
('l1', fluid.Linear(10, 2)),
('l2', fluid.Linear(2, 3))
)
model2['l1'] # 访问 l1 子层
model2.add_sublayer('l3', fluid.Linear(3, 3)) # 添加子层
res2 = model2(data) # 顺序执行

data = np.random.uniform(-1, 1, [30, 10]).astype('float32')
data = paddle.to_tensor(data)
# create Sequential with iterable Layers
model1 = paddle.nn.Sequential(
paddle.nn.Linear(10, 1), paddle.nn.Linear(1, 2)
)
model1[0] # access the first layer
res1 = model1(data) # sequential execution

# create Sequential with name Layer pairs
model2 = paddle.nn.Sequential(
('l1', paddle.nn.Linear(10, 2)),
('l2', paddle.nn.Linear(2, 3))
)
model2['l1'] # access l1 layer
model2.add_sublayer('l3', paddle.nn.Linear(3, 3)) # add sublayer
res2 = model2(data) # sequential execution