Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
88974072
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看板
提交
88974072
编写于
3月 20, 2018
作者:
X
Xin Pan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Better usage for multi-gpu
Use must set num_gpus in config.py to the number of gpus available.
上级
de683692
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
12 addition
and
4 deletion
+12
-4
fluid/neural_machine_translation/transformer/config.py
fluid/neural_machine_translation/transformer/config.py
+3
-0
fluid/neural_machine_translation/transformer/model.py
fluid/neural_machine_translation/transformer/model.py
+7
-4
fluid/neural_machine_translation/transformer/train.py
fluid/neural_machine_translation/transformer/train.py
+2
-0
未找到文件。
fluid/neural_machine_translation/transformer/config.py
浏览文件 @
88974072
...
...
@@ -6,6 +6,9 @@ class TrainTaskConfig(object):
# number of sequences contained in a mini-batch.
batch_size
=
32
# number of gpu devices
num_gpus
=
4
# the hyper params for Adam optimizer.
learning_rate
=
0.001
beta1
=
0.9
...
...
fluid/neural_machine_translation/transformer/model.py
浏览文件 @
88974072
...
...
@@ -10,6 +10,7 @@ from config import TrainTaskConfig, input_data_names, pos_enc_param_names
# FIXME(guosheng): Remove out the batch_size from the model.
batch_size
=
TrainTaskConfig
.
batch_size
num_gpus
=
TrainTaskConfig
.
num_gpus
def
position_encoding_init
(
n_position
,
d_pos_vec
):
...
...
@@ -86,7 +87,8 @@ def multi_head_attention(queries,
hidden_size
=
x
.
shape
[
-
1
]
# FIXME(guosheng): Decouple the program desc with batch_size.
reshaped
=
layers
.
reshape
(
x
=
x
,
shape
=
[
batch_size
/
2
,
-
1
,
n_head
,
hidden_size
//
n_head
])
x
=
x
,
shape
=
[
batch_size
/
num_gpus
,
-
1
,
n_head
,
hidden_size
//
n_head
])
# permuate the dimensions into:
# [batch_size, n_head, max_sequence_len, hidden_size_per_head]
...
...
@@ -106,7 +108,8 @@ def multi_head_attention(queries,
return
layers
.
reshape
(
x
=
trans_x
,
shape
=
map
(
int
,
[
batch_size
/
2
,
-
1
,
trans_x
.
shape
[
2
]
*
trans_x
.
shape
[
3
]]))
[
batch_size
/
num_gpus
,
-
1
,
trans_x
.
shape
[
2
]
*
trans_x
.
shape
[
3
]]))
def
scaled_dot_product_attention
(
q
,
k
,
v
,
attn_bias
,
d_model
,
dropout_rate
):
"""
...
...
@@ -233,7 +236,7 @@ def prepare_encoder(src_word,
# FIXME(guosheng): Decouple the program desc with batch_size.
enc_input
=
layers
.
reshape
(
x
=
enc_input
,
shape
=
[
batch_size
/
2
,
-
1
,
src_emb_dim
])
shape
=
[
batch_size
/
num_gpus
,
-
1
,
src_emb_dim
])
return
layers
.
dropout
(
enc_input
,
dropout_prob
=
dropout
,
is_test
=
False
)
if
dropout
else
enc_input
...
...
@@ -465,7 +468,7 @@ def transformer(
append_batch_size
=
False
)
places
=
fluid
.
layers
.
get_places
()
pd
=
fluid
.
layers
.
ParallelDo
(
places
,
use_nccl
=
Fals
e
)
pd
=
fluid
.
layers
.
ParallelDo
(
places
,
use_nccl
=
Tru
e
)
src_word
=
fluid
.
layers
.
reshape
(
x
=
src_word
,
shape
=
[
batch_size
,
-
1
,
1
])
...
...
fluid/neural_machine_translation/transformer/train.py
浏览文件 @
88974072
...
...
@@ -146,6 +146,8 @@ def main():
" 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
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录