From 36a98db7650bda1bb93bf541bf8a91c0ec9a009c Mon Sep 17 00:00:00 2001 From: Wang Huan Date: Mon, 28 Sep 2020 05:11:41 +0000 Subject: [PATCH 1/5] modify some cn doc, test=develop --- .../fluid/dygraph/container/Sequential_cn.rst | 36 +++++++++---------- .../fluid/framework/in_dygraph_mode_cn.rst | 18 +++++----- .../layers/bilinear_tensor_product_cn.rst | 12 +++---- .../paddle/fluid/unique_name/generate_cn.rst | 11 +++--- .../api/paddle/fluid/unique_name/guard_cn.rst | 27 +++++++------- .../paddle/fluid/unique_name/switch_cn.rst | 26 +++++++------- 6 files changed, 64 insertions(+), 66 deletions(-) diff --git a/doc/paddle/api/paddle/fluid/dygraph/container/Sequential_cn.rst b/doc/paddle/api/paddle/fluid/dygraph/container/Sequential_cn.rst index b39b4a556aa..9af4e95ecd7 100644 --- a/doc/paddle/api/paddle/fluid/dygraph/container/Sequential_cn.rst +++ b/doc/paddle/api/paddle/fluid/dygraph/container/Sequential_cn.rst @@ -3,7 +3,7 @@ Sequential ------------------------------- -.. py:class:: paddle.fluid.dygraph.Sequential(*layers) +.. py:class:: paddle.nn.Sequential(*layers) @@ -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 diff --git a/doc/paddle/api/paddle/fluid/framework/in_dygraph_mode_cn.rst b/doc/paddle/api/paddle/fluid/framework/in_dygraph_mode_cn.rst index 06c960ce5c3..dd9af96443d 100644 --- a/doc/paddle/api/paddle/fluid/framework/in_dygraph_mode_cn.rst +++ b/doc/paddle/api/paddle/fluid/framework/in_dygraph_mode_cn.rst @@ -3,13 +3,17 @@ in_dygraph_mode ------------------------------- -.. py:function:: paddle.fluid.in_dygraph_mode() +.. py:function:: paddle.in_dynamic_mode() 该接口检查程序是否在动态图模式中运行。 -可以通过 ``fluid.dygraph.guard`` 接口开启动态图模式。 +从paddle2.0开始,默认开启动态图模式。 + +注意: + ``paddle.in_dynamic_mode`` 是 ``fluid.in_dygraph_mode`` 的別名, + 我们推荐使用 ``paddle.in_dynamic_mode。 返回:如果程序是在动态图模式下运行的,则返回 ``True``。 @@ -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 diff --git a/doc/paddle/api/paddle/fluid/layers/bilinear_tensor_product_cn.rst b/doc/paddle/api/paddle/fluid/layers/bilinear_tensor_product_cn.rst index b8a01b3b0b3..1182e11e7b4 100644 --- a/doc/paddle/api/paddle/fluid/layers/bilinear_tensor_product_cn.rst +++ b/doc/paddle/api/paddle/fluid/layers/bilinear_tensor_product_cn.rst @@ -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) @@ -40,11 +40,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) diff --git a/doc/paddle/api/paddle/fluid/unique_name/generate_cn.rst b/doc/paddle/api/paddle/fluid/unique_name/generate_cn.rst index 4eb8a68c09b..5c63fc1667c 100644 --- a/doc/paddle/api/paddle/fluid/unique_name/generate_cn.rst +++ b/doc/paddle/api/paddle/fluid/unique_name/generate_cn.rst @@ -3,7 +3,7 @@ generate ------------------------------- -.. py:function:: paddle.fluid.unique_name.generate(key) +.. py:function:: paddle.utils.unique_name.generate(key) @@ -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 diff --git a/doc/paddle/api/paddle/fluid/unique_name/guard_cn.rst b/doc/paddle/api/paddle/fluid/unique_name/guard_cn.rst index 7c457eb1511..1bee4ba5010 100644 --- a/doc/paddle/api/paddle/fluid/unique_name/guard_cn.rst +++ b/doc/paddle/api/paddle/fluid/unique_name/guard_cn.rst @@ -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) @@ -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 diff --git a/doc/paddle/api/paddle/fluid/unique_name/switch_cn.rst b/doc/paddle/api/paddle/fluid/unique_name/switch_cn.rst index 93da7cc1dd9..03fb89d2ef9 100644 --- a/doc/paddle/api/paddle/fluid/unique_name/switch_cn.rst +++ b/doc/paddle/api/paddle/fluid/unique_name/switch_cn.rst @@ -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) @@ -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. \ No newline at end of file From 84413dacfb3ed12a8cd1880005763026f5cf5827 Mon Sep 17 00:00:00 2001 From: Wang Huan Date: Tue, 29 Sep 2020 02:47:51 +0000 Subject: [PATCH 2/5] move unique_name to paddle.utils, test=develop --- doc/paddle/api/alias_api_mapping | 3 +++ doc/paddle/api/not_display_doc_list | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/paddle/api/alias_api_mapping b/doc/paddle/api/alias_api_mapping index 9216cd32944..29615cca60c 100644 --- a/doc/paddle/api/alias_api_mapping +++ b/doc/paddle/api/alias_api_mapping @@ -569,3 +569,6 @@ paddle.metric.metrics.Accuracy paddle.metric.Accuracy paddle.metric.metrics.Precision paddle.metric.Precision paddle.metric.metrics.Recall paddle.metric.Recall paddle.metric.metrics.Auc paddle.metric.Auc +paddle.fluid.unique_name.guard paddle.util.unique_name.guard +paddle.fluid.unique_name.switch paddle.util.unique_name.switch +paddle.fluid.unique_name.generate paddle.util.unique_name.generate \ No newline at end of file diff --git a/doc/paddle/api/not_display_doc_list b/doc/paddle/api/not_display_doc_list index cb197d73d13..a9423f46982 100644 --- a/doc/paddle/api/not_display_doc_list +++ b/doc/paddle/api/not_display_doc_list @@ -1,4 +1,3 @@ -paddle.utils paddle.incubate paddle.hapi.progressbar.ProgressBar paddle.fluid.contrib From 1a02835eab75e0ce7b6e314b5717db8ac15b5b87 Mon Sep 17 00:00:00 2001 From: Wang Huan Date: Tue, 29 Sep 2020 03:35:39 +0000 Subject: [PATCH 3/5] refine doc, test=develop --- .../fluid/framework/in_dygraph_mode_cn.rst | 18 ++++++++---------- .../layers/bilinear_tensor_product_cn.rst | 4 +--- .../paddle/fluid/unique_name/generate_cn.rst | 4 +--- .../api/paddle/fluid/unique_name/switch_cn.rst | 4 +--- 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/doc/paddle/api/paddle/fluid/framework/in_dygraph_mode_cn.rst b/doc/paddle/api/paddle/fluid/framework/in_dygraph_mode_cn.rst index dd9af96443d..06c960ce5c3 100644 --- a/doc/paddle/api/paddle/fluid/framework/in_dygraph_mode_cn.rst +++ b/doc/paddle/api/paddle/fluid/framework/in_dygraph_mode_cn.rst @@ -3,17 +3,13 @@ in_dygraph_mode ------------------------------- -.. py:function:: paddle.in_dynamic_mode() +.. py:function:: paddle.fluid.in_dygraph_mode() 该接口检查程序是否在动态图模式中运行。 -从paddle2.0开始,默认开启动态图模式。 - -注意: - ``paddle.in_dynamic_mode`` 是 ``fluid.in_dygraph_mode`` 的別名, - 我们推荐使用 ``paddle.in_dynamic_mode。 +可以通过 ``fluid.dygraph.guard`` 接口开启动态图模式。 返回:如果程序是在动态图模式下运行的,则返回 ``True``。 @@ -23,9 +19,11 @@ in_dygraph_mode .. code-block:: python - import paddle + import paddle.fluid as fluid + + 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 diff --git a/doc/paddle/api/paddle/fluid/layers/bilinear_tensor_product_cn.rst b/doc/paddle/api/paddle/fluid/layers/bilinear_tensor_product_cn.rst index 1182e11e7b4..d78a3118c3b 100644 --- a/doc/paddle/api/paddle/fluid/layers/bilinear_tensor_product_cn.rst +++ b/doc/paddle/api/paddle/fluid/layers/bilinear_tensor_product_cn.rst @@ -32,9 +32,7 @@ bilinear_tensor_product - **param_attr** (ParamAttr,可选) :指定权重参数属性的对象。默认值为 None,表示使用默认的权重参数属性。具体用法请参见 :ref:`cn_api_fluid_ParamAttr` 。 - **bias_attr** (ParamAttr,可选) : 指定偏置参数属性的对象。默认值为 None,表示使用默认的偏置参数属性。具体用法请参见 :ref:`cn_api_fluid_ParamAttr` 。 -返回: 一个形为 [batch_size, size] 的 2-D 张量。 - -返回类型:Variable +返回: Variable, 一个形为 [batch_size, size] 的 2-D 张量。 **代码示例:** diff --git a/doc/paddle/api/paddle/fluid/unique_name/generate_cn.rst b/doc/paddle/api/paddle/fluid/unique_name/generate_cn.rst index 5c63fc1667c..fef06fef75f 100644 --- a/doc/paddle/api/paddle/fluid/unique_name/generate_cn.rst +++ b/doc/paddle/api/paddle/fluid/unique_name/generate_cn.rst @@ -13,9 +13,7 @@ generate 参数: - **key** (str) - 产生的唯一名称的前缀。 -返回:含前缀key的唯一名称。 - -返回类型:str。 +返回:str, 含前缀key的唯一名称。 **代码示例** diff --git a/doc/paddle/api/paddle/fluid/unique_name/switch_cn.rst b/doc/paddle/api/paddle/fluid/unique_name/switch_cn.rst index 03fb89d2ef9..4f4970aa810 100644 --- a/doc/paddle/api/paddle/fluid/unique_name/switch_cn.rst +++ b/doc/paddle/api/paddle/fluid/unique_name/switch_cn.rst @@ -13,9 +13,7 @@ switch 参数: - **new_generator** (UniqueNameGenerator, 可选) - 要切换到的新命名空间,一般无需设置。缺省值为None,表示切换到一个匿名的新命名空间。 -返回:先前的命名空间,一般无需操作该返回值。 - -返回类型:UniqueNameGenerator。 +返回:UniqueNameGenerator, 先前的命名空间,一般无需操作该返回值。 **代码示例** From 62ed3bda4315412368dd11296ddfee0249336042 Mon Sep 17 00:00:00 2001 From: Wang Huan Date: Tue, 29 Sep 2020 03:56:56 +0000 Subject: [PATCH 4/5] fix alias tab, test=develop --- doc/paddle/api/alias_api_mapping | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/paddle/api/alias_api_mapping b/doc/paddle/api/alias_api_mapping index 29615cca60c..d1dc9120778 100644 --- a/doc/paddle/api/alias_api_mapping +++ b/doc/paddle/api/alias_api_mapping @@ -569,6 +569,6 @@ paddle.metric.metrics.Accuracy paddle.metric.Accuracy paddle.metric.metrics.Precision paddle.metric.Precision paddle.metric.metrics.Recall paddle.metric.Recall paddle.metric.metrics.Auc paddle.metric.Auc -paddle.fluid.unique_name.guard paddle.util.unique_name.guard -paddle.fluid.unique_name.switch paddle.util.unique_name.switch -paddle.fluid.unique_name.generate paddle.util.unique_name.generate \ No newline at end of file +paddle.fluid.unique_name.guard paddle.util.unique_name.guard +paddle.fluid.unique_name.switch paddle.util.unique_name.switch +paddle.fluid.unique_name.generate paddle.util.unique_name.generate \ No newline at end of file From ee5b6c0fb3a177a202210baa54c286a42d9953ee Mon Sep 17 00:00:00 2001 From: Wang Huan Date: Tue, 29 Sep 2020 05:19:13 +0000 Subject: [PATCH 5/5] fix alias bug, test=develop --- doc/paddle/api/alias_api_mapping | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/paddle/api/alias_api_mapping b/doc/paddle/api/alias_api_mapping index d1dc9120778..2273fb4b841 100644 --- a/doc/paddle/api/alias_api_mapping +++ b/doc/paddle/api/alias_api_mapping @@ -569,6 +569,6 @@ paddle.metric.metrics.Accuracy paddle.metric.Accuracy paddle.metric.metrics.Precision paddle.metric.Precision paddle.metric.metrics.Recall paddle.metric.Recall paddle.metric.metrics.Auc paddle.metric.Auc -paddle.fluid.unique_name.guard paddle.util.unique_name.guard -paddle.fluid.unique_name.switch paddle.util.unique_name.switch -paddle.fluid.unique_name.generate paddle.util.unique_name.generate \ No newline at end of file +paddle.fluid.unique_name.guard paddle.utils.unique_name.guard +paddle.fluid.unique_name.switch paddle.utils.unique_name.switch +paddle.fluid.unique_name.generate paddle.utils.unique_name.generate \ No newline at end of file