Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
50a02adf
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
50a02adf
编写于
1月 10, 2018
作者:
T
typhoonzero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
transpile program ok
上级
9c0b1cf1
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
66 addition
and
27 deletion
+66
-27
python/paddle/v2/fluid/distribute_transpiler.py
python/paddle/v2/fluid/distribute_transpiler.py
+66
-27
未找到文件。
python/paddle/v2/fluid/distribute_transpiler.py
浏览文件 @
50a02adf
...
...
@@ -114,12 +114,15 @@ class DistributeTranspiler:
# step3
send_inputs
=
[]
send_outputs
=
[]
for
_
,
splited
in
grad_var_mapping
.
iteritems
():
send_inputs
.
extend
(
splited
)
for
b
in
grad_blocks
:
# append by order
varname
,
block_id
,
_
=
b
.
split
(
":"
)
send_inputs
.
append
(
grad_var_mapping
[
varname
][
int
(
block_id
)])
param_var_mapping
=
self
.
_create_vars_from_blocklist
(
program
,
param_blocks
)
for
_
,
splited
in
param_var_mapping
.
iteritems
():
send_outputs
.
extend
(
splited
)
for
b
in
param_blocks
:
varname
,
block_id
,
_
=
b
.
split
(
":"
)
send_outputs
.
append
(
param_var_mapping
[
varname
][
int
(
block_id
)])
# let send_op know which endpoint to send which var, eplist is of the same
# order of send_inputs.
eplist
=
split_method
(
send_inputs
,
pserver_endpoints
)
...
...
@@ -243,8 +246,37 @@ class DistributeTranspiler:
var_list
.
append
(
var_each
)
return
var_list
def
_append_pserver_ops
(
self
,
opt_op
,
endpoint
):
def
_get_optimizer_input_shape
(
self
,
op_type
,
varkey
,
orig_shape
,
param_shape
):
"""
Returns the shape for optimizer inputs that need to be reshaped when
Param and Grad is splited to multiple servers.
"""
# HACK(typhoonzero): Should use functions of corresponding optimizer in
# optimizer.py to get the shape, do not bind this in the transpiler.
if
op_type
==
"adam"
:
if
varkey
in
[
"Moment1"
,
"Moment2"
]:
return
param_shape
elif
op_type
==
"adagrad"
:
if
varkey
==
"Moment"
:
return
param_shape
elif
op_type
==
"adamax"
:
if
varkey
in
[
"Moment"
,
"InfNorm"
]:
return
param_shape
elif
op_type
==
"momentum"
:
if
varkey
==
"Velocity"
:
return
param_shape
elif
op_type
==
""
:
if
varkey
==
"Moment"
:
return
param_shape
elif
op_type
==
"sgd"
:
pass
return
orig_shape
def
_append_pserver_ops
(
self
,
program
,
opt_op
,
endpoint
):
new_inputs
=
dict
()
# update param/grad shape first, then other inputs like
# moment can use the updated shape
for
key
,
var
in
opt_op
.
inputs
.
iteritems
():
if
key
==
"Grad"
:
grad_block
=
None
...
...
@@ -256,7 +288,7 @@ class DistributeTranspiler:
# do not append this op if current endpoint
# is not dealing with this grad block
return
merged_var
=
optimize_sub_
program
.
global_block
().
create_var
(
merged_var
=
program
.
global_block
().
create_var
(
name
=
grad_block
.
name
,
persistable
=
grad_block
.
persistable
,
dtype
=
grad_block
.
dtype
,
...
...
@@ -264,13 +296,12 @@ class DistributeTranspiler:
# append merging ops if trainers > 1
if
self
.
trainers
>
1
:
vars2merge
=
self
.
_create_var_for_trainers
(
optimize_sub_program
.
global_block
(),
grad_block
,
self
.
trainers
)
optimize_sub_program
.
global_block
().
append_op
(
program
.
global_block
(),
grad_block
,
self
.
trainers
)
program
.
global_block
().
append_op
(
type
=
"sum"
,
inputs
=
{
"X"
:
vars2merge
},
outputs
=
{
"Out"
:
merged_var
})
optimize_sub_
program
.
global_block
().
append_op
(
program
.
global_block
().
append_op
(
type
=
"scale"
,
inputs
=
{
"X"
:
merged_var
},
outputs
=
{
"Out"
:
merged_var
},
...
...
@@ -285,37 +316,45 @@ class DistributeTranspiler:
break
if
not
param_block
:
return
tmpvar
=
optimize_sub_
program
.
global_block
().
create_var
(
tmpvar
=
program
.
global_block
().
create_var
(
name
=
param_block
.
name
,
persistable
=
param_block
.
persistable
,
dtype
=
param_block
.
dtype
,
shape
=
param_block
.
shape
)
new_inputs
[
key
]
=
tmpvar
else
:
tmpvar
=
optimize_sub_program
.
global_block
().
create_var
(
name
=
var
.
name
,
persistable
=
var
.
persistable
,
dtype
=
var
.
dtype
,
shape
=
var
.
shape
)
new_inputs
[
key
]
=
tmpvar
for
key
,
var
in
opt_op
.
inputs
.
iteritems
():
if
key
in
[
"Param"
,
"Grad"
]:
continue
# update accumulator variable shape
param_shape
=
new_inputs
[
"Param"
].
shape
new_shape
=
self
.
_get_optimizer_input_shape
(
opt_op
.
type
,
key
,
var
.
shape
,
param_shape
)
print
(
"var, new shape"
,
key
,
var
.
name
,
new_shape
)
tmpvar
=
program
.
global_block
().
create_var
(
name
=
var
.
name
,
persistable
=
var
.
persistable
,
dtype
=
var
.
dtype
,
shape
=
new_shape
)
new_inputs
[
key
]
=
tmpvar
# FIXME: change outputs ParamOut
optimize_sub_
program
.
global_block
().
append_op
(
program
.
global_block
().
append_op
(
type
=
opt_op
.
type
,
inputs
=
new_inputs
,
outputs
=
opt_op
.
outputs
,
attrs
=
opt_op
.
attrs
)
def
_append_pserver_non_opt_ops
(
self
,
opt_op
):
def
_append_pserver_non_opt_ops
(
self
,
program
,
opt_op
):
for
_
,
var
in
opt_op
.
inputs
.
iteritems
():
optimize_sub_
program
.
global_block
().
create_var
(
program
.
global_block
().
create_var
(
name
=
var
.
name
,
persistable
=
var
.
persistable
,
dtype
=
var
.
dtype
,
shape
=
var
.
shape
)
optimize_sub_
program
.
global_block
().
append_op
(
program
.
global_block
().
append_op
(
type
=
opt_op
.
type
,
inputs
=
new_
inputs
,
inputs
=
opt_op
.
inputs
,
outputs
=
opt_op
.
outputs
,
attrs
=
opt_op
.
attrs
)
...
...
@@ -331,15 +370,15 @@ class DistributeTranspiler:
# step5
pserver_program
=
Program
()
for
v
in
self
.
param_grad_ep_mapping
[
endpoint
][
"params"
]:
self
.
_clone_
param
(
pserver_program
.
global_block
(),
v
)
self
.
_clone_
var
(
pserver_program
.
global_block
(),
v
)
# step6
optimize_sub_program
=
Program
()
for
opt_op
in
optimize_ops
:
if
opt_op
s
.
inputs
.
has_key
(
"Grad"
):
if
opt_op
.
inputs
.
has_key
(
"Grad"
):
# append optimize_op
self
.
_append_pserver_ops
(
opt_op
,
endpoint
)
self
.
_append_pserver_ops
(
opt
imize_sub_program
,
opt
_op
,
endpoint
)
else
:
self
.
_append_pserver_non_opt_ops
(
opt_op
)
self
.
_append_pserver_non_opt_ops
(
opt
imize_sub_program
,
opt
_op
)
pserver_program
.
global_block
().
append_op
(
type
=
"recv"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录