Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
efc3b182
P
Paddle
项目概览
Crayon鑫
/
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看板
未验证
提交
efc3b182
编写于
11月 20, 2020
作者:
W
Wojciech Uss
提交者:
GitHub
11月 20, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
a fix for the fc_lstm_fuse_pass (#28709)
上级
3b0dd5f6
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
14 addition
and
17 deletion
+14
-17
paddle/fluid/framework/ir/fc_lstm_fuse_pass.cc
paddle/fluid/framework/ir/fc_lstm_fuse_pass.cc
+14
-17
未找到文件。
paddle/fluid/framework/ir/fc_lstm_fuse_pass.cc
浏览文件 @
efc3b182
...
...
@@ -36,9 +36,7 @@ int BuildFusion(Graph* graph, const std::string& name_scope, Scope* scope,
->
assert_var_not_persistable
();
patterns
::
FC
fc_pattern
(
pattern
,
name_scope
);
// fc_out is a tmp var, will be removed after fuse, so marked as intermediate.
auto
*
fc_out
=
fc_pattern
(
x
,
with_fc_bias
,
/* with_relu */
false
)
->
AsIntermediate
();
auto
*
fc_out
=
fc_pattern
(
x
,
with_fc_bias
,
/* with_relu */
false
);
patterns
::
LSTM
lstm_pattern
(
pattern
,
name_scope
);
lstm_pattern
(
fc_out
);
...
...
@@ -58,28 +56,25 @@ int BuildFusion(Graph* graph, const std::string& name_scope, Scope* scope,
// Add FC-bias with LSTM-bias and create a new weight
PADDLE_ENFORCE_NOT_NULL
(
scope
,
platform
::
errors
::
InvalidArgument
(
"Scope cannot be nullptr."
));
const
std
::
string
&
new_bias_var
=
patterns
::
UniqueKey
(
"NewBias"
);
auto
*
bias_var
=
scope
->
Var
(
new_bias_var
);
PADDLE_ENFORCE_NOT_NULL
(
bias_var
,
platform
::
errors
::
InvalidArgument
(
"Bias var ptr cannot be nullptr."
));
auto
*
bias_tensor
=
bias_var
->
GetMutable
<
framework
::
LoDTensor
>
();
auto
*
lstm_bias_var
=
scope
->
FindVar
(
bias
->
Name
());
auto
*
fc_bias_var
=
scope
->
FindVar
(
fc_bias
->
Name
());
PADDLE_ENFORCE_NOT_NULL
(
lstm_bias_var
,
platform
::
errors
::
InvalidArgument
(
"Lstm bias var ptr cannot be nullptr."
));
const
auto
&
lstm_bias_tensor
=
lstm_bias_var
->
Get
<
framework
::
LoDTensor
>
();
bias_tensor
->
Resize
(
lstm_bias_tensor
.
dims
());
auto
*
fc_bias_var
=
scope
->
FindVar
(
fc_bias
->
Name
());
PADDLE_ENFORCE_NOT_NULL
(
fc_bias_var
,
platform
::
errors
::
InvalidArgument
(
"FC bias var ptr cannot be nullptr."
));
auto
*
lstm_bias_tensor
=
lstm_bias_var
->
GetMutable
<
framework
::
LoDTensor
>
();
const
auto
&
fc_bias_tensor
=
fc_bias_var
->
Get
<
framework
::
LoDTensor
>
();
auto
*
data
=
bias_tensor
->
mutable_data
<
float
>
(
platform
::
CPUPlace
());
auto
lstm_bias_data
=
lstm_bias_tensor
->
mutable_data
<
float
>
(
platform
::
CPUPlace
());
auto
*
fc_bias_data
=
fc_bias_tensor
.
data
<
float
>
();
for
(
int
i
=
0
;
i
<
bias_tensor
->
numel
();
i
++
)
{
data
[
i
]
=
fc_bias_tensor
.
data
<
float
>
()[
i
]
+
lstm_bias_tensor
.
data
<
float
>
()[
i
];
for
(
int
i
=
0
;
i
<
lstm_bias_tensor
->
numel
();
i
++
)
{
lstm_bias_data
[
i
]
+=
fc_bias_data
[
i
];
}
op_desc
.
SetInput
(
"Bias"
,
{
new_bias_var
});
}
op_desc
.
SetInput
(
"H0"
,
{});
...
...
@@ -114,6 +109,8 @@ int BuildFusion(Graph* graph, const std::string& name_scope, Scope* scope,
IR_NODE_LINK_TO
(
weight_h
,
op
);
IR_NODE_LINK_TO
(
bias
,
op
);
IR_NODE_LINK_TO
(
op
,
hidden
);
IR_NODE_LINK_TO
(
op
,
cell
);
IR_NODE_LINK_TO
(
op
,
xx
);
#define IR_NODE(x) \
VarDesc key_##x(x); \
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录