Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
12d9a640
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
12d9a640
编写于
10月 17, 2019
作者:
L
Li Fuchen
提交者:
GitHub
10月 17, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revert "unify reader to dataloader (#3488)" (#3550)
This reverts commit
5108c1c1
.
上级
272a9b52
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
36 addition
and
34 deletion
+36
-34
PaddleNLP/language_model/args.py
PaddleNLP/language_model/args.py
+2
-2
PaddleNLP/language_model/run.sh
PaddleNLP/language_model/run.sh
+1
-1
PaddleNLP/language_model/train.py
PaddleNLP/language_model/train.py
+13
-11
PaddleNLP/models/language_model/lm_model.py
PaddleNLP/models/language_model/lm_model.py
+20
-20
未找到文件。
PaddleNLP/language_model/args.py
浏览文件 @
12d9a640
...
...
@@ -60,10 +60,10 @@ def parse_args():
default
=
False
,
help
=
'Whether profiling the trainning [True|False]'
)
parser
.
add_argument
(
'--use_
datalo
ader'
,
'--use_
py_re
ader'
,
type
=
str2bool
,
default
=
False
,
help
=
'Whether using
datalo
ader to feed data [True|False]'
)
help
=
'Whether using
py_re
ader to feed data [True|False]'
)
parser
.
add_argument
(
'--log_path'
,
help
=
'path of the log file. If not set, logs are printed to console'
)
...
...
PaddleNLP/language_model/run.sh
浏览文件 @
12d9a640
...
...
@@ -6,7 +6,7 @@ function run_train() {
python train.py
\
--data_path
data/simple-examples/data/
\
--model_type
small
\
--use_gpu
True
\
--use_gpu
True
}
run_train
PaddleNLP/language_model/train.py
浏览文件 @
12d9a640
...
...
@@ -124,10 +124,10 @@ def main():
init_scale
=
config
.
init_scale
,
dropout
=
config
.
dropout
,
rnn_model
=
config
.
rnn_model
,
use_
dataloader
=
args
.
use_datalo
ader
)
use_
py_reader
=
args
.
use_py_re
ader
)
if
args
.
use_
datalo
ader
:
datalo
ader
=
res_vars
[
-
1
]
if
args
.
use_
py_re
ader
:
py_re
ader
=
res_vars
[
-
1
]
res_vars
=
res_vars
[:
-
1
]
loss
,
last_hidden
,
last_cell
,
feed_order
=
res_vars
...
...
@@ -159,7 +159,7 @@ def main():
init_scale
=
config
.
init_scale
,
dropout
=
config
.
dropout
,
rnn_model
=
config
.
rnn_model
,
use_
datalo
ader
=
False
)
use_
py_re
ader
=
False
)
# Some op behaves differently for train and inference, we need to call
# this clone function to ensure every op is right for inference.
inference_program
=
inference_program
.
clone
(
for_test
=
True
)
...
...
@@ -176,6 +176,8 @@ def main():
exec_strategy
.
num_iteration_per_drop_scope
=
100
build_strategy
=
fluid
.
BuildStrategy
()
build_strategy
.
enable_inplace
=
True
build_strategy
.
memory_optimize
=
False
build_strategy
.
fuse_all_optimizer_ops
=
True
if
args
.
parallel
:
...
...
@@ -308,7 +310,7 @@ def main():
ppl
=
np
.
exp
(
total_loss
/
iters
)
return
ppl
def
train_an_epoch_
datalo
ader
(
epoch_id
,
batch_times
):
def
train_an_epoch_
py_re
ader
(
epoch_id
,
batch_times
):
# get train epoch size
log_interval
=
get_log_interval
(
len
(
train_data
))
...
...
@@ -317,7 +319,7 @@ def main():
total_loss
=
0
iters
=
0
datalo
ader
.
start
()
py_re
ader
.
start
()
batch_id
=
0
try
:
while
True
:
...
...
@@ -359,14 +361,14 @@ def main():
batch_id
+=
1
except
fluid
.
core
.
EOFException
:
datalo
ader
.
reset
()
py_re
ader
.
reset
()
batch_times
.
append
(
time
.
time
()
-
batch_start_time
)
ppl
=
np
.
exp
(
total_loss
/
iters
)
return
ppl
def
train
():
if
args
.
use_
datalo
ader
:
if
args
.
use_
py_re
ader
:
def
data_gen
():
data_iter_size
=
config
.
batch_size
//
device_count
...
...
@@ -378,14 +380,14 @@ def main():
y
=
y
.
reshape
((
-
1
,
1
))
yield
x
,
y
dataloader
.
set_batch_generato
r
(
data_gen
)
py_reader
.
decorate_tensor_provide
r
(
data_gen
)
total_time
=
0.0
for
epoch_id
in
range
(
config
.
max_epoch
):
batch_times
=
[]
epoch_start_time
=
time
.
time
()
if
args
.
use_
datalo
ader
:
train_ppl
=
train_an_epoch_
datalo
ader
(
epoch_id
,
batch_times
)
if
args
.
use_
py_re
ader
:
train_ppl
=
train_an_epoch_
py_re
ader
(
epoch_id
,
batch_times
)
else
:
train_ppl
=
train_an_epoch
(
epoch_id
,
batch_times
)
epoch_time
=
time
.
time
()
-
epoch_start_time
...
...
PaddleNLP/models/language_model/lm_model.py
浏览文件 @
12d9a640
...
...
@@ -32,7 +32,7 @@ def lm_model(hidden_size,
init_scale
=
0.1
,
dropout
=
None
,
rnn_model
=
'static'
,
use_
datalo
ader
=
False
):
use_
py_re
ader
=
False
):
def
padding_rnn
(
input_embedding
,
len
=
3
,
init_hidden
=
None
,
init_cell
=
None
):
weight_1_arr
=
[]
weight_2_arr
=
[]
...
...
@@ -255,23 +255,23 @@ def lm_model(hidden_size,
return
real_res
,
last_hidden
,
last_cell
batch_size_each
=
batch_size
//
fluid
.
core
.
get_cuda_device_count
()
x
=
layers
.
data
(
name
=
"x"
,
shape
=
[
batch_size_each
,
num_steps
,
1
],
dtype
=
'int64'
,
append_batch_size
=
False
)
y
=
layers
.
data
(
name
=
"y"
,
shape
=
[
batch_size_each
*
num_steps
,
1
],
dtype
=
'int64'
,
append_batch_size
=
False
)
if
use_dataloader
:
dataloader
=
fluid
.
io
.
DataLoader
.
from_generator
(
feed_list
=
[
x
,
y
]
,
capacity
=
16
,
iterable
=
False
,
use_double_buffer
=
Tru
e
)
if
use_py_reader
:
feed_shapes
=
[[
batch_size_each
,
num_steps
,
1
]
,
[
batch_size_each
*
num_steps
,
1
]]
py_reader
=
fluid
.
layers
.
py_reader
(
capacity
=
16
,
shapes
=
feed_shapes
,
dtypes
=
[
'int64'
,
'int64'
]
)
x
,
y
=
fluid
.
layers
.
read_file
(
py_reader
)
else
:
x
=
layers
.
data
(
name
=
"x"
,
shape
=
[
batch_size_each
,
num_steps
,
1
],
dtype
=
'int64'
,
append_batch_size
=
False
)
y
=
layers
.
data
(
name
=
"y"
,
shape
=
[
batch_size_each
*
num_steps
,
1
]
,
dtype
=
'int64'
,
append_batch_size
=
Fals
e
)
init_hidden
=
layers
.
data
(
name
=
"init_hidden"
,
...
...
@@ -385,7 +385,7 @@ def lm_model(hidden_size,
layers
.
assign
(
input
=
last_hidden
,
output
=
init_hidden
)
feeding_list
=
[
'x'
,
'y'
,
'init_hidden'
,
'init_cell'
]
if
use_
datalo
ader
:
return
loss
,
last_hidden
,
last_cell
,
feeding_list
,
datalo
ader
if
use_
py_re
ader
:
return
loss
,
last_hidden
,
last_cell
,
feeding_list
,
py_re
ader
else
:
return
loss
,
last_hidden
,
last_cell
,
feeding_list
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录