Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
c22803f2
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
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看板
未验证
提交
c22803f2
编写于
12月 14, 2022
作者:
W
Wenyu
提交者:
GitHub
12月 14, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
upgrade adamw for new paddle version (#7507)
上级
1a336e5f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
54 addition
and
26 deletion
+54
-26
ppdet/optimizer/adamw.py
ppdet/optimizer/adamw.py
+54
-26
未找到文件。
ppdet/optimizer/adamw.py
浏览文件 @
c22803f2
...
@@ -16,10 +16,15 @@ from __future__ import absolute_import
...
@@ -16,10 +16,15 @@ from __future__ import absolute_import
from
__future__
import
division
from
__future__
import
division
from
__future__
import
print_function
from
__future__
import
print_function
import
paddle
from
paddle.optimizer
import
AdamW
from
paddle.optimizer
import
AdamW
from
functools
import
partial
from
functools
import
partial
import
re
import
re
IS_PADDLE_LATER_2_4
=
(
int
(
paddle
.
version
.
major
)
>=
2
and
int
(
paddle
.
version
.
minor
)
>=
4
)
or
int
(
paddle
.
version
.
major
)
==
0
def
layerwise_lr_decay
(
decay_rate
,
name_dict
,
n_layers
,
param
):
def
layerwise_lr_decay
(
decay_rate
,
name_dict
,
n_layers
,
param
):
"""
"""
...
@@ -48,7 +53,10 @@ def layerwise_lr_decay(decay_rate, name_dict, n_layers, param):
...
@@ -48,7 +53,10 @@ def layerwise_lr_decay(decay_rate, name_dict, n_layers, param):
elif
'cls_token'
in
static_name
or
'patch_embed'
in
static_name
:
elif
'cls_token'
in
static_name
or
'patch_embed'
in
static_name
:
ratio
=
decay_rate
**
(
n_layers
+
1
)
ratio
=
decay_rate
**
(
n_layers
+
1
)
param
.
optimize_attr
[
'learning_rate'
]
*=
ratio
if
IS_PADDLE_LATER_2_4
:
return
ratio
else
:
param
.
optimize_attr
[
'learning_rate'
]
*=
ratio
class
AdamWDL
(
AdamW
):
class
AdamWDL
(
AdamW
):
...
@@ -172,31 +180,51 @@ class AdamWDL(AdamW):
...
@@ -172,31 +180,51 @@ class AdamWDL(AdamW):
self
.
set_param_lr_func
=
partial
(
self
.
set_param_lr_func
=
partial
(
set_param_lr_func
,
layerwise_decay
,
name_dict
,
set_param_lr_func
,
layerwise_decay
,
name_dict
,
n_layers
)
if
set_param_lr_func
is
not
None
else
set_param_lr_func
n_layers
)
if
set_param_lr_func
is
not
None
else
set_param_lr_func
super
(
AdamWDL
,
self
).
__init__
(
learning_rate
=
learning_rate
,
if
IS_PADDLE_LATER_2_4
:
parameters
=
parameters
,
super
(
AdamWDL
,
self
).
__init__
(
beta1
=
beta1
,
learning_rate
=
learning_rate
,
beta2
=
beta2
,
parameters
=
parameters
,
epsilon
=
epsilon
,
beta1
=
beta1
,
grad_clip
=
grad_clip
,
beta2
=
beta2
,
name
=
name
,
epsilon
=
epsilon
,
apply_decay_param_fun
=
apply_decay_param_fun
,
grad_clip
=
grad_clip
,
weight_decay
=
weight_decay
,
name
=
name
,
lazy_mode
=
lazy_mode
,
apply_decay_param_fun
=
apply_decay_param_fun
,
multi_precision
=
multi_precision
)
weight_decay
=
weight_decay
,
lazy_mode
=
lazy_mode
,
def
_append_optimize_op
(
self
,
block
,
param_and_grad
):
multi_precision
=
multi_precision
,
if
self
.
set_param_lr_func
is
None
:
lr_ratio
=
self
.
set_param_lr_func
)
return
super
(
AdamWDL
,
self
).
_append_optimize_op
(
block
,
else
:
param_and_grad
)
super
(
AdamWDL
,
self
).
__init__
(
learning_rate
=
learning_rate
,
self
.
_append_decoupled_weight_decay
(
block
,
param_and_grad
)
parameters
=
parameters
,
prev_lr
=
param_and_grad
[
0
].
optimize_attr
[
"learning_rate"
]
beta1
=
beta1
,
self
.
set_param_lr_func
(
param_and_grad
[
0
])
beta2
=
beta2
,
# excute Adam op
epsilon
=
epsilon
,
res
=
super
(
AdamW
,
self
).
_append_optimize_op
(
block
,
param_and_grad
)
grad_clip
=
grad_clip
,
param_and_grad
[
0
].
optimize_attr
[
"learning_rate"
]
=
prev_lr
name
=
name
,
return
res
apply_decay_param_fun
=
apply_decay_param_fun
,
weight_decay
=
weight_decay
,
lazy_mode
=
lazy_mode
,
multi_precision
=
multi_precision
)
def
_append_optimize_op
(
self
,
block
,
param_and_grad
):
if
self
.
set_param_lr_func
is
None
:
return
super
(
AdamWDL
,
self
).
_append_optimize_op
(
block
,
param_and_grad
)
self
.
_append_decoupled_weight_decay
(
block
,
param_and_grad
)
prev_lr
=
param_and_grad
[
0
].
optimize_attr
[
"learning_rate"
]
self
.
set_param_lr_func
(
param_and_grad
[
0
])
# excute Adam op
res
=
super
(
AdamW
,
self
).
_append_optimize_op
(
block
,
param_and_grad
)
param_and_grad
[
0
].
optimize_attr
[
"learning_rate"
]
=
prev_lr
return
res
if
not
IS_PADDLE_LATER_2_4
:
AdamWDL
.
_append_optimize_op
=
_append_optimize_op
def
build_adamwdl
(
model
,
def
build_adamwdl
(
model
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录