Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
0b8e80b2
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看板
未验证
提交
0b8e80b2
编写于
1月 18, 2021
作者:
L
liu zhengxi
提交者:
GitHub
1月 18, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change the dir name (#5202)
* change the dir name * add static step final save * refine doc * alter method name
上级
c86f79bd
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
27 addition
and
21 deletion
+27
-21
PaddleNLP/benchmark/transformer/README.md
PaddleNLP/benchmark/transformer/README.md
+7
-7
PaddleNLP/benchmark/transformer/dygraph/train.py
PaddleNLP/benchmark/transformer/dygraph/train.py
+1
-1
PaddleNLP/benchmark/transformer/static/predict.py
PaddleNLP/benchmark/transformer/static/predict.py
+2
-2
PaddleNLP/benchmark/transformer/static/train.py
PaddleNLP/benchmark/transformer/static/train.py
+17
-11
PaddleNLP/benchmark/transformer/util/distributed_utils.py
PaddleNLP/benchmark/transformer/util/distributed_utils.py
+0
-0
PaddleNLP/benchmark/transformer/util/record.py
PaddleNLP/benchmark/transformer/util/record.py
+0
-0
未找到文件。
PaddleNLP/benchmark/transformer/README.md
浏览文件 @
0b8e80b2
...
...
@@ -55,7 +55,7 @@ dataset = WMT14ende.get_datasets(mode="train", transform_func=transform_func)
```
shell
cd
static/
export
CUDA_VISIBLE_DEVICES
=
0
python3 train.py
python3 train.py
--config
../configs/transformer.base.yaml
```
需要注意的是,单卡下的超参设置与多卡下的超参设置有些不同,单卡执行需要修改
`configs/transformer.big.yaml`
或是
`configs/transformer.base.yaml`
中:
...
...
@@ -67,7 +67,7 @@ python3 train.py
```
shell
cd
dygraph/
export
CUDA_VISIBLE_DEVICES
=
0
python3 train.py
python3 train.py
--config
../configs/transformer.base.yaml
```
需要注意的是,单卡下的超参设置与多卡下的超参设置有些不同,单卡执行需要修改
`configs/transformer.big.yaml`
或是
`configs/transformer.base.yaml`
中:
...
...
@@ -85,7 +85,7 @@ python3 train.py
```
shell
cd
static/
export
CUDA_VISIBLE_DEVICES
=
0,1,2,3,4,5,6,7
python3 train.py
python3 train.py
--config
../configs/transformer.base.yaml
```
使用 PE 的方式启动单机多卡需要设置
`configs/transformer.big.yaml`
或是
`configs/transformer.base.yaml`
中
`is_distributed`
参数为
`False`
。
...
...
@@ -94,7 +94,7 @@ python3 train.py
```
shell
cd
static/
export
CUDA_VISIBLE_DEVICES
=
0,1,2,3,4,5,6,7
python
-m
paddle.distributed.launch
--gpus
=
"0,1,2,3,4,5,6,7"
train.py
python
3
-m
paddle.distributed.launch
--gpus
=
"0,1,2,3,4,5,6,7"
train.py
--config
../configs/transformer.base.yaml
```
使用 fleet 的方式启动单机多卡需要设置
`configs/transformer.big.yaml`
或是
`configs/transformer.base.yaml`
中
`is_distributed`
参数为
`True`
。
...
...
@@ -104,7 +104,7 @@ python -m paddle.distributed.launch --gpus="0,1,2,3,4,5,6,7" train.py
```
shell
cd
dygraph/
export
CUDA_VISIBLE_DEVICES
=
0,1,2,3,4,5,6,7
python3
-m
paddle.distributed.launch
--gpus
"0,1,2,3,4,5,6,7"
train.py
python3
-m
paddle.distributed.launch
--gpus
"0,1,2,3,4,5,6,7"
train.py
--config
../configs/transformer.base.yaml
```
### 模型推断
...
...
@@ -116,7 +116,7 @@ python3 -m paddle.distributed.launch --gpus "0,1,2,3,4,5,6,7" train.py
# setting visible devices for prediction
cd
static/
export
CUDA_VISIBLE_DEVICES
=
0
python
predict.py
--config
./configs/transformer.base.yaml
python
3 predict.py
--config
.
./configs/transformer.base.yaml
```
由
`predict_file`
指定的文件中文本的翻译结果会输出到
`output_file`
指定的文件。执行预测时需要设置
`init_from_params`
来给出模型所在目录,更多参数的使用可以在
`configs/transformer.big.yaml`
和
`configs/transformer.base.yaml`
文件中查阅注释说明并进行更改设置。如果执行不提供
`--config`
选项,程序将默认使用 big model 的配置。
...
...
@@ -128,7 +128,7 @@ python predict.py --config ./configs/transformer.base.yaml
# setting visible devices for prediction
cd
dygraph/
export
CUDA_VISIBLE_DEVICES
=
0
python
predict.py
--config
./configs/transformer.base.yaml
python
3 predict.py
--config
.
./configs/transformer.base.yaml
```
由
`predict_file`
指定的文件中文本的翻译结果会输出到
`output_file`
指定的文件。执行预测时需要设置
`init_from_params`
来给出模型所在目录,更多参数的使用可以在
`configs/transformer.big.yaml`
和
`configs/transformer.base.yaml`
文件中查阅注释说明并进行更改设置。如果执行不提供
`--config`
选项,程序将默认使用 big model 的配置。
...
...
PaddleNLP/benchmark/transformer/dygraph/train.py
浏览文件 @
0b8e80b2
...
...
@@ -16,7 +16,7 @@ from paddlenlp.transformers import TransformerModel, CrossEntropyCriterion, posi
sys
.
path
.
append
(
"../"
)
import
reader
from
util
s
.record
import
AverageStatistical
from
util.record
import
AverageStatistical
FORMAT
=
'%(asctime)s-%(levelname)s: %(message)s'
logging
.
basicConfig
(
level
=
logging
.
INFO
,
format
=
FORMAT
)
...
...
PaddleNLP/benchmark/transformer/static/predict.py
浏览文件 @
0b8e80b2
...
...
@@ -48,7 +48,7 @@ def post_process_seq(seq, bos_idx, eos_idx, output_bos=False, output_eos=False):
return
seq
def
do_
train
(
args
):
def
do_
predict
(
args
):
paddle
.
enable_static
()
if
args
.
use_gpu
:
place
=
paddle
.
set_device
(
"gpu:0"
)
...
...
@@ -118,4 +118,4 @@ if __name__ == "__main__":
args
=
AttrDict
(
yaml
.
safe_load
(
f
))
pprint
(
args
)
do_
train
(
args
)
do_
predict
(
args
)
PaddleNLP/benchmark/transformer/static/train.py
浏览文件 @
0b8e80b2
...
...
@@ -17,7 +17,7 @@ from paddlenlp.transformers import TransformerModel, CrossEntropyCriterion
sys
.
path
.
append
(
"../"
)
import
reader
from
util
s
.record
import
AverageStatistical
from
util.record
import
AverageStatistical
FORMAT
=
'%(asctime)s-%(levelname)s: %(message)s'
logging
.
basicConfig
(
level
=
logging
.
INFO
,
format
=
FORMAT
)
...
...
@@ -40,10 +40,12 @@ def do_train(args):
if
args
.
is_distributed
:
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
()
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
()
places
=
paddle
.
static
.
cuda_places
(
)
if
args
.
use_gpu
else
paddle
.
static
.
cpu_places
()
trainer_count
=
len
(
places
)
# Set seed for CE
...
...
@@ -110,24 +112,24 @@ def do_train(args):
'init_loss_scaling'
:
args
.
scale_loss
,
}
optimizer
=
fleet
.
distributed_optimizer
(
optimizer
,
strategy
=
dist_strategy
)
optimizer
=
fleet
.
distributed_optimizer
(
optimizer
,
strategy
=
dist_strategy
)
optimizer
.
minimize
(
avg_cost
)
if
args
.
is_distributed
:
exe
=
paddle
.
static
.
Executor
(
places
)
else
:
exe
=
paddle
.
static
.
Executor
()
build_strategy
=
paddle
.
static
.
BuildStrategy
()
exec_strategy
=
paddle
.
static
.
ExecutionStrategy
()
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
,
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
)
# the best cross-entropy value with label smoothing
loss_normalizer
=
-
(
(
1.
-
args
.
label_smooth_eps
)
*
np
.
log
(
...
...
@@ -220,6 +222,10 @@ def do_train(args):
step_idx
+=
1
batch_start
=
time
.
time
()
if
args
.
save_model
and
dist
.
get_rank
()
==
0
:
model_path
=
os
.
path
.
join
(
args
.
save_model
,
"step_final"
,
"transformer"
)
paddle
.
static
.
save
(
train_program
,
model_path
)
paddle
.
disable_static
()
...
...
PaddleNLP/benchmark/transformer/util
s
/distributed_utils.py
→
PaddleNLP/benchmark/transformer/util/distributed_utils.py
浏览文件 @
0b8e80b2
文件已移动
PaddleNLP/benchmark/transformer/util
s
/record.py
→
PaddleNLP/benchmark/transformer/util/record.py
浏览文件 @
0b8e80b2
文件已移动
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录