diff --git a/doc/paddle/api/paddle/fluid/dygraph/base/disable_dygraph_cn.rst b/doc/paddle/api/paddle/fluid/dygraph/base/disable_dygraph_cn.rst index 59dc22b7b49..6655166c7f5 100644 --- a/doc/paddle/api/paddle/fluid/dygraph/base/disable_dygraph_cn.rst +++ b/doc/paddle/api/paddle/fluid/dygraph/base/disable_dygraph_cn.rst @@ -1,22 +1,27 @@ -.. _cn_api_fluid_disable_dygraph: +.. _cn_api_paddle_enable_static: -disable_dygraph +enable_static ------------------------------- -.. py:function:: paddle.fluid.disable_dygraph() +.. py:function:: paddle.enable_static() + +.. note:: + 从2.0.0版本开始,Paddle默认开启动态图模式。 + +该接口开启静态图模式。可通过 :ref:`cn_api_paddle_disable_static` 关闭静态图模式。 -该接口关闭动态图模式。 返回:无 -**示例代码** +**代码示例** .. code-block:: python - import paddle.fluid as fluid - import numpy as np - fluid.enable_dygraph() # Now we are in dygraph mode - print(fluid.in_dygraph_mode()) # True - fluid.disable_dygraph() - print(fluid.in_dygraph_mode()) # False + import paddle + print(paddle.in_dynamic_mode()) # True, dynamic mode is turn ON by default since paddle 2.0.0 + + paddle.enable_static() + print(paddle.in_dynamic_mode()) # False, Now we are in static mode + paddle.disable_static() + print(paddle.in_dynamic_mode()) # True, Now we are in dynamic mode diff --git a/doc/paddle/api/paddle/fluid/dygraph/base/enable_dygraph_cn.rst b/doc/paddle/api/paddle/fluid/dygraph/base/enable_dygraph_cn.rst index 0df485bd856..1db8c794080 100644 --- a/doc/paddle/api/paddle/fluid/dygraph/base/enable_dygraph_cn.rst +++ b/doc/paddle/api/paddle/fluid/dygraph/base/enable_dygraph_cn.rst @@ -1,25 +1,31 @@ -.. _cn_api_fluid_enable_dygraph: +.. _cn_api_paddle_disable_static: -enable_dygraph +disable_static ------------------------------- -.. py:function:: paddle.fluid.enable_dygraph(place=None) +.. py:function:: paddle.disable_static(place=None) + +.. note:: + 从2.0.0版本开始,Paddle默认开启动态图模式。 + +该接口关闭静态图模式。可通过 :ref:`cn_api_paddle_enable_static` 开启静态图模式。 -该接口打开动态图模式。 参数: - - **place** (fluid.CPUPlace 或 fluid.CUDAPlace,可选) - 执行动态图的设备数目。若为None,则设备根据paddle的编译方式决定。默认值为 ``None``。 + - **place** (paddle.CPUPlace|paddle.CUDAPlace,可选) - 动态图运行时的设备。默认值为 ``None`` , 此时,会根据paddle的版本自动判断。 返回:无 -**示例代码** +**代码示例** .. code-block:: python - import paddle.fluid as fluid - import numpy as np - fluid.enable_dygraph() # Now we are in dygraph mode - print(fluid.in_dygraph_mode()) # True - fluid.disable_dygraph() - print(fluid.in_dygraph_mode()) # False + import paddle + print(paddle.in_dynamic_mode()) # True, dynamic mode is turn ON by default since paddle 2.0.0 + + paddle.enable_static() + print(paddle.in_dynamic_mode()) # False, Now we are in static mode + + paddle.disable_static() + print(paddle.in_dynamic_mode()) # True, Now we are in dynamic modes diff --git a/doc/paddle/api/paddle/fluid/dygraph/base/to_variable_cn.rst b/doc/paddle/api/paddle/fluid/dygraph/base/to_variable_cn.rst deleted file mode 100644 index 5472faa7762..00000000000 --- a/doc/paddle/api/paddle/fluid/dygraph/base/to_variable_cn.rst +++ /dev/null @@ -1,55 +0,0 @@ -.. _cn_api_fluid_dygraph_to_variable: - -to_variable -------------------------------- - - -.. py:function:: paddle.fluid.dygraph.to_variable(value, name=None, zero_copy=None) - - - - - -该函数实现从tuple、list、numpy\.ndarray、Variable、ComplexVariable 对象创建一个 ``Variable`` 类型的对象。 - - -参数: - - **value** (tuple|list|ndarray|Variable|Tensor|ComplexVariable) – 初始化的数据。可以是tuple、list、numpy\.ndarray、Variable、ComplexVariable。 - 维度可以为多维,数据类型为numpy\.{float16, float32, float64, int16, int32, int64, uint8, uint16}中的一种。 - - **name** (str, 可选) – 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 - - **zero_copy** (bool, 可选) – 是否与输入的numpy数组共享内存。此参数仅适用于CPUPlace,当它为None时将设置为True。默认值为None。 - - **dtype** (str, 可选) - 返回的 ``Variable`` 所需的数据类型。可以是 'bool','float16','float32','float64','int8','int16','int32','int64','uint8'。默认值: None。 - - -返回:如果 ``value`` 是tuple/list/numpy\.ndarray对象,返回对应numpy\.ndarray对象创建的 ``Tensor`` ;如果 ``value`` 是Variable对象,直接返回 ``value`` 。 - -返回类型:Variable - -**代码示例**: - -.. code-block:: python - - import numpy as np - import paddle.fluid as fluid - with fluid.dygraph.guard(fluid.CPUPlace()): - - x = np.ones([2, 2], np.float32) - y = fluid.dygraph.to_variable(x, zero_copy=False) - x[0][0] = -1 - y[0][0].numpy() # array([1.], dtype=float32) - - y = fluid.dygraph.to_variable(x) - x[0][0] = 0 - y[0][0].numpy() # array([0.], dtype=float32) - - c = np.array([2+1j, 2]) - z = fluid.dygraph.to_variable(c) - z.numpy() # array([2.+1.j, 2.+0.j]) - z.dtype # 'complex128' - - y = fluid.dygraph.to_variable([[0.1, 1.2], [2.2, 3.1], [4.9, 5.2]]) - y.shape # [3L, 2L] - y = fluid.dygraph.to_variable(((0.1, 1.2), (2.2, 3.1), (4.9, 5.2)), dtype='int32') - y.shape # [3L, 2L] - y.dtype # core.VarDesc.VarType.INT32 - 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..8d90c265ce8 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 @@ -1,29 +1,32 @@ -.. _cn_api_fluid_in_dygraph_mode: +.. _cn_api_paddle_in_dynamic_mode: -in_dygraph_mode +in_dynamic_mode ------------------------------- -.. py:function:: paddle.fluid.in_dygraph_mode() +.. py:function:: paddle.in_dynamic_mode() +.. note:: + 从2.0.0版本开始,Paddle默认开启动态图模式。 +该接口查看paddle当前是否在动态图模式中运行。 +可以通过 :ref:`cn_api_paddle_enable_static` 开启静态图模式, :ref:`cn_api_paddle_disable_static` 关闭静态图模式。 -该接口检查程序是否在动态图模式中运行。 -可以通过 ``fluid.dygraph.guard`` 接口开启动态图模式。 - -返回:如果程序是在动态图模式下运行的,则返回 ``True``。 +返回:如果paddle当前是在动态图模式运行,则返回 ``True`` ,否则返回 ``False`` 返回类型:bool -**示例代码** +**代码示例** .. code-block:: python - import paddle.fluid as fluid + import paddle + print(paddle.in_dynamic_mode()) # True, dynamic mode is turn ON by default since paddle 2.0.0 + + paddle.enable_static() + print(paddle.in_dynamic_mode()) # False, Now we are in static mode - fluid.enable_dygraph() # 现在进入 dygragh 模式 - print(fluid.in_dygraph_mode()) # True - fluid.disable_dygraph() - print(fluid.in_dygraph_mode()) # False + paddle.disable_static() + print(paddle.in_dynamic_mode()) # True, Now we are in dynamic mode