Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
d5686f58
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看板
提交
d5686f58
编写于
2月 05, 2018
作者:
K
Kexin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
clean code
上级
dc68e7c4
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
3 addition
and
48 deletion
+3
-48
paddle/framework/block_desc.cc
paddle/framework/block_desc.cc
+1
-4
paddle/framework/op_desc.cc
paddle/framework/op_desc.cc
+2
-13
paddle/framework/program_desc.cc
paddle/framework/program_desc.cc
+0
-9
paddle/framework/prune.cc
paddle/framework/prune.cc
+0
-6
python/paddle/v2/fluid/io.py
python/paddle/v2/fluid/io.py
+0
-6
python/paddle/v2/fluid/tests/book/test_rnn_encoder_decoder.py
...on/paddle/v2/fluid/tests/book/test_rnn_encoder_decoder.py
+0
-10
未找到文件。
paddle/framework/block_desc.cc
浏览文件 @
d5686f58
...
@@ -155,8 +155,6 @@ BlockDesc::BlockDesc(ProgramDesc *prog, proto::BlockDesc *desc)
...
@@ -155,8 +155,6 @@ BlockDesc::BlockDesc(ProgramDesc *prog, proto::BlockDesc *desc)
for
(
const
proto
::
OpDesc
&
op_desc
:
desc_
->
ops
())
{
for
(
const
proto
::
OpDesc
&
op_desc
:
desc_
->
ops
())
{
ops_
.
emplace_back
(
new
OpDesc
(
op_desc
,
prog
,
this
));
ops_
.
emplace_back
(
new
OpDesc
(
op_desc
,
prog
,
this
));
}
}
std
::
cout
<<
"Constructed block idx "
<<
desc
->
idx
()
<<
" from protobuf str"
<<
std
::
endl
;
}
}
BlockDesc
::
BlockDesc
(
const
BlockDesc
&
other
,
proto
::
BlockDesc
*
desc
,
BlockDesc
::
BlockDesc
(
const
BlockDesc
&
other
,
proto
::
BlockDesc
*
desc
,
...
@@ -164,9 +162,8 @@ BlockDesc::BlockDesc(const BlockDesc &other, proto::BlockDesc *desc,
...
@@ -164,9 +162,8 @@ BlockDesc::BlockDesc(const BlockDesc &other, proto::BlockDesc *desc,
:
prog_
(
prog
),
desc_
(
desc
)
{
:
prog_
(
prog
),
desc_
(
desc
)
{
need_update_
=
true
;
need_update_
=
true
;
for
(
auto
&
op
:
other
.
ops_
)
{
for
(
auto
&
op
:
other
.
ops_
)
{
ops_
.
emplace_back
(
new
OpDesc
(
*
op
,
this
));
ops_
.
emplace_back
(
new
OpDesc
(
*
op
->
Proto
(),
prog
,
this
));
}
}
for
(
auto
&
it
:
other
.
vars_
)
{
for
(
auto
&
it
:
other
.
vars_
)
{
auto
*
var
=
new
VarDesc
(
*
it
.
second
);
auto
*
var
=
new
VarDesc
(
*
it
.
second
);
vars_
[
it
.
first
].
reset
(
var
);
vars_
[
it
.
first
].
reset
(
var
);
...
...
paddle/framework/op_desc.cc
浏览文件 @
d5686f58
...
@@ -124,21 +124,10 @@ OpDesc::OpDesc(const proto::OpDesc &desc, ProgramDesc *prog, BlockDesc *block)
...
@@ -124,21 +124,10 @@ OpDesc::OpDesc(const proto::OpDesc &desc, ProgramDesc *prog, BlockDesc *block)
// restore attrs_
// restore attrs_
for
(
const
proto
::
OpDesc
::
Attr
&
attr
:
desc_
.
attrs
())
{
for
(
const
proto
::
OpDesc
::
Attr
&
attr
:
desc_
.
attrs
())
{
std
::
string
attr_name
=
attr
.
name
();
std
::
string
attr_name
=
attr
.
name
();
// we use a trick to handle attr.type() is BLOCK here, because at this
// The sub_block referred to by the BLOCK attr hasn't be added
// moment the sub_block hasn't beed added to ProgramDesc's vector<Block>
// to ProgramDesc class yet, we skip setting BLOCK attr here.
// so we cast the block_idx to a dummy BlockDesc pointer
if
(
attr
.
type
()
!=
proto
::
AttrType
::
BLOCK
)
{
if
(
attr
.
type
()
!=
proto
::
AttrType
::
BLOCK
)
{
attrs_
[
attr_name
]
=
GetAttrValue
(
attr
);
attrs_
[
attr_name
]
=
GetAttrValue
(
attr
);
}
else
{
size_t
blk_idx
=
attr
.
block_idx
();
if
(
blk_idx
<
prog
->
Size
())
{
attrs_
[
attr_name
]
=
prog
->
MutableBlock
(
blk_idx
);
std
::
cout
<<
"In OpDesc: set up attr block idx "
<<
blk_idx
<<
std
::
endl
;
}
else
{
std
::
cout
<<
"In OpDesc: We don't have this block idx "
<<
blk_idx
<<
std
::
endl
;
}
}
}
}
}
this
->
block_
=
block
;
this
->
block_
=
block
;
...
...
paddle/framework/program_desc.cc
浏览文件 @
d5686f58
...
@@ -43,7 +43,6 @@ ProgramDesc::ProgramDesc() {
...
@@ -43,7 +43,6 @@ ProgramDesc::ProgramDesc() {
ProgramDesc
::
ProgramDesc
(
const
ProgramDesc
&
o
)
{
ProgramDesc
::
ProgramDesc
(
const
ProgramDesc
&
o
)
{
desc_
=
o
.
desc_
;
desc_
=
o
.
desc_
;
for
(
int
i
=
0
;
i
<
desc_
.
blocks_size
();
++
i
)
{
for
(
int
i
=
0
;
i
<
desc_
.
blocks_size
();
++
i
)
{
auto
*
block
=
desc_
.
mutable_blocks
(
i
);
auto
*
block
=
desc_
.
mutable_blocks
(
i
);
blocks_
.
emplace_back
(
new
BlockDesc
(
*
o
.
blocks_
[
i
],
block
,
this
));
blocks_
.
emplace_back
(
new
BlockDesc
(
*
o
.
blocks_
[
i
],
block
,
this
));
...
@@ -54,8 +53,6 @@ ProgramDesc::ProgramDesc(const ProgramDesc &o) {
...
@@ -54,8 +53,6 @@ ProgramDesc::ProgramDesc(const ProgramDesc &o) {
if
(
attr
.
type
()
==
proto
::
AttrType
::
BLOCK
)
{
if
(
attr
.
type
()
==
proto
::
AttrType
::
BLOCK
)
{
size_t
blk_idx
=
attr
.
block_idx
();
size_t
blk_idx
=
attr
.
block_idx
();
op
->
SetBlockAttr
(
attr
.
name
(),
*
this
->
MutableBlock
(
blk_idx
));
op
->
SetBlockAttr
(
attr
.
name
(),
*
this
->
MutableBlock
(
blk_idx
));
std
::
cout
<<
"In ProgramDesc 1: set block attr idx "
<<
blk_idx
<<
std
::
endl
;
}
}
}
}
}
}
...
@@ -64,11 +61,8 @@ ProgramDesc::ProgramDesc(const ProgramDesc &o) {
...
@@ -64,11 +61,8 @@ ProgramDesc::ProgramDesc(const ProgramDesc &o) {
ProgramDesc
::
ProgramDesc
(
const
proto
::
ProgramDesc
&
desc
)
{
ProgramDesc
::
ProgramDesc
(
const
proto
::
ProgramDesc
&
desc
)
{
desc_
=
desc
;
desc_
=
desc
;
std
::
cout
<<
std
::
endl
<<
"starting in ProgDesc constructor"
<<
std
::
endl
;
for
(
auto
&
block_desc
:
*
desc_
.
mutable_blocks
())
{
for
(
auto
&
block_desc
:
*
desc_
.
mutable_blocks
())
{
blocks_
.
emplace_back
(
new
BlockDesc
(
this
,
&
block_desc
));
blocks_
.
emplace_back
(
new
BlockDesc
(
this
,
&
block_desc
));
std
::
cout
<<
"Done constructing block idx "
<<
block_desc
.
idx
()
<<
" parent idx "
<<
block_desc
.
parent_idx
()
<<
std
::
endl
;
}
}
for
(
auto
&
block
:
blocks_
)
{
for
(
auto
&
block
:
blocks_
)
{
for
(
auto
*
op
:
block
->
AllOps
())
{
for
(
auto
*
op
:
block
->
AllOps
())
{
...
@@ -76,13 +70,10 @@ ProgramDesc::ProgramDesc(const proto::ProgramDesc &desc) {
...
@@ -76,13 +70,10 @@ ProgramDesc::ProgramDesc(const proto::ProgramDesc &desc) {
if
(
attr
.
type
()
==
proto
::
AttrType
::
BLOCK
)
{
if
(
attr
.
type
()
==
proto
::
AttrType
::
BLOCK
)
{
size_t
blk_idx
=
attr
.
block_idx
();
size_t
blk_idx
=
attr
.
block_idx
();
op
->
SetBlockAttr
(
attr
.
name
(),
*
this
->
MutableBlock
(
blk_idx
));
op
->
SetBlockAttr
(
attr
.
name
(),
*
this
->
MutableBlock
(
blk_idx
));
std
::
cout
<<
"In ProgramDesc 2: set block attr idx "
<<
blk_idx
<<
std
::
endl
;
}
}
}
}
}
}
}
}
std
::
cout
<<
"Done ProgDesc construction"
<<
std
::
endl
<<
std
::
endl
;
}
}
ProgramDesc
::
ProgramDesc
(
const
std
::
string
&
binary_str
)
{
ProgramDesc
::
ProgramDesc
(
const
std
::
string
&
binary_str
)
{
...
...
paddle/framework/prune.cc
浏览文件 @
d5686f58
...
@@ -137,8 +137,6 @@ void prune_impl(const proto::ProgramDesc& input, proto::ProgramDesc* output,
...
@@ -137,8 +137,6 @@ void prune_impl(const proto::ProgramDesc& input, proto::ProgramDesc* output,
sub_block_dependent_vars
.
insert
(
argu
);
sub_block_dependent_vars
.
insert
(
argu
);
}
}
}
}
std
::
cout
<<
"pruning the next block, the current output_block_id is "
<<
output_block_id
<<
std
::
endl
;
// GetSubBlockIndex(*op) is the idx of the sub_block in the input desc
// GetSubBlockIndex(*op) is the idx of the sub_block in the input desc
// output_block_id is the idx of the current block in the output desc
// output_block_id is the idx of the current block in the output desc
prune_impl
(
input
,
output
,
GetSubBlockIndex
(
*
op
),
output_block_id
,
prune_impl
(
input
,
output
,
GetSubBlockIndex
(
*
op
),
output_block_id
,
...
@@ -147,8 +145,6 @@ void prune_impl(const proto::ProgramDesc& input, proto::ProgramDesc* output,
...
@@ -147,8 +145,6 @@ void prune_impl(const proto::ProgramDesc& input, proto::ProgramDesc* output,
}
}
}
}
std
::
cout
<<
"Starting to remove unreferenced variables"
<<
" for block idx "
<<
output_block_id
<<
std
::
endl
;
// remove the VarDescs in BlockDesc that are not referenced in
// remove the VarDescs in BlockDesc that are not referenced in
// the pruned OpDescs
// the pruned OpDescs
std
::
unordered_map
<
std
::
string
,
proto
::
VarDesc
>
var_map
;
std
::
unordered_map
<
std
::
string
,
proto
::
VarDesc
>
var_map
;
...
@@ -186,9 +182,7 @@ void prune_impl(const proto::ProgramDesc& input, proto::ProgramDesc* output,
...
@@ -186,9 +182,7 @@ void prune_impl(const proto::ProgramDesc& input, proto::ProgramDesc* output,
// TODO(fengjiayi): Prune() could be inplaced to avoid unnecessary copies
// TODO(fengjiayi): Prune() could be inplaced to avoid unnecessary copies
void
Prune
(
const
proto
::
ProgramDesc
&
input
,
proto
::
ProgramDesc
*
output
)
{
void
Prune
(
const
proto
::
ProgramDesc
&
input
,
proto
::
ProgramDesc
*
output
)
{
std
::
set
<
std
::
string
>
dependent_vars
;
std
::
set
<
std
::
string
>
dependent_vars
;
std
::
cout
<<
std
::
endl
<<
"Start C++ framework::prune"
<<
std
::
endl
;
prune_impl
(
input
,
output
,
0
,
-
1
,
dependent_vars
);
prune_impl
(
input
,
output
,
0
,
-
1
,
dependent_vars
);
std
::
cout
<<
"Finished C++ framework::prune"
<<
std
::
endl
<<
std
::
endl
;
}
}
void
inference_optimize_impl
(
const
proto
::
ProgramDesc
&
input
,
void
inference_optimize_impl
(
const
proto
::
ProgramDesc
&
input
,
...
...
python/paddle/v2/fluid/io.py
浏览文件 @
d5686f58
...
@@ -342,12 +342,6 @@ def save_inference_model(dirname,
...
@@ -342,12 +342,6 @@ def save_inference_model(dirname,
prepend_feed_ops
(
inference_program
,
feeded_var_names
)
prepend_feed_ops
(
inference_program
,
feeded_var_names
)
append_fetch_ops
(
inference_program
,
fetch_var_names
)
append_fetch_ops
(
inference_program
,
fetch_var_names
)
# save for checking
curstr
=
inference_program
.
to_string
(
True
)
f
=
open
(
"save_inf_prog_after_feed_fetch.txt"
,
'w'
)
f
.
write
(
curstr
)
f
.
close
()
model_file_name
=
dirname
+
"/__model__"
model_file_name
=
dirname
+
"/__model__"
with
open
(
model_file_name
,
"wb"
)
as
f
:
with
open
(
model_file_name
,
"wb"
)
as
f
:
f
.
write
(
inference_program
.
desc
.
serialize_to_string
())
f
.
write
(
inference_program
.
desc
.
serialize_to_string
())
...
...
python/paddle/v2/fluid/tests/book/test_rnn_encoder_decoder.py
浏览文件 @
d5686f58
...
@@ -225,18 +225,8 @@ def infer(save_dirname=None):
...
@@ -225,18 +225,8 @@ def infer(save_dirname=None):
# Construct feed as a dictionary of {feed_target_name: feed_target_data}
# Construct feed as a dictionary of {feed_target_name: feed_target_data}
# and results will contain a list of data corresponding to fetch_targets.
# and results will contain a list of data corresponding to fetch_targets.
print
(
"Print feed fetch target names as follows"
)
print
(
feed_target_names
)
assert
feed_target_names
[
0
]
==
'source_sequence'
assert
feed_target_names
[
0
]
==
'source_sequence'
assert
feed_target_names
[
1
]
==
'target_sequence'
assert
feed_target_names
[
1
]
==
'target_sequence'
print
([
var
.
name
for
var
in
fetch_targets
])
# save for checking
curstr
=
inference_program
.
to_string
(
True
)
f
=
open
(
"loaded_infer_prog.txt"
,
'w'
)
f
.
write
(
curstr
)
f
.
close
()
results
=
exe
.
run
(
inference_program
,
results
=
exe
.
run
(
inference_program
,
feed
=
{
feed
=
{
feed_target_names
[
0
]:
word_data
,
feed_target_names
[
0
]:
word_data
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录