未验证 提交 aaa3ee65 编写于 作者: W wanghuancoder 提交者: GitHub

modify doc for unique_name.guard unique_name.generate unique_name.switch, test=develop (#27605)

上级 7ca66f1e
...@@ -97,9 +97,9 @@ def generate(key): ...@@ -97,9 +97,9 @@ def generate(key):
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid import paddle
name1 = fluid.unique_name.generate('fc') name1 = paddle.utils.unique_name.generate('fc')
name2 = fluid.unique_name.generate('fc') name2 = paddle.utils.unique_name.generate('fc')
print(name1, name2) # fc_0, fc_1 print(name1, name2) # fc_0, fc_1
""" """
return generator(key) return generator(key)
...@@ -154,19 +154,18 @@ def switch(new_generator=None, new_para_name_checker=None): ...@@ -154,19 +154,18 @@ def switch(new_generator=None, new_para_name_checker=None):
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid import paddle
name1 = fluid.unique_name.generate('fc') name1 = paddle.utils.unique_name.generate('fc')
name2 = fluid.unique_name.generate('fc') name2 = paddle.utils.unique_name.generate('fc')
print(name1, name2) # fc_0, fc_1 print(name1, name2) # fc_0, fc_1
pre_generator, pre_dygraph_name_checker = fluid.unique_name.switch() # switch to a new anonymous namespace. pre_generator, pre_dygraph_name_checker = paddle.utils.unique_name.switch() # switch to a new anonymous namespace.
name2 = fluid.unique_name.generate('fc') name2 = paddle.utils.unique_name.generate('fc')
print(name2) # fc_0 print(name2) # fc_0
fluid.unique_name.switch(pre_generator, pre_dygraph_name_checker) # switch back to pre_generator. paddle.utils.unique_name.switch(pre_generator, pre_dygraph_name_checker) # switch back to pre_generator.
name3 = fluid.unique_name.generate('fc') name3 = paddle.utils.unique_name.generate('fc')
print(name3) # fc_2, since pre_generator has generated fc_0, fc_1. print(name3) # fc_2, since pre_generator has generated fc_0, fc_1.
""" """
global generator global generator
old_generator = generator old_generator = generator
...@@ -204,17 +203,17 @@ def guard(new_generator=None): ...@@ -204,17 +203,17 @@ def guard(new_generator=None):
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid import paddle
with fluid.unique_name.guard(): with paddle.utils.unique_name.guard():
name_1 = fluid.unique_name.generate('fc') name_1 = paddle.utils.unique_name.generate('fc')
with fluid.unique_name.guard(): with paddle.utils.unique_name.guard():
name_2 = fluid.unique_name.generate('fc') name_2 = paddle.utils.unique_name.generate('fc')
print(name_1, name_2) # fc_0, fc_0 print(name_1, name_2) # fc_0, fc_0
with fluid.unique_name.guard('A'): with paddle.utils.unique_name.guard('A'):
name_1 = fluid.unique_name.generate('fc') name_1 = paddle.utils.unique_name.generate('fc')
with fluid.unique_name.guard('B'): with paddle.utils.unique_name.guard('B'):
name_2 = fluid.unique_name.generate('fc') name_2 = paddle.utils.unique_name.generate('fc')
print(name_1, name_2) # Afc_0, Bfc_0 print(name_1, name_2) # Afc_0, Bfc_0
""" """
if isinstance(new_generator, six.string_types): if isinstance(new_generator, six.string_types):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册