Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
4658f950
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
4658f950
编写于
12月 21, 2017
作者:
T
typhoonzero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix delete ops
上级
70729270
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
33 addition
and
7 deletion
+33
-7
paddle/framework/block_desc.cc
paddle/framework/block_desc.cc
+15
-0
paddle/framework/block_desc.h
paddle/framework/block_desc.h
+2
-0
paddle/pybind/protobuf.cc
paddle/pybind/protobuf.cc
+1
-0
python/paddle/v2/fluid/distribute_transpiler.py
python/paddle/v2/fluid/distribute_transpiler.py
+5
-5
python/paddle/v2/fluid/framework.py
python/paddle/v2/fluid/framework.py
+10
-2
未找到文件。
paddle/framework/block_desc.cc
浏览文件 @
4658f950
...
@@ -91,6 +91,21 @@ OpDescBind *BlockDescBind::PrependOp() {
...
@@ -91,6 +91,21 @@ OpDescBind *BlockDescBind::PrependOp() {
return
ops_
.
front
().
get
();
return
ops_
.
front
().
get
();
}
}
void
BlockDescBind
::
RemoveOp
(
size_t
s
,
size_t
e
)
{
if
(
ops_
.
begin
()
+
s
==
ops_
.
end
()
||
ops_
.
begin
()
+
e
==
ops_
.
end
())
{
return
;
}
need_update_
=
true
;
for
(
auto
it
=
ops_
.
begin
()
+
s
;
it
!=
ops_
.
begin
()
+
e
;
it
++
)
{
auto
names
=
(
*
it
)
->
InputArgumentNames
();
for
(
auto
n
:
names
)
{
// TODO(typhoonzero): delete vars if no other op use it.
VLOG
(
3
)
<<
"deleting var "
<<
n
;
}
}
ops_
.
erase
(
ops_
.
begin
()
+
s
,
ops_
.
begin
()
+
e
);
}
std
::
vector
<
OpDescBind
*>
BlockDescBind
::
AllOps
()
const
{
std
::
vector
<
OpDescBind
*>
BlockDescBind
::
AllOps
()
const
{
std
::
vector
<
OpDescBind
*>
res
;
std
::
vector
<
OpDescBind
*>
res
;
for
(
const
auto
&
op
:
ops_
)
{
for
(
const
auto
&
op
:
ops_
)
{
...
...
paddle/framework/block_desc.h
浏览文件 @
4658f950
...
@@ -80,6 +80,8 @@ class BlockDescBind {
...
@@ -80,6 +80,8 @@ class BlockDescBind {
OpDescBind
*
PrependOp
();
OpDescBind
*
PrependOp
();
void
RemoveOp
(
size_t
s
,
size_t
e
);
std
::
vector
<
OpDescBind
*>
AllOps
()
const
;
std
::
vector
<
OpDescBind
*>
AllOps
()
const
;
size_t
OpSize
()
const
{
return
ops_
.
size
();
}
size_t
OpSize
()
const
{
return
ops_
.
size
();
}
...
...
paddle/pybind/protobuf.cc
浏览文件 @
4658f950
...
@@ -159,6 +159,7 @@ void BindBlockDesc(py::module &m) {
...
@@ -159,6 +159,7 @@ void BindBlockDesc(py::module &m) {
py
::
return_value_policy
::
reference
)
py
::
return_value_policy
::
reference
)
.
def
(
"prepend_op"
,
&
BlockDescBind
::
PrependOp
,
.
def
(
"prepend_op"
,
&
BlockDescBind
::
PrependOp
,
py
::
return_value_policy
::
reference
)
py
::
return_value_policy
::
reference
)
.
def
(
"remove_op"
,
&
BlockDescBind
::
RemoveOp
)
.
def
(
"var"
,
.
def
(
"var"
,
[](
BlockDescBind
&
self
,
py
::
bytes
byte_name
)
{
[](
BlockDescBind
&
self
,
py
::
bytes
byte_name
)
{
std
::
string
name
=
byte_name
;
std
::
string
name
=
byte_name
;
...
...
python/paddle/v2/fluid/distribute_transpiler.py
浏览文件 @
4658f950
...
@@ -131,11 +131,6 @@ class DistributeTranspiler:
...
@@ -131,11 +131,6 @@ class DistributeTranspiler:
def
_optimize_distributed
(
self
,
optimize_ops
,
program
,
params_and_grads
,
def
_optimize_distributed
(
self
,
optimize_ops
,
program
,
params_and_grads
,
**
kwargs
):
**
kwargs
):
# remove optimize ops and add a send op to main_program
# FIXME(typhoonzero): delete_op only remove the first accurance,
# need to consider about multiple same optimize op?
for
op
in
optimize_ops
:
program
.
global_block
().
delete_op
(
op
)
if
kwargs
.
has_key
(
"split_method"
):
if
kwargs
.
has_key
(
"split_method"
):
split_method
=
kwargs
[
"split_method"
]
split_method
=
kwargs
[
"split_method"
]
else
:
else
:
...
@@ -159,6 +154,10 @@ class DistributeTranspiler:
...
@@ -159,6 +154,10 @@ class DistributeTranspiler:
attrs
=
{
"endpoints"
:
pserver_endpoints
,
attrs
=
{
"endpoints"
:
pserver_endpoints
,
"epmap"
:
epmap
})
"epmap"
:
epmap
})
def
get_trainer_program
(
optimize_ops
,
program
):
# remove optimize ops and add a send op to main_program
program
.
global_block
().
delete_ops
(
optimize_ops
)
def
_create_var_for_trainers
(
self
,
block
,
var
,
trainers
):
def
_create_var_for_trainers
(
self
,
block
,
var
,
trainers
):
var_list
=
[]
var_list
=
[]
for
i
in
xrange
(
trainers
):
for
i
in
xrange
(
trainers
):
...
@@ -209,6 +208,7 @@ class DistributeTranspiler:
...
@@ -209,6 +208,7 @@ class DistributeTranspiler:
if
opt_op
.
inputs
.
has_key
(
"Grad"
):
if
opt_op
.
inputs
.
has_key
(
"Grad"
):
if
opt_op
.
inputs
[
"Grad"
].
name
in
grad_var_names
:
if
opt_op
.
inputs
[
"Grad"
].
name
in
grad_var_names
:
print
"appending "
,
opt_op
.
type
,
opt_op
.
inputs
optimize_sub_program
.
global_block
().
append_op
(
optimize_sub_program
.
global_block
().
append_op
(
type
=
opt_op
.
type
,
type
=
opt_op
.
type
,
inputs
=
opt_op
.
inputs
,
inputs
=
opt_op
.
inputs
,
...
...
python/paddle/v2/fluid/framework.py
浏览文件 @
4658f950
...
@@ -579,6 +579,7 @@ class Block(object):
...
@@ -579,6 +579,7 @@ class Block(object):
self
.
vars
=
dict
()
# var_name --> var
self
.
vars
=
dict
()
# var_name --> var
self
.
ops
=
collections
.
deque
()
# operator list
self
.
ops
=
collections
.
deque
()
# operator list
self
.
program
=
program
self
.
program
=
program
self
.
removed_vars
=
dict
()
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
to_string
(
True
)
return
self
.
to_string
(
True
)
...
@@ -635,8 +636,15 @@ class Block(object):
...
@@ -635,8 +636,15 @@ class Block(object):
self
.
ops
.
append
(
op
)
self
.
ops
.
append
(
op
)
return
op
return
op
def
delete_op
(
self
,
op
):
def
delete_ops
(
self
,
ops
):
self
.
ops
.
remove
(
op
)
# remove from cpp
# FIXME(typhoonzero): remove only the first occuracy.
try
:
start
=
list
(
self
.
ops
).
index
(
ops
[
0
])
end
=
list
(
self
.
ops
).
index
(
ops
[
-
1
])
except
Exception
,
e
:
raise
e
self
.
desc
.
remove_op
(
start
,
end
)
def
prepend_op
(
self
,
*
args
,
**
kwargs
):
def
prepend_op
(
self
,
*
args
,
**
kwargs
):
op_desc
=
self
.
desc
.
prepend_op
()
op_desc
=
self
.
desc
.
prepend_op
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录