Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
308f6022
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
308f6022
编写于
1月 30, 2018
作者:
F
fengjiayi
提交者:
GitHub
1月 30, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #7945 from JiayiFeng/dev_debug_string_for_parameter
Refine debug string of Parameter
上级
f254d876
361bd296
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
131 addition
and
10 deletion
+131
-10
python/paddle/v2/fluid/clip.py
python/paddle/v2/fluid/clip.py
+24
-0
python/paddle/v2/fluid/framework.py
python/paddle/v2/fluid/framework.py
+96
-10
python/paddle/v2/fluid/regularizer.py
python/paddle/v2/fluid/regularizer.py
+11
-0
未找到文件。
python/paddle/v2/fluid/clip.py
浏览文件 @
308f6022
...
...
@@ -30,6 +30,9 @@ __all__ = [
class
BaseErrorClipAttr
(
object
):
def
__str__
(
self
):
raise
NotImplementedError
()
def
append_clip_op
(
self
,
block
,
grad_name
):
raise
NotImplementedError
()
...
...
@@ -44,6 +47,9 @@ class ErrorClipByValue(BaseErrorClipAttr):
self
.
max
=
max
self
.
min
=
min
def
__str__
(
self
):
return
"ByValue, min=%f, max=%f"
%
(
self
.
min
,
self
.
max
)
def
append_clip_op
(
self
,
block
,
grad_name
):
clip_op_desc
=
block
.
desc
.
append_op
()
clip_op_desc
.
set_type
(
"clip"
)
...
...
@@ -71,6 +77,9 @@ def error_clip_callback(block, context):
class
BaseGradientClipAttr
(
object
):
def
__str__
(
self
):
raise
NotImplementedError
()
def
process_context
(
self
,
context
,
param
,
grad
):
raise
NotImplementedError
()
...
...
@@ -79,6 +88,9 @@ class BaseGradientClipAttr(object):
class
NullGradientClipAttr
(
BaseGradientClipAttr
):
def
__str__
(
self
):
return
"Null"
def
process_context
(
self
,
context
,
param
,
grad
):
pass
...
...
@@ -96,6 +108,9 @@ class GradientClipByValue(BaseGradientClipAttr):
self
.
max
=
max
self
.
min
=
min
def
__str__
(
self
):
return
"ByValue, min=%f, max=%f"
%
(
self
.
min
,
self
.
max
)
def
process_context
(
self
,
context
,
param
,
grad
):
pass
...
...
@@ -108,6 +123,9 @@ class GradientClipByNorm(BaseGradientClipAttr):
def
__init__
(
self
,
clip_norm
):
self
.
clip_norm
=
clip_norm
def
__str__
(
self
):
return
"ByNorm, clip_norm=%f"
%
self
.
clip_norm
def
process_context
(
self
,
context
,
param
,
grad
):
pass
...
...
@@ -124,6 +142,10 @@ class GradientClipByGlobalNorm(BaseGradientClipAttr):
self
.
clip_norm
=
clip_norm
self
.
group_name
=
group_name
def
__str__
(
self
):
return
"ByGlobalNorm, group_name=%s, clip_norm=%f"
%
(
self
.
group_name
,
self
.
clip_norm
)
def
process_context
(
self
,
context
,
param
,
grad
):
if
self
.
group_name
not
in
context
:
context
[
self
.
group_name
]
=
[]
...
...
@@ -210,3 +232,5 @@ def append_gradient_clip_ops(param_grad):
ClipByValue
=
GradientClipByValue
ClipByNorm
=
GradientClipByNorm
ClipByGlobalNorm
=
GradientClipByGlobalNorm
python/paddle/v2/fluid/framework.py
浏览文件 @
308f6022
...
...
@@ -14,6 +14,7 @@
import
collections
import
contextlib
import
re
import
numpy
as
np
...
...
@@ -239,20 +240,30 @@ class Variable(object):
def
__str__
(
self
):
return
self
.
to_string
(
True
)
def
to_string
(
self
,
throw_on_error
):
def
to_string
(
self
,
throw_on_error
,
with_details
=
False
):
"""
Get debug string.
Args:
throw_on_error(bool): True if raise an exception when self is not
intialized.
with_details(bool): more details about variables and parameters
(e.g. trainable, optimize_attr, ...) will be printed when with_details is True
Returns(str): The debug string.
"""
assert
isinstance
(
throw_on_error
,
bool
)
and
isinstance
(
with_details
,
bool
)
protostr
=
self
.
desc
.
serialize_to_string
()
proto
=
framework_pb2
.
VarDesc
.
FromString
(
str
(
protostr
))
return
_debug_string_
(
proto
,
throw_on_error
)
res_str
=
_debug_string_
(
proto
,
throw_on_error
)
if
with_details
:
additional_attr
=
(
"error_clip"
,
"stop_gradient"
)
for
attr_name
in
additional_attr
:
res_str
+=
"%s: %s
\n
"
%
(
attr_name
,
str
(
getattr
(
self
,
attr_name
)))
return
res_str
__repr__
=
__str__
...
...
@@ -629,10 +640,36 @@ class Block(object):
def
__str__
(
self
):
return
self
.
to_string
(
True
)
def
to_string
(
self
,
throw_on_error
):
protostr
=
self
.
desc
.
serialize_to_string
()
proto
=
framework_pb2
.
BlockDesc
.
FromString
(
str
(
protostr
))
return
_debug_string_
(
proto
,
throw_on_error
)
def
to_string
(
self
,
throw_on_error
,
with_details
=
False
):
"""
To debug string.
Args:
throw_on_error(bool): raise exception when self is not initialized
when throw_on_error is True
with_details(bool): more details about variables and parameters
(e.g. trainable, optimize_attr, ...) will be printed when with_details is True
Returns(str): The debug string.
"""
assert
isinstance
(
throw_on_error
,
bool
)
and
isinstance
(
with_details
,
bool
)
if
with_details
:
re_add_indent
=
re
.
compile
(
r
"\n(.)"
)
res_str
=
"blocks {
\n
idx: %d
\n
parent_idx: %d"
%
(
self
.
idx
,
self
.
parent_idx
)
for
var
in
self
.
vars
.
itervalues
():
res_str
+=
"
\n
vars {
\n
%s }"
%
re_add_indent
.
sub
(
r
"\n \1"
,
var
.
to_string
(
throw_on_error
,
with_details
))
for
op
in
self
.
ops
:
res_str
+=
"
\n
ops {
\n
%s }"
%
re_add_indent
.
sub
(
r
"\n \1"
,
op
.
to_string
(
throw_on_error
))
res_str
+=
"
\n
}"
else
:
protostr
=
self
.
desc
.
serialize_to_string
()
proto
=
framework_pb2
.
BlockDesc
.
FromString
(
str
(
protostr
))
res_str
=
_debug_string_
(
proto
,
throw_on_error
)
return
res_str
__repr__
=
__str__
...
...
@@ -796,10 +833,29 @@ class Program(object):
def
__str__
(
self
):
return
self
.
to_string
(
True
)
def
to_string
(
self
,
throw_on_error
):
protostr
=
self
.
desc
.
serialize_to_string
()
proto
=
framework_pb2
.
ProgramDesc
.
FromString
(
str
(
protostr
))
return
_debug_string_
(
proto
,
throw_on_error
)
def
to_string
(
self
,
throw_on_error
,
with_details
=
False
):
"""
To debug string.
Args:
throw_on_error(bool): raise exception when self is not initialized
when throw_on_error is True
with_details(bool): more details about variables and parameters
(e.g. trainable, optimize_attr, ...) will be printed when with_details is True
Returns(str): The debug string.
"""
assert
isinstance
(
throw_on_error
,
bool
)
and
isinstance
(
with_details
,
bool
)
if
with_details
:
res_str
=
""
for
block
in
self
.
blocks
:
res_str
+=
block
.
to_string
(
throw_on_error
,
with_details
)
else
:
protostr
=
self
.
desc
.
serialize_to_string
()
proto
=
framework_pb2
.
ProgramDesc
.
FromString
(
str
(
protostr
))
res_str
=
_debug_string_
(
proto
,
throw_on_error
)
return
res_str
def
get_desc
(
self
):
return
self
.
desc
...
...
@@ -950,6 +1006,36 @@ class Parameter(Variable):
self
.
gradient_clip_attr
=
kwargs
.
get
(
'gradient_clip_attr'
,
None
)
def
__str__
(
self
):
return
self
.
to_string
(
True
)
def
to_string
(
self
,
throw_on_error
,
with_details
=
False
):
"""
To debug string.
Args:
throw_on_error(bool): raise exception when self is not initialized
when throw_on_error is True
with_details(bool): more details about variables and parameters
(e.g. trainable, optimize_attr, ...) will be printed when with_details is True
Returns(str): The debug string.
"""
assert
isinstance
(
throw_on_error
,
bool
)
and
isinstance
(
with_details
,
bool
)
if
with_details
:
res_str
=
Variable
.
to_string
(
self
,
throw_on_error
,
True
)
additional_attr
=
(
"trainable"
,
"optimize_attr"
,
"regularizer"
,
"gradient_clip_attr"
)
for
attr_name
in
additional_attr
:
res_str
+=
"%s: %s
\n
"
%
(
attr_name
,
str
(
getattr
(
self
,
attr_name
)))
else
:
res_str
=
Variable
.
to_string
(
self
,
throw_on_error
,
False
)
return
res_str
__repr__
=
__str__
# program is a global instance.
_main_program_
=
Program
()
...
...
python/paddle/v2/fluid/regularizer.py
浏览文件 @
308f6022
...
...
@@ -87,6 +87,11 @@ class WeightDecayRegularizer(object):
"""
raise
NotImplementedError
()
def
__str__
(
self
):
"""Debug string
"""
raise
NotImplementedError
()
class
L2DecayRegularizer
(
WeightDecayRegularizer
):
"""Implements the L2 Weight Decay Regularization
...
...
@@ -123,6 +128,9 @@ class L2DecayRegularizer(WeightDecayRegularizer):
return
decay
def
__str__
(
self
):
return
"L2Decay, regularization_coeff=%f"
%
self
.
_regularization_coeff
class
L1DecayRegularizer
(
WeightDecayRegularizer
):
"""Implements the L1 Weight Decay Regularization
...
...
@@ -163,6 +171,9 @@ class L1DecayRegularizer(WeightDecayRegularizer):
return
decay
def
__str__
(
self
):
return
"L1Decay, regularization_coeff=%f"
%
self
.
_regularization_coeff
# We short the class name, since users will use the regulaizer with the package
# name. The sample code:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录