Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
b9d12bde
P
Paddle
项目概览
PaddlePaddle
/
Paddle
12 个月 前同步成功
通知
2292
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b9d12bde
编写于
10月 11, 2019
作者:
L
Leo Chen
提交者:
Zeng Jinle
10月 11, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[cherry-pick] Polish en APIs of unique_name, test=release/1.6, test=document_fix (#20113) (#20455)
上级
732650e4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
45 addition
and
30 deletion
+45
-30
paddle/fluid/API.spec
paddle/fluid/API.spec
+3
-3
python/paddle/fluid/unique_name.py
python/paddle/fluid/unique_name.py
+42
-27
未找到文件。
paddle/fluid/API.spec
浏览文件 @
b9d12bde
...
...
@@ -1125,9 +1125,9 @@ paddle.fluid.profiler.reset_profiler (ArgSpec(args=[], varargs=None, keywords=No
paddle.fluid.profiler.profiler (ArgSpec(args=['state', 'sorted_key', 'profile_path'], varargs=None, keywords=None, defaults=(None, '/tmp/profile')), ('document', '8e8d777eb0127876d7bdb6c421db7f5c'))
paddle.fluid.profiler.start_profiler (ArgSpec(args=['state'], varargs=None, keywords=None, defaults=None), ('document', '9494b48e79a0e07b49017ba5a97800b6'))
paddle.fluid.profiler.stop_profiler (ArgSpec(args=['sorted_key', 'profile_path'], varargs=None, keywords=None, defaults=(None, '/tmp/profile')), ('document', '10406b144bd8b5e01ea44301219f7fef'))
paddle.fluid.unique_name.generate (ArgSpec(args=['key'], varargs=None, keywords=None, defaults=None), ('document', '
4d68cde4c4df8f1b8018620b4dc19b4
2'))
paddle.fluid.unique_name.switch (ArgSpec(args=['new_generator'], varargs=None, keywords=None, defaults=(None,)), ('document', '
695a6e91afbcdbafac69a069038811be
'))
paddle.fluid.unique_name.guard (ArgSpec(args=['new_generator'], varargs=None, keywords=None, defaults=(None,)), ('document', '
ead717d6d440a1eb11971695cd1727f4
'))
paddle.fluid.unique_name.generate (ArgSpec(args=['key'], varargs=None, keywords=None, defaults=None), ('document', '
16bbac2df5f02c65cf5100741cd2aeb
2'))
paddle.fluid.unique_name.switch (ArgSpec(args=['new_generator'], varargs=None, keywords=None, defaults=(None,)), ('document', '
d7a9f8dd00c6337ea298623cb9d63c39
'))
paddle.fluid.unique_name.guard (ArgSpec(args=['new_generator'], varargs=None, keywords=None, defaults=(None,)), ('document', '
b11ef0165c3f73d8dc73ec60dc988792
'))
paddle.fluid.Scope Scope() -> paddle.fluid.core_avx._Scope
paddle.fluid.install_check.run_check (ArgSpec(args=[], varargs=None, keywords=None, defaults=None), ('document', '66b7c84a17ed32fec2df9628367be2b9'))
paddle.fluid.save (ArgSpec(args=['program', 'model_path'], varargs=None, keywords=None, defaults=None), ('document', 'cef7d50c36b93c02b6d12bcea7d025ce'))
...
...
python/paddle/fluid/unique_name.py
浏览文件 @
b9d12bde
...
...
@@ -56,23 +56,24 @@ generator = UniqueNameGenerator()
def
generate
(
key
):
"""
Generate unique name with prefix key.
Generate unique name with prefix key. Currently, Paddle distinguishes the
names of the same key by numbering it from zero. For example, when key=fc,
it continuously generates fc_0, fc_1, fc_2, etc.
Args:
key(str): The generated name prefix. All generated name will be
started with this prefix.
Args:
key(str): The prefix of generated name.
Returns:
str: A unique string with the prefix key.
Examples:
Examples:
.. code-block:: python
import paddle.fluid as fluid
name1 = fluid.unique_name.generate('fc')
name2 = fluid.unique_name.generate('fc')
# The result is fc_0, fc_1
print name1, name2
print(name1, name2) # fc_0, fc_1
"""
return
generator
(
key
)
...
...
@@ -102,27 +103,36 @@ def generate_with_ignorable_key(key):
def
switch
(
new_generator
=
None
):
"""
Switch the Global namespace to a new namespace.
Switch the namespace of in current context to a new namespace. Though
:code:`switch()` and :code:`guard()` can both change namespace,
:code:`guard()` is recommended since it can manage the context better
together with :code:`with` statement.
Args:
new_generator(None|UniqueNameGenerator): A new UniqueNameGenerator.
Args:
new_generator(UniqueNameGenerator, optional): A new UniqueNameGenerator, not
required normally. Default is None, which means switch to a new anonymous
namespace.
Returns:
UniqueNameGenerator: The previous UniqueNameGenerator.
Examples:
Examples:
.. code-block:: python
import paddle.fluid as fluid
name1 = fluid.unique_name.generate('fc')
name2 = fluid.unique_name.generate('fc')
# The result is fc_0, fc_1
print name1, name2
print(name1, name2) # fc_0, fc_1
fluid.unique_name.switch()
pre_generator = fluid.unique_name.switch() # switch to a new anonymous namespace.
name2 = fluid.unique_name.generate('fc')
# The result is fc_0
print name2
print(name2) # fc_0
fluid.unique_name.switch(pre_generator) # switch back to pre_generator.
name3 = fluid.unique_name.generate('fc')
print(name3) # fc_2, since pre_generator has generated fc_0, fc_1.
"""
global
generator
old
=
generator
...
...
@@ -136,14 +146,21 @@ def switch(new_generator=None):
@
signature_safe_contextmanager
def
guard
(
new_generator
=
None
):
"""
Change the global namespace with `with` statement.
Change the namespace of unique name with :code:`with` statement. After calling it,
a new namespace in the context of :code:`with` will be created, and it will number
names from zero again when calling :code:`generate()` with same key.
Args:
new_generator(str|bytes, optional): New name of global namespace. Note that str
in Python2 was spilted into str and bytes in Python3, so here are two
types. Default is None. If not None, new_generator will be added into
the prefix of unique name generated by :code:`generate()`.
Arg
s:
new_generator(None|str|bytes): New name of global namespac
e.
Note that str in Python2 was spilted into str and bytes in Python3,
so here are two types. Default is None.
Return
s:
Non
e.
Examples:
Examples:
.. code-block:: python
import paddle.fluid as fluid
...
...
@@ -151,15 +168,13 @@ def guard(new_generator=None):
name_1 = fluid.unique_name.generate('fc')
with fluid.unique_name.guard():
name_2 = fluid.unique_name.generate('fc')
# The result is fc_0, fc_0
print name_1, name_2
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')
# The result is Afc_0, Bfc_0
print name_1, name_2
name_2 = fluid.unique_name.generate('fc')
print(name_1, name_2) # Afc_0, Bfc_0
"""
if
isinstance
(
new_generator
,
six
.
string_types
):
new_generator
=
UniqueNameGenerator
(
new_generator
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录