Skip to content
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
42 changes: 28 additions & 14 deletions python/paddle/fluid/dygraph/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,31 @@ def enabled():

def enable_dygraph(place=None):
"""
This function enables dynamic graph mode.

.. note::
Dynamic graph mode is turn ON by default since paddle 2.0.0

This API turn OFF static graph mode. You can turn ON static graph mode by `enable_static <./disable_dygraph_en.html>`_ .

Parameters:
place(fluid.CPUPlace or fluid.CUDAPlace, optional): Place to execute dygraph.
If None, the running place will be determined according to the way of paddle compilation. Default: None
place(paddle.CPUPlace|paddle.CUDAPlace, optional): Place to run dynamic graph. Default: None. Which means that the running place will be
determined according to the way of paddle compilation.

return:
None

Examples:
.. 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

paddle.disable_static()
print(paddle.in_dynamic_mode()) # True, Now we are in dynamic mode

fluid.enable_dygraph() # Now we are in dygragh mode
print(fluid.in_dygraph_mode()) # True
fluid.disable_dygraph()
print(fluid.in_dygraph_mode()) # False
"""
global _functional_dygraph_context_manager
if _functional_dygraph_context_manager is None:
Expand All @@ -147,20 +154,27 @@ def enable_dygraph(place=None):

def disable_dygraph():
"""
This function disables dynamic graph mode.

.. note::
Dynamic graph mode is turn ON by default since paddle 2.0.0

This API turn ON static graph mode. You can turn ON static graph mode by `disable_static <./enable_dygraph_en.html>`_ .

return:
None

Examples:
.. 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

paddle.disable_static()
print(paddle.in_dynamic_mode()) # True, Now we are in dynamic mode

fluid.enable_dygraph() # Now we are in dygragh mode
print(fluid.in_dygraph_mode()) # True
fluid.disable_dygraph()
print(fluid.in_dygraph_mode()) # False
"""
global _functional_dygraph_context_manager
if _functional_dygraph_context_manager is not None:
Expand Down
29 changes: 16 additions & 13 deletions python/paddle/fluid/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,27 +180,30 @@ def version_cmp(ver_a, ver_b):

def in_dygraph_mode():
"""
:alias_main: paddle.in_dygraph_mode
:alias: paddle.in_dygraph_mode
:old_api: paddle.fluid.framework.in_dygraph_mode

This function checks whether the program runs in dynamic graph mode or not.
You can enter dynamic graph mode with :ref:`api_fluid_dygraph_guard` api,
or enable and disable dynamic graph mode with :ref:`api_fluid_dygraph_enable`
and :ref:`api_fluid_dygraph_disable` api .
.. note::
Dynamic graph mode is turn ON by default since paddle 2.0.0

This API checks whether paddle runs in dynamic graph mode.

You can turn ON static graph mode by `enable_static <../dygraph/base/disable_dygraph_en.html>`_ ,
and turn OFF static graph mode by `disable_static <../dygraph/base/enable_dygraph_en.html>`_ .

Returns:
bool: Whether the program is running in dynamic graph mode.
bool: Whether paddle runs in dynamic graph mode.

Examples:
.. 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

paddle.disable_static()
print(paddle.in_dynamic_mode()) # True, Now we are in dynamic mode

fluid.enable_dygraph() # Now we are in dygragh mode
print(fluid.in_dygraph_mode()) # True
fluid.disable_dygraph()
print(fluid.in_dygraph_mode()) # False
"""
return _dygraph_tracer_ is not None

Expand Down