Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
5135f05c
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5135f05c
编写于
2月 09, 2018
作者:
Y
Yancey1989
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
create optimize block in pserver program
上级
222155cc
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
15 addition
and
28 deletion
+15
-28
python/paddle/v2/fluid/distribute_transpiler.py
python/paddle/v2/fluid/distribute_transpiler.py
+15
-28
未找到文件。
python/paddle/v2/fluid/distribute_transpiler.py
浏览文件 @
5135f05c
...
...
@@ -347,7 +347,8 @@ class DistributeTranspiler:
j
-=
1
return
False
def
_append_pserver_ops
(
self
,
program
,
pserver_program
,
opt_op
,
endpoint
):
def
_append_pserver_ops
(
self
,
optimize_block
,
opt_op
,
endpoint
):
program
=
optimize_block
.
program
new_inputs
=
dict
()
# update param/grad shape first, then other inputs like
# moment can use the updated shape
...
...
@@ -371,11 +372,11 @@ class DistributeTranspiler:
if
self
.
trainers
>
1
:
vars2merge
=
self
.
_create_var_for_trainers
(
program
.
global_block
(),
grad_block
,
self
.
trainers
)
program
.
global_block
()
.
append_op
(
optimize_block
.
append_op
(
type
=
"sum"
,
inputs
=
{
"X"
:
vars2merge
},
outputs
=
{
"Out"
:
merged_var
})
program
.
global_block
()
.
append_op
(
optimize_block
.
append_op
(
type
=
"scale"
,
inputs
=
{
"X"
:
merged_var
},
outputs
=
{
"Out"
:
merged_var
},
...
...
@@ -412,25 +413,18 @@ class DistributeTranspiler:
dtype
=
var
.
dtype
,
shape
=
new_shape
)
new_inputs
[
key
]
=
tmpvar
# create var in pserver program global block.
# TODO(typhoonzero): put blocks in one program to avoid create two
# variables.
pserver_program
.
global_block
().
create_var
(
name
=
var
.
name
,
persistable
=
var
.
persistable
,
dtype
=
var
.
dtype
,
shape
=
new_shape
)
# change output's ParamOut variable
outputs
=
self
.
_get_output_map_from_op
(
program
.
global_block
(),
opt_op
)
outputs
[
"ParamOut"
]
=
new_inputs
[
"Param"
]
program
.
global_block
()
.
append_op
(
optimize_block
.
append_op
(
type
=
opt_op
.
type
,
inputs
=
new_inputs
,
outputs
=
outputs
,
attrs
=
opt_op
.
attrs
)
def
_append_pserver_non_opt_ops
(
self
,
program
,
pserver_program
,
opt_op
):
def
_append_pserver_non_opt_ops
(
self
,
optimize_block
,
opt_op
):
program
=
optimize_block
.
program
# Append the ops for parameters that do not need to be optimized/updated
inputs
=
self
.
_get_input_map_from_op
(
self
.
program
.
global_block
().
vars
,
opt_op
)
...
...
@@ -440,14 +434,8 @@ class DistributeTranspiler:
else
:
varlist
=
[
var
]
for
var
in
varlist
:
# TODO(typhoonzero): will remove below line later.
program
.
global_block
().
create_var
(
name
=
var
.
name
,
persistable
=
var
.
persistable
,
dtype
=
var
.
dtype
,
shape
=
var
.
shape
)
if
not
pserver_program
.
global_block
().
vars
.
has_key
(
var
.
name
):
pserver_program
.
global_block
().
create_var
(
if
not
program
.
global_block
().
vars
.
has_key
(
var
.
name
):
program
.
global_block
().
create_var
(
name
=
var
.
name
,
persistable
=
var
.
persistable
,
dtype
=
var
.
dtype
,
...
...
@@ -456,7 +444,7 @@ class DistributeTranspiler:
outputs
=
self
.
_get_output_map_from_op
(
self
.
program
.
global_block
().
vars
,
opt_op
)
program
.
global_block
()
.
append_op
(
optimize_block
.
append_op
(
type
=
opt_op
.
type
,
inputs
=
inputs
,
outputs
=
outputs
,
...
...
@@ -489,7 +477,7 @@ class DistributeTranspiler:
dtype
=
v
.
dtype
,
shape
=
v
.
shape
)
# step6
optimize_
sub_program
=
Program
(
)
optimize_
block
=
pserver_program
.
create_block
(
0
)
# Iterate through the ops and append ops as needed
for
idx
,
opt_op
in
enumerate
(
self
.
optimize_ops
):
is_op_on_pserver
=
self
.
_is_op_on_pserver
(
endpoint
,
...
...
@@ -497,18 +485,17 @@ class DistributeTranspiler:
if
not
is_op_on_pserver
:
continue
if
"Grad"
in
opt_op
.
desc
.
input_arg_names
():
self
.
_append_pserver_ops
(
optimize_sub_program
,
pserver_program
,
opt_op
,
endpoint
)
self
.
_append_pserver_ops
(
optimize_block
,
opt_op
,
endpoint
)
else
:
self
.
_append_pserver_non_opt_ops
(
optimize_
sub_program
,
pserver_program
,
opt_op
)
self
.
_append_pserver_non_opt_ops
(
optimize_
block
,
opt_op
)
# Append the listen_and_serv op
pserver_program
.
global_block
().
append_op
(
type
=
"listen_and_serv"
,
inputs
=
{},
outputs
=
{},
attrs
=
{
"OptimizeBlock"
:
optimize_
sub_program
.
global_block
()
,
"OptimizeBlock"
:
optimize_
block
,
"endpoint"
:
endpoint
,
"ParamList"
:
[
p
.
name
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录