Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
afeixing77
Paddle
提交
3ec0bcbb
P
Paddle
项目概览
afeixing77
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
3ec0bcbb
编写于
8月 19, 2020
作者:
W
Wilber
提交者:
GitHub
8月 19, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Bug] Fix prune for save_inference_model about transformer (#25347)
上级
3f816bc8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
50 addition
and
1 deletion
+50
-1
paddle/fluid/framework/prune.cc
paddle/fluid/framework/prune.cc
+17
-0
paddle/fluid/framework/prune_test.cc
paddle/fluid/framework/prune_test.cc
+31
-0
python/paddle/fluid/layers/rnn.py
python/paddle/fluid/layers/rnn.py
+2
-1
未找到文件。
paddle/fluid/framework/prune.cc
浏览文件 @
3ec0bcbb
...
@@ -210,6 +210,23 @@ void prune_impl(const proto::ProgramDesc& input, proto::ProgramDesc* output,
...
@@ -210,6 +210,23 @@ void prune_impl(const proto::ProgramDesc& input, proto::ProgramDesc* output,
should_run
.
push_back
(
true
);
should_run
.
push_back
(
true
);
}
else
{
}
else
{
should_run
.
push_back
(
false
);
should_run
.
push_back
(
false
);
// If the output of an op modifies feed vars, the op should not clip.
// For example, in the transformer structure, the third parameter returned
// by beam_search op is generally assigned to a feed var. Cutting the
// assign op will cause an error.
if
(
parent_block_id
!=
-
1
)
{
bool
flag
=
false
;
for
(
auto
&
var
:
op_desc
.
outputs
())
{
for
(
auto
&
argu
:
var
.
arguments
())
{
if
(
feed_var_names
.
count
(
argu
))
{
flag
=
true
;
}
}
}
if
(
flag
)
{
should_run
.
back
()
=
true
;
}
}
}
}
}
}
...
...
paddle/fluid/framework/prune_test.cc
浏览文件 @
3ec0bcbb
...
@@ -185,3 +185,34 @@ TEST(Prune, recurrrent_op) {
...
@@ -185,3 +185,34 @@ TEST(Prune, recurrrent_op) {
EXPECT_EQ
(
pruned
.
blocks
(
0
).
ops_size
(),
2
);
EXPECT_EQ
(
pruned
.
blocks
(
0
).
ops_size
(),
2
);
EXPECT_EQ
(
pruned
.
blocks
(
1
).
ops_size
(),
1
);
EXPECT_EQ
(
pruned
.
blocks
(
1
).
ops_size
(),
1
);
}
}
// If the output of an op modifies feed vars, the op should not clip.
TEST
(
Prune
,
recurrrent_op_2
)
{
f
::
ProgramDesc
program
;
f
::
BlockDesc
*
block
=
program
.
MutableBlock
(
0
);
f
::
BlockDesc
*
sub_block
=
program
.
AppendBlock
(
*
block
);
AddOp
(
"one_two"
,
{{
"input"
,
{
"a"
}}},
{{
"output"
,
{
"b"
,
"c"
}}},
f
::
AttributeMap
{},
block
);
std
::
vector
<
std
::
string
>
state_var_name
(
1
,
"y"
);
AddOp
(
"recurrent"
,
{{
"input"
,
{
"b"
,
"c"
}}},
{{
"output"
,
{
"b1, c1"
}}},
{{
"ex_states"
,
state_var_name
},
{
"states"
,
state_var_name
},
{
"sub_block"
,
sub_block
}},
block
);
EXPECT_TRUE
(
sub_block
!=
nullptr
);
AddOp
(
"rnn_memory_helper"
,
{{
"input"
,
{
"x"
}}},
{{
"output"
,
{
"a"
}}},
f
::
AttributeMap
{},
sub_block
);
f
::
proto
::
ProgramDesc
*
pdesc
=
program
.
Proto
();
pdesc
->
mutable_blocks
(
0
)
->
mutable_ops
(
1
)
->
set_is_target
(
true
);
f
::
proto
::
ProgramDesc
pruned
;
std
::
set
<
std
::
string
>
feed_var_names
=
{
"x"
,
"a"
};
f
::
Prune
(
*
pdesc
,
feed_var_names
,
&
pruned
);
EXPECT_EQ
(
pruned
.
blocks_size
(),
2
);
EXPECT_EQ
(
pruned
.
blocks
(
0
).
ops_size
(),
2
);
EXPECT_EQ
(
pruned
.
blocks
(
1
).
ops_size
(),
1
);
}
python/paddle/fluid/layers/rnn.py
浏览文件 @
3ec0bcbb
...
@@ -3102,7 +3102,8 @@ def beam_search_decode(ids, scores, beam_size, end_id, name=None):
...
@@ -3102,7 +3102,8 @@ def beam_search_decode(ids, scores, beam_size, end_id, name=None):
'beam_search_encode'
)
'beam_search_encode'
)
helper
=
LayerHelper
(
'beam_search_decode'
,
**
locals
())
helper
=
LayerHelper
(
'beam_search_decode'
,
**
locals
())
sentence_ids
=
helper
.
create_variable_for_type_inference
(
dtype
=
ids
.
dtype
)
sentence_ids
=
helper
.
create_variable_for_type_inference
(
dtype
=
ids
.
dtype
)
sentence_scores
=
helper
.
create_variable_for_type_inference
(
dtype
=
ids
.
dtype
)
sentence_scores
=
helper
.
create_variable_for_type_inference
(
dtype
=
scores
.
dtype
)
helper
.
append_op
(
helper
.
append_op
(
type
=
"beam_search_decode"
,
type
=
"beam_search_decode"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录