提交 f67fd716 编写于 作者: C cryoco

2.0 api unique_name

上级 a596f054
......@@ -3,7 +3,7 @@
generate
-------------------------------
.. py:function:: paddle.fluid.unique_name.generate(key)
.. py:function:: paddle.utils.unique_name.generate(key)
......@@ -21,9 +21,9 @@ generate
.. 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
......@@ -3,7 +3,7 @@
guard
-------------------------------
.. py:function:: paddle.fluid.unique_name.guard(new_generator=None)
.. py:function:: paddle.utils.unique_name.guard(new_generator=None)
......@@ -19,17 +19,17 @@ guard
.. 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
......@@ -3,7 +3,7 @@
switch
-------------------------------
.. py:function:: paddle.fluid.unique_name.switch(new_generator=None)
.. py:function:: paddle.utils.unique_name.switch(new_generator=None)
......@@ -21,15 +21,15 @@ switch
.. 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 = fluid.unique_name.switch() # 切换到新命名空间
name2 = fluid.unique_name.generate('fc')
pre_generator, pre_dygraph_name_checker = paddle.utils.unique_name.switch() # 切换到新命名空间
name2 = paddle.utils.unique_name.generate('fc')
print(name2) # fc_0
fluid.unique_name.switch(pre_generator) # 切换回原命名空间
name3 = fluid.unique_name.generate('fc')
paddle.utils.unique_name.switch(pre_generator, pre_dygraph_name_checker) # 切换回原命名空间
name3 = paddle.utils.unique_name.generate('fc')
print(name3) # fc_2, 因为原命名空间已生成fc_0, fc_1
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册