Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
4dba6afa
M
models
项目概览
PaddlePaddle
/
models
大约 1 年 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
4dba6afa
编写于
2月 02, 2021
作者:
W
WangXi
提交者:
GitHub
2月 02, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fleet support pure_fp16 in bert benchmark (#5255)
* bert benchmark fleet support pure_fp16 * fix use_pure_fp16
上级
53208f52
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
16 addition
and
5 deletion
+16
-5
PaddleNLP/benchmark/bert/run_pretrain.py
PaddleNLP/benchmark/bert/run_pretrain.py
+16
-5
未找到文件。
PaddleNLP/benchmark/bert/run_pretrain.py
浏览文件 @
4dba6afa
...
@@ -231,9 +231,13 @@ def dist_optimizer(args, optimizer):
...
@@ -231,9 +231,13 @@ def dist_optimizer(args, optimizer):
dist_strategy
.
fuse_grad_size_in_MB
=
16
dist_strategy
.
fuse_grad_size_in_MB
=
16
if
args
.
use_amp
:
if
args
.
use_amp
:
dist_strategy
.
amp
=
True
dist_strategy
.
amp
=
True
custom_black_list
=
[
'lookup_table'
,
'lookup_table_v2'
]
if
args
.
use_pure_fp16
else
None
dist_strategy
.
amp_configs
=
{
dist_strategy
.
amp_configs
=
{
'custom_white_list'
:
[
'softmax'
,
'layer_norm'
,
'gelu'
],
'custom_white_list'
:
[
'softmax'
,
'layer_norm'
,
'gelu'
],
'init_loss_scaling'
:
args
.
scale_loss
,
'init_loss_scaling'
:
args
.
scale_loss
,
'custom_black_list'
:
custom_black_list
,
'use_pure_fp16'
:
args
.
use_pure_fp16
}
}
if
args
.
gradient_merge_steps
>
1
:
if
args
.
gradient_merge_steps
>
1
:
dist_strategy
.
gradient_merge
=
True
dist_strategy
.
gradient_merge
=
True
...
@@ -320,15 +324,20 @@ def do_train(args):
...
@@ -320,15 +324,20 @@ def do_train(args):
apply_decay_param_fun
=
lambda
x
:
x
in
[
apply_decay_param_fun
=
lambda
x
:
x
in
[
p
.
name
for
n
,
p
in
model
.
named_parameters
()
p
.
name
for
n
,
p
in
model
.
named_parameters
()
if
not
any
(
nd
in
n
for
nd
in
[
"bias"
,
"norm"
])
if
not
any
(
nd
in
n
for
nd
in
[
"bias"
,
"norm"
])
])
],
multi_precision
=
args
.
use_pure_fp16
)
if
worker_num
==
1
and
args
.
use_amp
:
if
worker_num
==
1
and
args
.
use_amp
:
amp_list
=
paddle
.
fluid
.
contrib
.
mixed_precision
.
AutoMixedPrecisionLists
(
custom_black_list
=
([
'lookup_table'
,
'lookup_table_v2'
]
custom_white_list
=
[
'softmax'
,
'layer_norm'
,
'gelu'
])
if
args
.
use_pure_fp16
else
None
)
optimizer
=
paddle
.
fluid
.
contrib
.
mixed_precision
.
decorate
(
amp_list
=
paddle
.
static
.
amp
.
AutoMixedPrecisionLists
(
custom_white_list
=
[
'softmax'
,
'layer_norm'
,
'gelu'
],
custom_black_list
=
custom_black_list
)
optimizer
=
paddle
.
static
.
amp
.
decorate
(
optimizer
,
optimizer
,
amp_list
,
amp_list
,
init_loss_scaling
=
args
.
scale_loss
,
init_loss_scaling
=
args
.
scale_loss
,
use_dynamic_loss_scaling
=
True
)
use_dynamic_loss_scaling
=
True
,
use_pure_fp16
=
args
.
use_pure_fp16
)
if
worker_num
>
1
:
if
worker_num
>
1
:
# Use the fleet api to compile the distributed optimizer
# Use the fleet api to compile the distributed optimizer
...
@@ -343,6 +352,8 @@ def do_train(args):
...
@@ -343,6 +352,8 @@ def do_train(args):
# Use the state dict to update the parameter
# Use the state dict to update the parameter
reset_state_dict
=
reset_program_state_dict
(
model
,
state_dict
)
reset_state_dict
=
reset_program_state_dict
(
model
,
state_dict
)
paddle
.
static
.
set_program_state
(
main_program
,
reset_state_dict
)
paddle
.
static
.
set_program_state
(
main_program
,
reset_state_dict
)
if
args
.
use_amp
:
optimizer
.
amp_init
(
place
)
if
worker_num
==
1
:
if
worker_num
==
1
:
# Construct the compiled program
# Construct the compiled program
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录