Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
3e51633d
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看板
提交
3e51633d
编写于
4月 09, 2018
作者:
G
gongweibao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cleanup
上级
844c7bec
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
5 addition
and
24 deletion
+5
-24
fluid/neural_machine_translation/transformer/model.py
fluid/neural_machine_translation/transformer/model.py
+0
-1
fluid/neural_machine_translation/transformer/nmt_fluid.py
fluid/neural_machine_translation/transformer/nmt_fluid.py
+5
-19
fluid/neural_machine_translation/transformer/optim.py
fluid/neural_machine_translation/transformer/optim.py
+0
-4
未找到文件。
fluid/neural_machine_translation/transformer/model.py
浏览文件 @
3e51633d
...
...
@@ -10,7 +10,6 @@ from config import TrainTaskConfig, pos_enc_param_names, \
# FIXME(guosheng): Remove out the batch_size from the model.
batch_size
=
TrainTaskConfig
.
batch_size
def
position_encoding_init
(
n_position
,
d_pos_vec
):
"""
Generate the initial values for the sinusoid position encoding table.
...
...
fluid/neural_machine_translation/transformer/nmt_fluid.py
浏览文件 @
3e51633d
...
...
@@ -8,6 +8,7 @@ import paddle.fluid as fluid
import
paddle.fluid.core
as
core
from
model
import
transformer
,
position_encoding_init
import
model
from
optim
import
LearningRateScheduler
from
config
import
TrainTaskConfig
,
ModelHyperParams
,
pos_enc_param_names
,
\
encoder_input_data_names
,
decoder_input_data_names
,
label_data_names
...
...
@@ -71,6 +72,8 @@ parser.add_argument(
"--task_index"
,
type
=
int
,
default
=
0
,
help
=
"Index of task within the job"
)
args
=
parser
.
parse_args
()
model
.
batch_size
=
args
.
batch_size
def
pad_batch_data
(
insts
,
pad_idx
,
n_head
,
...
...
@@ -118,7 +121,6 @@ def pad_batch_data(insts,
def
prepare_batch_input
(
insts
,
input_data_names
,
src_pad_idx
,
trg_pad_idx
,
max_length
,
n_head
):
print
(
"input_data_name:"
,
input_data_names
)
"""
Put all padded data needed by training into a dict.
"""
...
...
@@ -152,7 +154,6 @@ def prepare_batch_input(insts, input_data_names, src_pad_idx, trg_pad_idx,
trg_src_attn_pre_softmax_shape
,
trg_src_attn_post_softmax_shape
,
lbl_word
,
lbl_weight
]))
#print("input_dict", input_dict)
return
input_dict
...
...
@@ -199,7 +200,7 @@ def main():
ModelHyperParams
.
trg_pad_idx
,
ModelHyperParams
.
max_length
,
ModelHyperParams
.
n_head
)
test_cost
=
exe
.
run
(
test
_program
,
test_cost
=
exe
.
run
(
inference
_program
,
feed
=
data_input
,
fetch_list
=
[
cost
])[
0
]
...
...
@@ -210,7 +211,6 @@ def main():
ts
=
time
.
time
()
for
pass_id
in
xrange
(
args
.
pass_num
):
for
batch_id
,
data
in
enumerate
(
train_reader
()):
print
(
"batch_id:"
,
batch_id
)
# The current program desc is coupled with batch_size, thus all
# mini-batches must have the same number of instances currently.
if
len
(
data
)
!=
args
.
batch_size
:
...
...
@@ -223,11 +223,8 @@ def main():
ModelHyperParams
.
trg_pad_idx
,
ModelHyperParams
.
max_length
,
ModelHyperParams
.
n_head
)
#print("feed0:", data_input)
#print("fetch_list0:", [cost])
lr_scheduler
.
update_learning_rate
(
data_input
)
print
(
"before exe run in train_loop"
)
outs
=
exe
.
run
(
trainer_prog
,
feed
=
data_input
,
fetch_list
=
[
cost
],
...
...
@@ -239,9 +236,7 @@ def main():
# Validate and save the model for inference.
val_cost
=
test
(
exe
)
#pass_elapsed = time.time() - start_time
#print("pass_id = " + str(pass_id) + " val_cost = " + str(val_cost))
print
(
"pass_id = %d batch = %d cost = %f speed = %.2f sample/s"
%
print
(
"pass_id = %d cost = %f avg_speed = %.2f sample/s"
%
(
pass_id
,
batch_id
,
cost_val
,
len
(
data
)
/
(
time
.
time
()
-
ts
)))
if
args
.
local
:
...
...
@@ -298,9 +293,6 @@ def main():
exe
.
run
(
pserver_startup
)
exe
.
run
(
pserver_prog
)
elif
training_role
==
"TRAINER"
:
#print("cost 0:", cost)
#print("before run start up")
# Parameter initialization
exe
.
run
(
fluid
.
default_startup_program
())
...
...
@@ -327,13 +319,7 @@ def main():
ModelHyperParams
.
trg_vocab_size
),
batch_size
=
args
.
batch_size
)
#print("before get trainer program")
trainer_prog
=
t
.
get_trainer_program
()
#print("before start")
# feeder = fluid.DataFeeder(feed_list=[images, label], place=place)
# TODO(typhoonzero): change trainer startup program to fetch parameters from pserver
# exe.run(fluid.default_startup_program())
train_loop
(
exe
,
trainer_prog
)
else
:
print
(
"environment var TRAINER_ROLE should be TRAINER os PSERVER"
)
...
...
fluid/neural_machine_translation/transformer/optim.py
浏览文件 @
3e51633d
...
...
@@ -28,7 +28,6 @@ class LearningRateScheduler(object):
dtype
=
"float32"
,
persistable
=
True
)
self
.
place
=
place
#print("LearningRateScheduler init learning_rate_name:", self.learning_rate.name)
def
update_learning_rate
(
self
,
data_input
):
self
.
current_steps
+=
1
...
...
@@ -38,7 +37,4 @@ class LearningRateScheduler(object):
])
lr_tensor
=
fluid
.
LoDTensor
()
lr_tensor
.
set
(
np
.
array
([
lr_value
],
dtype
=
"float32"
),
self
.
place
)
#print("in learning_rate")
#print("learning_rate_name:", self.learning_rate.name)
#print("data_input:", data_input)
data_input
[
self
.
learning_rate
.
name
]
=
lr_tensor
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录