Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
969939e7
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看板
未验证
提交
969939e7
编写于
1月 08, 2021
作者:
L
lilong12
提交者:
GitHub
1月 08, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add fleet for transformer benchmark (#5164)
* add fleet, test=develop
上级
85105600
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
65 addition
and
19 deletion
+65
-19
PaddleNLP/benchmark/transformer/configs/transformer.big.yaml
PaddleNLP/benchmark/transformer/configs/transformer.big.yaml
+7
-0
PaddleNLP/benchmark/transformer/static/run_pretrain.sh
PaddleNLP/benchmark/transformer/static/run_pretrain.sh
+4
-0
PaddleNLP/benchmark/transformer/static/train.py
PaddleNLP/benchmark/transformer/static/train.py
+54
-19
未找到文件。
PaddleNLP/benchmark/transformer/configs/transformer.big.yaml
浏览文件 @
969939e7
...
@@ -96,4 +96,11 @@ dropout: 0.1
...
@@ -96,4 +96,11 @@ dropout: 0.1
# Vocabularies in source and target should be same for weight sharing.
# Vocabularies in source and target should be same for weight sharing.
weight_sharing
:
True
weight_sharing
:
True
# Use amp or not
use_amp
:
False
scale_loss
:
1.0
# Whether to use multi-card/multi-node distributed training.
is_distributed
:
True
max_iter
:
None
max_iter
:
None
PaddleNLP/benchmark/transformer/static/run_pretrain.sh
0 → 100644
浏览文件 @
969939e7
python
-m
paddle.distributed.launch
\
--gpus
=
"0,1"
\
train.py
PaddleNLP/benchmark/transformer/static/train.py
浏览文件 @
969939e7
...
@@ -10,6 +10,7 @@ from attrdict import AttrDict
...
@@ -10,6 +10,7 @@ from attrdict import AttrDict
from
pprint
import
pprint
from
pprint
import
pprint
import
paddle
import
paddle
import
paddle.distributed.fleet
as
fleet
import
paddle.distributed
as
dist
import
paddle.distributed
as
dist
from
paddlenlp.transformers
import
TransformerModel
,
CrossEntropyCriterion
from
paddlenlp.transformers
import
TransformerModel
,
CrossEntropyCriterion
...
@@ -36,8 +37,14 @@ def parse_args():
...
@@ -36,8 +37,14 @@ def parse_args():
def
do_train
(
args
):
def
do_train
(
args
):
paddle
.
enable_static
()
paddle
.
enable_static
()
places
=
paddle
.
static
.
cuda_places
()
if
args
.
use_gpu
else
paddle
.
static
.
cpu_places
()
if
args
.
is_distributed
:
trainer_count
=
len
(
places
)
fleet
.
init
(
is_collective
=
True
)
gpu_id
=
int
(
os
.
getenv
(
"FLAGS_selected_gpus"
,
"0"
))
places
=
paddle
.
CUDAPlace
(
gpu_id
)
if
args
.
use_gpu
else
paddle
.
static
.
cpu_places
()
trainer_count
=
1
if
args
.
use_gpu
else
len
(
places
)
else
:
places
=
paddle
.
static
.
cuda_places
()
if
args
.
use_gpu
else
paddle
.
static
.
cpu_places
()
trainer_count
=
len
(
places
)
# Set seed for CE
# Set seed for CE
random_seed
=
eval
(
str
(
args
.
random_seed
))
random_seed
=
eval
(
str
(
args
.
random_seed
))
...
@@ -88,19 +95,38 @@ def do_train(args):
...
@@ -88,19 +95,38 @@ def do_train(args):
epsilon
=
float
(
args
.
eps
),
epsilon
=
float
(
args
.
eps
),
parameters
=
transformer
.
parameters
())
parameters
=
transformer
.
parameters
())
if
args
.
is_distributed
:
build_strategy
=
paddle
.
static
.
BuildStrategy
()
exec_strategy
=
paddle
.
static
.
ExecutionStrategy
()
dist_strategy
=
fleet
.
DistributedStrategy
()
dist_strategy
.
build_strategy
=
build_strategy
dist_strategy
.
execution_strategy
=
exec_strategy
dist_strategy
.
fuse_grad_size_in_MB
=
16
if
args
.
use_amp
:
dist_strategy
.
amp
=
True
dist_strategy
.
amp_configs
=
{
'custom_white_list'
:
[
'softmax'
,
'layer_norm'
,
'gelu'
],
'init_loss_scaling'
:
args
.
scale_loss
,
}
optimizer
=
fleet
.
distributed_optimizer
(
optimizer
,
strategy
=
dist_strategy
)
optimizer
.
minimize
(
avg_cost
)
optimizer
.
minimize
(
avg_cost
)
exe
=
paddle
.
static
.
Executor
()
if
args
.
is_distributed
:
exe
=
paddle
.
static
.
Executor
(
places
)
else
:
exe
=
paddle
.
static
.
Executor
()
build_strategy
=
paddle
.
static
.
BuildStrategy
()
exec_strategy
=
paddle
.
static
.
ExecutionStrategy
()
compiled_train_program
=
paddle
.
static
.
CompiledProgram
(
train_program
).
with_data_parallel
(
loss_name
=
avg_cost
.
name
,
build_strategy
=
build_strategy
,
exec_strategy
=
exec_strategy
)
exe
.
run
(
startup_program
)
exe
.
run
(
startup_program
)
build_strategy
=
paddle
.
static
.
BuildStrategy
()
exec_strategy
=
paddle
.
static
.
ExecutionStrategy
()
compiled_train_program
=
paddle
.
static
.
CompiledProgram
(
train_program
).
with_data_parallel
(
loss_name
=
avg_cost
.
name
,
build_strategy
=
build_strategy
,
exec_strategy
=
exec_strategy
)
# the best cross-entropy value with label smoothing
# the best cross-entropy value with label smoothing
loss_normalizer
=
-
(
loss_normalizer
=
-
(
...
@@ -127,13 +153,22 @@ def do_train(args):
...
@@ -127,13 +153,22 @@ def do_train(args):
data
=
[
data
]
data
=
[
data
]
train_reader_cost
=
time
.
time
()
-
batch_start
train_reader_cost
=
time
.
time
()
-
batch_start
outs
=
exe
.
run
(
compiled_train_program
,
if
args
.
is_distributed
:
feed
=
[{
outs
=
exe
.
run
(
train_program
,
'src_word'
:
data
[
i
][
0
],
feed
=
[{
'trg_word'
:
data
[
i
][
1
],
'src_word'
:
data
[
i
][
0
],
'lbl_word'
:
data
[
i
][
2
],
'trg_word'
:
data
[
i
][
1
],
}
for
i
in
range
(
trainer_count
)],
'lbl_word'
:
data
[
i
][
2
],
fetch_list
=
[
sum_cost
.
name
,
token_num
.
name
])
}
for
i
in
range
(
trainer_count
)],
fetch_list
=
[
sum_cost
.
name
,
token_num
.
name
])
else
:
outs
=
exe
.
run
(
compiled_train_program
,
feed
=
[{
'src_word'
:
data
[
i
][
0
],
'trg_word'
:
data
[
i
][
1
],
'lbl_word'
:
data
[
i
][
2
],
}
for
i
in
range
(
trainer_count
)],
fetch_list
=
[
sum_cost
.
name
,
token_num
.
name
])
scheduler
.
step
()
scheduler
.
step
()
train_batch_cost
=
time
.
time
()
-
batch_start
train_batch_cost
=
time
.
time
()
-
batch_start
...
@@ -176,7 +211,7 @@ def do_train(args):
...
@@ -176,7 +211,7 @@ def do_train(args):
batch_ips_avg
.
reset
()
batch_ips_avg
.
reset
()
if
step_idx
%
args
.
save_step
==
0
and
step_idx
!=
0
:
if
step_idx
%
args
.
save_step
==
0
and
step_idx
!=
0
:
if
args
.
save_model
:
if
args
.
save_model
and
dist
.
get_rank
()
==
0
:
model_path
=
os
.
path
.
join
(
model_path
=
os
.
path
.
join
(
args
.
save_model
,
"step_"
+
str
(
step_idx
),
"transformer"
)
args
.
save_model
,
"step_"
+
str
(
step_idx
),
"transformer"
)
paddle
.
static
.
save
(
train_program
,
model_path
)
paddle
.
static
.
save
(
train_program
,
model_path
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录