Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
9d18809a
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看板
未验证
提交
9d18809a
编写于
7月 04, 2019
作者:
Y
Yiqun Liu
提交者:
GitHub
7月 04, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Correct a typo and add the support of profiler. (#2713)
上级
b2a6586d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
29 addition
and
8 deletion
+29
-8
PaddleNLP/language_model/args.py
PaddleNLP/language_model/args.py
+5
-0
PaddleNLP/language_model/train.py
PaddleNLP/language_model/train.py
+24
-8
未找到文件。
PaddleNLP/language_model/args.py
浏览文件 @
9d18809a
...
...
@@ -54,6 +54,11 @@ def parse_args():
type
=
str2bool
,
default
=
True
,
help
=
'Whether using gpu in parallel [True|False]'
)
parser
.
add_argument
(
'--profile'
,
type
=
str2bool
,
default
=
False
,
help
=
'Whether profiling the trainning [True|False]'
)
parser
.
add_argument
(
'--use_py_reader'
,
type
=
str2bool
,
...
...
PaddleNLP/language_model/train.py
浏览文件 @
9d18809a
...
...
@@ -20,12 +20,13 @@ import numpy as np
import
time
import
os
import
random
import
math
import
contextlib
import
paddle
import
paddle.fluid
as
fluid
import
paddle.fluid.framework
as
framework
import
paddle.fluid.profiler
as
profiler
from
paddle.fluid.executor
import
Executor
import
reader
...
...
@@ -48,6 +49,15 @@ import pickle
SEED
=
123
@
contextlib
.
contextmanager
def
profile_context
(
profile
=
True
):
if
profile
:
with
profiler
.
profiler
(
'All'
,
'total'
,
'/tmp/paddingrnn.profile'
):
yield
else
:
yield
def
get_current_model_para
(
train_prog
,
train_exe
):
param_list
=
train_prog
.
block
(
0
).
all_parameters
()
param_name_list
=
[
p
.
name
for
p
in
param_list
]
...
...
@@ -273,8 +283,10 @@ def main():
batch_start_time
=
time
.
time
()
fetch_outs
=
exe
.
run
(
train_program
,
feed
=
input_data_feed
,
fetch_list
=
[
loss
.
name
,
"learning_rate"
,
\
last_hidden
.
name
,
last_cell
.
name
],
fetch_list
=
[
loss
.
name
,
"learning_rate"
,
last_hidden
.
name
,
last_cell
.
name
],
use_program_cache
=
True
)
batch_time
=
time
.
time
()
-
batch_start_time
batch_times
.
append
(
batch_time
)
...
...
@@ -324,14 +336,16 @@ def main():
fetch_outs
=
exe
.
run
(
train_program
,
feed
=
data_feeds
,
fetch_list
=
[
loss
.
name
,
"learning_rate"
,
\
last_hidden
.
name
,
last_cell
.
name
],
fetch_list
=
[
loss
.
name
,
"learning_rate"
,
last_hidden
.
name
,
last_cell
.
name
],
use_program_cache
=
True
)
cost_train
=
np
.
array
(
fetch_outs
[
0
])
lr
=
np
.
array
(
fetch_outs
[
1
])
init_hidden
=
np
.
array
(
fetch_
list
[
2
])
init_cell
=
np
.
array
(
fetch_list
[
3
]
)
init_hidden
=
np
.
array
(
fetch_
outs
[
2
])
init_cell
=
np
.
array
(
fetch_outs
[
3
]
)
total_loss
+=
cost_train
iters
+=
config
.
num_steps
...
...
@@ -424,7 +438,9 @@ def main():
executor
=
exe
,
dirname
=
save_model_dir
,
main_program
=
main_program
)
print
(
"Saved model to: %s.
\n
"
%
save_model_dir
)
train
()
with
profile_context
(
args
.
profile
):
train
()
test_ppl
=
eval
(
test_data
)
print
(
"Test ppl:"
,
test_ppl
[
0
])
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录