From ed14138601657378efc8aeead06a3fb2f6e75003 Mon Sep 17 00:00:00 2001 From: Wang Huan Date: Sun, 27 Sep 2020 06:36:23 +0000 Subject: [PATCH] modify doc for unique_name.guard unique_name.generate unique_name.switch, test=develop --- python/paddle/fluid/unique_name.py | 39 +++++++++++++++--------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/python/paddle/fluid/unique_name.py b/python/paddle/fluid/unique_name.py index 406baa9d7d6..9565dd74d83 100644 --- a/python/paddle/fluid/unique_name.py +++ b/python/paddle/fluid/unique_name.py @@ -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): -- GitLab