Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
2e4c0bd2
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
694
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2e4c0bd2
编写于
5月 19, 2017
作者:
Y
Yibing Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enable global gradient_clipping_threshold
correct a typo optimize code fix a bug
上级
285bee54
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
42 addition
and
8 deletion
+42
-8
paddle/parameter/FirstOrderOptimizer.cpp
paddle/parameter/FirstOrderOptimizer.cpp
+24
-6
paddle/parameter/OptimizerWithRegularizer.cpp
paddle/parameter/OptimizerWithRegularizer.cpp
+2
-1
paddle/parameter/ParameterOptimizer.h
paddle/parameter/ParameterOptimizer.h
+10
-0
proto/TrainerConfig.proto
proto/TrainerConfig.proto
+3
-0
python/paddle/trainer/config_parser.py
python/paddle/trainer/config_parser.py
+1
-0
python/paddle/trainer_config_helpers/optimizers.py
python/paddle/trainer_config_helpers/optimizers.py
+2
-1
未找到文件。
paddle/parameter/FirstOrderOptimizer.cpp
浏览文件 @
2e4c0bd2
...
@@ -161,6 +161,7 @@ void AdaDeltaParameterOptimizer::update(const VectorPtr vecs[],
...
@@ -161,6 +161,7 @@ void AdaDeltaParameterOptimizer::update(const VectorPtr vecs[],
const
ParameterConfig
&
config
,
const
ParameterConfig
&
config
,
size_t
sparseId
)
const
{
size_t
sparseId
)
const
{
CHECK
(
sparseId
==
-
1LU
)
<<
"Sparse update is not supported"
;
CHECK
(
sparseId
==
-
1LU
)
<<
"Sparse update is not supported"
;
BaseMatrix
&
value
=
*
vecs
[
PARAMETER_VALUE
];
BaseMatrix
&
value
=
*
vecs
[
PARAMETER_VALUE
];
BaseMatrix
&
grad
=
*
vecs
[
PARAMETER_GRADIENT
];
BaseMatrix
&
grad
=
*
vecs
[
PARAMETER_GRADIENT
];
BaseMatrix
&
mom
=
*
vecs
[
PARAMETER_MOMENTUM
];
BaseMatrix
&
mom
=
*
vecs
[
PARAMETER_MOMENTUM
];
...
@@ -265,6 +266,7 @@ void AdamParameterOptimizer::update(const VectorPtr vecs[],
...
@@ -265,6 +266,7 @@ void AdamParameterOptimizer::update(const VectorPtr vecs[],
const
ParameterConfig
&
config
,
const
ParameterConfig
&
config
,
size_t
sparseId
)
const
{
size_t
sparseId
)
const
{
CHECK
(
sparseId
==
-
1UL
)
<<
"Sparse update is not supported"
;
CHECK
(
sparseId
==
-
1UL
)
<<
"Sparse update is not supported"
;
real
beta1_power
=
std
::
pow
(
beta1_
,
step_
);
real
beta1_power
=
std
::
pow
(
beta1_
,
step_
);
real
beta2_power
=
std
::
pow
(
beta2_
,
step_
);
real
beta2_power
=
std
::
pow
(
beta2_
,
step_
);
real
learningRate
=
config
.
learning_rate
()
*
learningRate_
;
real
learningRate
=
config
.
learning_rate
()
*
learningRate_
;
...
@@ -303,18 +305,34 @@ void AdamaxParameterOptimizer::update(const VectorPtr vecs[],
...
@@ -303,18 +305,34 @@ void AdamaxParameterOptimizer::update(const VectorPtr vecs[],
void
OptimizerWithGradientClipping
::
update
(
const
VectorPtr
vecs
[],
void
OptimizerWithGradientClipping
::
update
(
const
VectorPtr
vecs
[],
const
ParameterConfig
&
config
,
const
ParameterConfig
&
config
,
size_t
sparseId
)
const
{
size_t
sparseId
)
const
{
// globalGradientClipping(vecs, config, FLAGS_log_clipping);
real
global_thres_
=
optConfig_
.
gradient_clipping_threshold
();
real
local_thres_
=
config
.
gradient_clipping_threshold
();
real
threshold
;
std
::
string
field
;
if
(
global_thres_
>
0.0
f
&&
local_thres_
>
0.0
f
)
{
threshold
=
global_thres_
<
local_thres_
?
global_thres_
:
local_thres_
;
field
=
global_thres_
<
local_thres_
?
"global"
:
"local"
;
}
else
if
(
global_thres_
>
0.0
f
)
{
threshold
=
global_thres_
;
field
=
"global"
;
}
else
{
threshold
=
local_thres_
;
field
=
"local"
;
}
real
maxAbsGrad
=
vecs
[
PARAMETER_GRADIENT
]
->
getAbsMax
();
real
maxAbsGrad
=
vecs
[
PARAMETER_GRADIENT
]
->
getAbsMax
();
if
(
maxAbsGrad
>
config
.
gradient_clipping_threshold
()
)
{
if
(
maxAbsGrad
>
threshold
)
{
if
(
FLAGS_log_clipping
)
{
if
(
FLAGS_log_clipping
)
{
real
avgAbsGrad
=
vecs
[
PARAMETER_GRADIENT
]
->
getAbsSum
()
/
real
avgAbsGrad
=
vecs
[
PARAMETER_GRADIENT
]
->
getAbsSum
()
/
vecs
[
PARAMETER_GRADIENT
]
->
getSize
();
vecs
[
PARAMETER_GRADIENT
]
->
getSize
();
LOG
(
INFO
)
<<
"parameter="
<<
config
.
name
()
<<
" need clipping,"
LOG
(
INFO
)
<<
"parameter="
<<
config
.
name
()
<<
" need clipping by "
<<
" max grad="
<<
maxAbsGrad
<<
" avg grad="
<<
avgAbsGrad
;
<<
field
<<
" threshold="
<<
threshold
<<
", max grad="
<<
maxAbsGrad
<<
", avg grad="
<<
avgAbsGrad
;
}
}
vecs
[
PARAMETER_GRADIENT
]
->
clip
(
-
config
.
gradient_clipping_threshold
(),
vecs
[
PARAMETER_GRADIENT
]
->
clip
(
-
threshold
,
threshold
);
config
.
gradient_clipping_threshold
());
}
}
optimizer_
->
update
(
vecs
,
config
,
sparseId
);
optimizer_
->
update
(
vecs
,
config
,
sparseId
);
}
}
...
...
paddle/parameter/OptimizerWithRegularizer.cpp
浏览文件 @
2e4c0bd2
...
@@ -131,7 +131,8 @@ ParameterOptimizer* OptimizerWithRegularizer::create(
...
@@ -131,7 +131,8 @@ ParameterOptimizer* OptimizerWithRegularizer::create(
bool
inPserver
)
{
bool
inPserver
)
{
ParameterOptimizer
*
optimizer
=
ParameterOptimizer
*
optimizer
=
ParameterOptimizer
::
create
(
optConfig
,
inPserver
);
ParameterOptimizer
::
create
(
optConfig
,
inPserver
);
if
(
paraConfig
.
gradient_clipping_threshold
()
>
0.0
f
&&
if
((
optConfig
.
gradient_clipping_threshold
()
>
0.0
f
||
paraConfig
.
gradient_clipping_threshold
()
>
0.0
f
)
&&
!
dynamic_cast
<
AddOptimizer
*>
(
optimizer
))
{
!
dynamic_cast
<
AddOptimizer
*>
(
optimizer
))
{
optimizer
=
new
OptimizerWithGradientClipping
(
optConfig
,
optimizer
);
optimizer
=
new
OptimizerWithGradientClipping
(
optConfig
,
optimizer
);
}
}
...
...
paddle/parameter/ParameterOptimizer.h
浏览文件 @
2e4c0bd2
...
@@ -167,8 +167,12 @@ public:
...
@@ -167,8 +167,12 @@ public:
}
}
parameterTypes_
.
push_back
(
type
);
parameterTypes_
.
push_back
(
type
);
}
}
real
getLearningRate
()
const
{
return
learningRate_
;
}
real
getLearningRate
()
const
{
return
learningRate_
;
}
// real getGradientClippingThreshold() const {return
// gradientClippingThreshold_;}
virtual
void
setNoDecay
()
{
applyDecay_
=
false
;
}
virtual
void
setNoDecay
()
{
applyDecay_
=
false
;
}
static
ParameterOptimizer
*
create
(
const
OptimizationConfig
&
optConfig
,
static
ParameterOptimizer
*
create
(
const
OptimizationConfig
&
optConfig
,
...
@@ -201,6 +205,12 @@ protected:
...
@@ -201,6 +205,12 @@ protected:
* so, if lr change in StartBatch, please assign to learningRate_
* so, if lr change in StartBatch, please assign to learningRate_
*/
*/
real
learningRate_
;
real
learningRate_
;
/**
* global threshold for gradient clipping,
* init value is opt_config.gradient_clipping_thresholod
*/
std
::
unique_ptr
<
LearningRateScheduler
>
learningRateScheduler_
;
std
::
unique_ptr
<
LearningRateScheduler
>
learningRateScheduler_
;
int64_t
pass_
;
// current training pass (starting from 0)
int64_t
pass_
;
// current training pass (starting from 0)
bool
firstTime_
;
bool
firstTime_
;
...
...
proto/TrainerConfig.proto
浏览文件 @
2e4c0bd2
...
@@ -128,6 +128,9 @@ message OptimizationConfig {
...
@@ -128,6 +128,9 @@ message OptimizationConfig {
// when async_lagged_grad_discard_ratio * num_gradient_servers commit passed,
// when async_lagged_grad_discard_ratio * num_gradient_servers commit passed,
// current async gradient will be discard silently.
// current async gradient will be discard silently.
optional
double
async_lagged_grad_discard_ratio
=
37
[
default
=
1.5
];
optional
double
async_lagged_grad_discard_ratio
=
37
[
default
=
1.5
];
// global threshold for gradient clipping
optional
double
gradient_clipping_threshold
=
38
[
default
=
0.0
];
};
};
message
TrainerConfig
{
message
TrainerConfig
{
...
...
python/paddle/trainer/config_parser.py
浏览文件 @
2e4c0bd2
...
@@ -3377,6 +3377,7 @@ settings = dict(
...
@@ -3377,6 +3377,7 @@ settings = dict(
algorithm
=
'async_sgd'
,
algorithm
=
'async_sgd'
,
async_lagged_grad_discard_ratio
=
1.5
,
async_lagged_grad_discard_ratio
=
1.5
,
learning_method
=
'momentum'
,
learning_method
=
'momentum'
,
gradient_clipping_threshold
=
None
,
num_batches_per_send_parameter
=
None
,
num_batches_per_send_parameter
=
None
,
num_batches_per_get_parameter
=
None
,
num_batches_per_get_parameter
=
None
,
center_parameter_update_method
=
None
,
center_parameter_update_method
=
None
,
...
...
python/paddle/trainer_config_helpers/optimizers.py
浏览文件 @
2e4c0bd2
...
@@ -408,7 +408,8 @@ def settings(batch_size,
...
@@ -408,7 +408,8 @@ def settings(batch_size,
args
=
[
args
=
[
'batch_size'
,
'learning_rate'
,
'learning_rate_decay_a'
,
'batch_size'
,
'learning_rate'
,
'learning_rate_decay_a'
,
'learning_rate_decay_b'
,
'learning_rate_schedule'
,
'learning_rate_args'
'learning_rate_decay_b'
,
'learning_rate_schedule'
,
'learning_rate_args'
,
'gradient_clipping_threshold'
]
]
kwargs
=
dict
()
kwargs
=
dict
()
kwargs
[
'algorithm'
]
=
algorithm
kwargs
[
'algorithm'
]
=
algorithm
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录