Skip to content

Commit

Permalink
modify doc for unique_name.guard unique_name.generate unique_name.swi…
Browse files Browse the repository at this point in the history
…tch, test=develop (#27605)
  • Loading branch information
wanghuancoder authored Oct 8, 2020
1 parent 7ca66f1 commit aaa3ee6
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions python/paddle/fluid/unique_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit aaa3ee6

Please sign in to comment.