未验证 提交 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):
.. code-block:: python
import paddle.fluid as fluid
name1 = fluid.unique_name.generate('fc')
name2 = fluid.unique_name.generate('fc')
import paddle
name1 = paddle.utils.unique_name.generate('fc')
name2 = paddle.utils.unique_name.generate('fc')
print(name1, name2) # fc_0, fc_1
"""
return generator(key)
......@@ -154,19 +154,18 @@ def switch(new_generator=None, new_para_name_checker=None):
.. code-block:: python
import paddle.fluid as fluid
name1 = fluid.unique_name.generate('fc')
name2 = fluid.unique_name.generate('fc')
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 = fluid.unique_name.switch() # switch to a new anonymous namespace.
name2 = fluid.unique_name.generate('fc')
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
fluid.unique_name.switch(pre_generator, pre_dygraph_name_checker) # switch back to pre_generator.
name3 = fluid.unique_name.generate('fc')
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.
"""
global generator
old_generator = generator
......@@ -204,17 +203,17 @@ def guard(new_generator=None):
.. 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')
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 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')
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
"""
if isinstance(new_generator, six.string_types):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册