提交 f67fd716 编写于 作者: C cryoco

2.0 api unique_name

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