Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
csdn_franckjun
Paddle
提交
2c4cc68f
P
Paddle
项目概览
csdn_franckjun
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
2c4cc68f
编写于
6月 25, 2021
作者:
王
王明冬
提交者:
GitHub
6月 25, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add compat precondition for repeated_fc_relu_fuse_pass,test=develop. (#33742)
上级
98d25314
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
42 addition
and
3 deletion
+42
-3
paddle/fluid/framework/ir/op_compat_sensible_pass.cc
paddle/fluid/framework/ir/op_compat_sensible_pass.cc
+7
-0
paddle/fluid/framework/ir/op_compat_sensible_pass.h
paddle/fluid/framework/ir/op_compat_sensible_pass.h
+2
-0
paddle/fluid/framework/ir/repeated_fc_relu_fuse_pass.cc
paddle/fluid/framework/ir/repeated_fc_relu_fuse_pass.cc
+28
-2
paddle/fluid/framework/ir/repeated_fc_relu_fuse_pass.h
paddle/fluid/framework/ir/repeated_fc_relu_fuse_pass.h
+5
-1
未找到文件。
paddle/fluid/framework/ir/op_compat_sensible_pass.cc
浏览文件 @
2c4cc68f
...
@@ -23,6 +23,13 @@ namespace paddle {
...
@@ -23,6 +23,13 @@ namespace paddle {
namespace
framework
{
namespace
framework
{
namespace
ir
{
namespace
ir
{
AttrCompat
&
AttrCompat
::
IsStringEQ
(
const
std
::
string
&
value
)
{
conditions_
.
emplace_back
([
value
](
const
Attribute
&
attr
)
->
bool
{
return
value
==
BOOST_GET_CONST
(
std
::
string
,
attr
);
});
return
*
this
;
}
AttrCompat
&
AttrCompat
::
IsStringIn
(
const
std
::
set
<
std
::
string
>&
candidates
)
{
AttrCompat
&
AttrCompat
::
IsStringIn
(
const
std
::
set
<
std
::
string
>&
candidates
)
{
conditions_
.
emplace_back
([
candidates
](
const
Attribute
&
attr
)
->
bool
{
conditions_
.
emplace_back
([
candidates
](
const
Attribute
&
attr
)
->
bool
{
std
::
string
value
=
BOOST_GET_CONST
(
std
::
string
,
attr
);
std
::
string
value
=
BOOST_GET_CONST
(
std
::
string
,
attr
);
...
...
paddle/fluid/framework/ir/op_compat_sensible_pass.h
浏览文件 @
2c4cc68f
...
@@ -37,6 +37,8 @@ class AttrCompat {
...
@@ -37,6 +37,8 @@ class AttrCompat {
// @{ String-related methods
// @{ String-related methods
//! Assert the attribute is an string in the `candidates` domain.
//! Assert the attribute is an string in the `candidates` domain.
AttrCompat
&
IsStringEQ
(
const
std
::
string
&
value
);
//! Assert the attribute is an string in the `candidates` domain.
AttrCompat
&
IsStringIn
(
const
std
::
set
<
std
::
string
>&
candidates
);
AttrCompat
&
IsStringIn
(
const
std
::
set
<
std
::
string
>&
candidates
);
//! Assert the attribute is a string and match a custom judging function.
//! Assert the attribute is a string and match a custom judging function.
AttrCompat
&
IsStringMatch
(
AttrCompat
&
IsStringMatch
(
...
...
paddle/fluid/framework/ir/repeated_fc_relu_fuse_pass.cc
浏览文件 @
2c4cc68f
...
@@ -31,6 +31,27 @@ namespace paddle {
...
@@ -31,6 +31,27 @@ namespace paddle {
namespace
framework
{
namespace
framework
{
namespace
ir
{
namespace
ir
{
RepeatedFCReluFusePass
::
RepeatedFCReluFusePass
()
{
AddOpCompat
(
OpCompat
(
"fc"
))
.
AddInput
(
"Input"
)
.
IsTensor
()
.
End
()
.
AddInput
(
"W"
)
.
IsTensor
()
.
End
()
.
AddInput
(
"Bias"
)
.
IsTensor
()
.
End
()
.
AddOutput
(
"Out"
)
.
IsTensor
()
.
End
()
.
AddAttr
(
"in_num_col_dims"
)
.
IsNumEQ
(
1
)
.
End
()
.
AddAttr
(
"activation_type"
)
.
IsStringEQ
(
"relu"
)
.
End
();
}
static
bool
IsInputOfFC
(
Node
*
n
)
{
static
bool
IsInputOfFC
(
Node
*
n
)
{
if
(
n
&&
n
->
IsVar
()
&&
VarLinksToOp
(
n
,
"fc"
))
{
if
(
n
&&
n
->
IsVar
()
&&
VarLinksToOp
(
n
,
"fc"
))
{
return
true
;
return
true
;
...
@@ -295,8 +316,9 @@ void BuildRepeatedFCReluPattern(PDPattern* pattern,
...
@@ -295,8 +316,9 @@ void BuildRepeatedFCReluPattern(PDPattern* pattern,
}
}
}
}
static
int
BuildFusion
(
Graph
*
graph
,
const
std
::
string
&
name_scope
,
int
RepeatedFCReluFusePass
::
BuildFusion
(
Graph
*
graph
,
int
num_fc
)
{
const
std
::
string
&
name_scope
,
int
num_fc
)
const
{
GraphPatternDetector
gpd
;
GraphPatternDetector
gpd
;
auto
*
pattern
=
gpd
.
mutable_pattern
();
auto
*
pattern
=
gpd
.
mutable_pattern
();
BuildRepeatedFCReluPattern
(
pattern
,
name_scope
,
num_fc
);
BuildRepeatedFCReluPattern
(
pattern
,
name_scope
,
num_fc
);
...
@@ -316,6 +338,10 @@ static int BuildFusion(Graph* graph, const std::string& name_scope,
...
@@ -316,6 +338,10 @@ static int BuildFusion(Graph* graph, const std::string& name_scope,
int
fusion_count
{
0
};
int
fusion_count
{
0
};
auto
handler
=
[
&
](
const
GraphPatternDetector
::
subgraph_t
&
subgraph
,
auto
handler
=
[
&
](
const
GraphPatternDetector
::
subgraph_t
&
subgraph
,
Graph
*
g
)
{
Graph
*
g
)
{
if
(
!
IsCompat
(
subgraph
,
g
))
{
LOG
(
WARNING
)
<<
"repeated_fc_relu_fuse_pass failed in op compat."
;
return
;
}
LOG
(
INFO
)
<<
"handle Repeated FC Act fuse"
;
LOG
(
INFO
)
<<
"handle Repeated FC Act fuse"
;
std
::
vector
<
Node
*>
weights_vars
(
num_fc
);
std
::
vector
<
Node
*>
weights_vars
(
num_fc
);
std
::
vector
<
Node
*>
bias_vars
(
num_fc
);
std
::
vector
<
Node
*>
bias_vars
(
num_fc
);
...
...
paddle/fluid/framework/ir/repeated_fc_relu_fuse_pass.h
浏览文件 @
2c4cc68f
...
@@ -31,12 +31,16 @@ class Graph;
...
@@ -31,12 +31,16 @@ class Graph;
class
RepeatedFCReluFusePass
:
public
FusePassBase
{
class
RepeatedFCReluFusePass
:
public
FusePassBase
{
public:
public:
virtual
~
RepeatedFCReluFusePass
()
{}
RepeatedFCReluFusePass
();
protected:
protected:
void
ApplyImpl
(
ir
::
Graph
*
graph
)
const
override
;
void
ApplyImpl
(
ir
::
Graph
*
graph
)
const
override
;
const
std
::
string
name_scope_
{
"repeated_fc_relu_fuse"
};
const
std
::
string
name_scope_
{
"repeated_fc_relu_fuse"
};
private:
int
BuildFusion
(
Graph
*
graph
,
const
std
::
string
&
name_scope
,
int
num_fc
)
const
;
};
};
}
// namespace ir
}
// namespace ir
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录