Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
c779cc14
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
接近 2 年 前同步成功
通知
116
Star
4999
Fork
1114
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
6
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleClas
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
6
合并请求
6
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c779cc14
编写于
3月 02, 2023
作者:
D
dolcexu
提交者:
zengshao0622
3月 02, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
adamwdl fix
上级
995c8b26
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
9 addition
and
20 deletion
+9
-20
ppcls/optimizer/optimizer.py
ppcls/optimizer/optimizer.py
+9
-20
未找到文件。
ppcls/optimizer/optimizer.py
浏览文件 @
c779cc14
...
...
@@ -20,6 +20,7 @@ import inspect
from
paddle
import
optimizer
as
optim
from
ppcls.utils
import
logger
from
functools
import
partial
class
SGD
(
object
):
...
...
@@ -349,7 +350,8 @@ class AdamWDL(object):
self
.
layerwise_decay
=
layerwise_decay
self
.
name_dict
=
name_dict
self
.
n_layers
=
n_layers
self
.
set_param_lr_fun
=
self
.
_layerwise_lr_decay
self
.
set_param_lr_func
=
partial
(
self
.
_layerwise_lr_decay
,
layerwise_decay
,
name_dict
,
n_layers
)
super
().
__init__
(
learning_rate
=
learning_rate
,
parameters
=
parameters
,
...
...
@@ -361,30 +363,16 @@ class AdamWDL(object):
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_fun
is
None
:
return
super
(
AdamLW
,
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_fun
(
self
.
layerwise_decay
,
self
.
name_dict
,
self
.
n_layers
,
param_and_grad
[
0
])
# excute Adam op
res
=
super
(
optim
.
AdamW
,
self
).
_append_optimize_op
(
block
,
param_and_grad
)
param_and_grad
[
0
].
optimize_attr
[
"learning_rate"
]
=
prev_lr
return
res
multi_precision
=
multi_precision
,
lr_ratio
=
self
.
set_param_lr_func
)
# Layerwise decay
def
_layerwise_lr_decay
(
self
,
decay_rate
,
name_dict
,
n_layers
,
param
):
"""
Args:
decay_rate (float):
decay_rate (float):
The layer-wise decay ratio.
name_dict (dict):
name_dict (dict):
The keys of name_dict is dynamic name of model while the value
of name_dict is static name.
Use model.named_parameters() to get name_dict.
...
...
@@ -399,7 +387,8 @@ class AdamWDL(object):
ratio
=
decay_rate
**
(
n_layers
-
layer
)
elif
"embed"
in
static_name
:
ratio
=
decay_rate
**
(
n_layers
+
1
)
param
.
optimize_attr
[
"learning_rate"
]
*=
ratio
# param.optimize_attr["learning_rate"] *= ratio
return
ratio
def
__call__
(
self
,
model_list
):
model
=
model_list
[
0
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录