Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
caecc97a
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看板
提交
caecc97a
编写于
3月 20, 2018
作者:
X
Xin Pan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
single device
上级
d2243979
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
34 addition
and
13 deletion
+34
-13
fluid/neural_machine_translation/transformer/config.py
fluid/neural_machine_translation/transformer/config.py
+2
-2
fluid/neural_machine_translation/transformer/train.py
fluid/neural_machine_translation/transformer/train.py
+32
-11
未找到文件。
fluid/neural_machine_translation/transformer/config.py
浏览文件 @
caecc97a
class
TrainTaskConfig
(
object
):
use_gpu
=
Fals
e
use_gpu
=
Tru
e
# the epoch number to train.
pass_num
=
2
# number of sequences contained in a mini-batch.
batch_size
=
64
batch_size
=
32
# the hyper params for Adam optimizer.
learning_rate
=
0.001
...
...
fluid/neural_machine_translation/transformer/train.py
浏览文件 @
caecc97a
import
numpy
as
np
import
sys
import
time
import
paddle.v2
as
paddle
import
paddle.fluid
as
fluid
import
paddle.fluid.profiler
as
profiler
from
model
import
transformer
,
position_encoding_init
from
optim
import
LearningRateScheduler
...
...
@@ -127,23 +130,41 @@ def main():
position_encoding_init
(
ModelHyperParams
.
max_length
+
1
,
ModelHyperParams
.
d_model
),
place
)
def
fn
(
pass_id
,
batch_id
,
data
):
t1
=
time
.
time
()
data_input
=
prepare_batch_input
(
data
,
input_data_names
,
ModelHyperParams
.
src_pad_idx
,
ModelHyperParams
.
trg_pad_idx
,
ModelHyperParams
.
max_length
,
ModelHyperParams
.
n_head
,
place
)
lr_scheduler
.
update_learning_rate
(
data_input
)
outs
=
exe
.
run
(
fluid
.
framework
.
default_main_program
(),
feed
=
data_input
,
fetch_list
=
[
cost
],
use_program_cache
=
True
)
cost_val
=
np
.
array
(
outs
[
0
])
print
(
"pass_id = "
+
str
(
pass_id
)
+
" batch = "
+
str
(
batch_id
)
+
" cost = "
+
str
(
cost_val
))
return
time
.
time
()
-
t1
# with open('/tmp/program', 'w') as f:
# f.write('%s' % fluid.framework.default_main_program())
total_time
=
0.0
count
=
0
for
pass_id
in
xrange
(
TrainTaskConfig
.
pass_num
):
for
batch_id
,
data
in
enumerate
(
train_data
()):
# The current program desc is coupled with batch_size, thus all
# mini-batches must have the same number of instances currently.
if
len
(
data
)
!=
TrainTaskConfig
.
batch_size
:
continue
data_input
=
prepare_batch_input
(
data
,
input_data_names
,
ModelHyperParams
.
src_pad_idx
,
ModelHyperParams
.
trg_pad_idx
,
ModelHyperParams
.
max_length
,
ModelHyperParams
.
n_head
,
place
)
lr_scheduler
.
update_learning_rate
(
data_input
)
outs
=
exe
.
run
(
fluid
.
framework
.
default_main_program
(),
feed
=
data_input
,
fetch_list
=
[
cost
])
cost_val
=
np
.
array
(
outs
[
0
])
print
(
"pass_id = "
+
str
(
pass_id
)
+
" batch = "
+
str
(
batch_id
)
+
" cost = "
+
str
(
cost_val
))
if
pass_id
==
0
and
batch_id
>=
10
and
batch_id
<
12
:
with
profiler
.
profiler
(
'All'
,
'total'
,
'/tmp/transformer'
):
duration
=
fn
(
pass_id
,
batch_id
,
data
)
else
:
duration
=
fn
(
pass_id
,
batch_id
,
data
)
count
+=
1
total_time
+=
duration
print
(
"avg: "
+
str
(
total_time
/
count
)
+
" cur: "
+
str
(
duration
))
sys
.
stdout
.
flush
()
if
__name__
==
"__main__"
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录