Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
36 changes: 17 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,22 @@ 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 = 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

18 changes: 10 additions & 8 deletions doc/paddle/api/paddle/fluid/framework/in_dygraph_mode_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
in_dygraph_mode
-------------------------------

.. py:function:: paddle.fluid.in_dygraph_mode()
.. py:function:: paddle.in_dynamic_mode()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个文件周威已经更新了 PR 2703

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的,我回滚了我的修改。





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

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

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

Expand All @@ -19,11 +23,9 @@ in_dygraph_mode

.. code-block:: python

import paddle.fluid as fluid

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

print(paddle.in_dynamic_mode()) # True
paddle.enable_static()
print(paddle.in_dynamic_mode()) # False

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)



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

.. code-block:: python

import paddle.fluid as fluid
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

返回类型 和 返回写在一起哈,如
【返回:Variable,一个xxx】

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done,thx!

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/paddle/api/paddle/fluid/unique_name/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.utils.unique_name.generate(key)



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

.. code-block:: python
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

返回类型同上

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done,thx!


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

27 changes: 13 additions & 14 deletions doc/paddle/api/paddle/fluid/unique_name/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.utils.unique_name.guard(new_generator=None)



Expand All @@ -19,17 +19,16 @@ 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/paddle/api/paddle/fluid/unique_name/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.utils.unique_name.switch(new_generator=None)



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

.. code-block:: python
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

返回类型同上

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done,thx!


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.