Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
ae40ee32
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看板
未验证
提交
ae40ee32
编写于
11月 16, 2021
作者:
J
jakpiase
提交者:
GitHub
11月 16, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added onednn elu kernel (#37149)
上级
a9e7a854
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
48 addition
and
8 deletion
+48
-8
paddle/fluid/operators/activation_op.cc
paddle/fluid/operators/activation_op.cc
+8
-0
paddle/fluid/operators/mkldnn/activation_mkldnn_op.cc
paddle/fluid/operators/mkldnn/activation_mkldnn_op.cc
+17
-8
python/paddle/fluid/tests/unittests/mkldnn/test_activation_mkldnn_op.py
...fluid/tests/unittests/mkldnn/test_activation_mkldnn_op.py
+23
-0
未找到文件。
paddle/fluid/operators/activation_op.cc
浏览文件 @
ae40ee32
...
...
@@ -568,6 +568,10 @@ class ELUOpMaker : public framework::OpProtoAndCheckerMaker {
"The output is a multi-dimensional Tensor which has same "
"dimension and data type as the ``x``."
);
AddAttr
<
float
>
(
"alpha"
,
"The alpha value of ELU"
).
SetDefault
(
1.0
f
);
AddAttr
<
bool
>
(
"use_mkldnn"
,
"(bool, default false) Only used in mkldnn kernel"
)
.
SetDefault
(
false
)
.
AsExtra
();
AddComment
(
R"DOC(
ELU Activation Operator.
...
...
@@ -743,6 +747,10 @@ class HardSwishOpMaker : public framework::OpProtoAndCheckerMaker {
.
SetDefault
(
6.0
f
);
AddAttr
<
float
>
(
"offset"
,
"The offset parameter of HardSwish operator"
)
.
SetDefault
(
3.0
f
);
AddAttr
<
bool
>
(
"use_mkldnn"
,
"(bool, default false) Only used in mkldnn kernel"
)
.
SetDefault
(
false
)
.
AsExtra
();
AddComment
(
R"DOC(
HardSwish Activation Operator.
...
...
paddle/fluid/operators/mkldnn/activation_mkldnn_op.cc
浏览文件 @
ae40ee32
...
...
@@ -209,6 +209,10 @@ template <typename T>
using
AbsMKLDNNFunctor
=
MKLDNNActivationFunc
<
T
,
mkldnn
::
algorithm
::
eltwise_abs
>
;
template
<
typename
T
>
using
EluMKLDNNFunctor
=
MKLDNNActivationFunc
<
T
,
mkldnn
::
algorithm
::
eltwise_elu
>
;
template
<
typename
T
>
using
ReluMKLDNNGradFunctor
=
MKLDNNActivationGradFunc
<
T
,
mkldnn
::
algorithm
::
eltwise_relu
>
;
...
...
@@ -240,6 +244,10 @@ using SqrtMKLDNNGradFunctor =
template
<
typename
T
>
using
AbsMKLDNNGradFunctor
=
MKLDNNActivationGradFunc
<
T
,
mkldnn
::
algorithm
::
eltwise_abs
>
;
template
<
typename
T
>
using
EluMKLDNNGradFunctor
=
MKLDNNActivationGradFunc
<
T
,
mkldnn
::
algorithm
::
eltwise_elu
>
;
}
// namespace operators
}
// namespace paddle
...
...
@@ -264,14 +272,15 @@ namespace ops = paddle::operators;
ops::MKLDNNActivationGradKernel< \
ops::grad_functor<paddle::platform::bfloat16>>);
#define FOR_EACH_MKLDNN_KERNEL_FUNCTOR(__macro) \
__macro(relu6, Relu6MKLDNNFunctor, Relu6MKLDNNGradFunctor); \
__macro(leaky_relu, ReluMKLDNNFunctor, ReluMKLDNNGradFunctor); \
__macro(swish, SwishMKLDNNFunctor, SwishMKLDNNGradFunctor); \
__macro(hardswish, HardSwishMKLDNNFunctor, HardSwishMKLDNNGradFunctor); \
__macro(tanh, TanhMKLDNNFunctor, TanhMKLDNNGradFunctor); \
__macro(sqrt, SqrtMKLDNNFunctor, SqrtMKLDNNGradFunctor); \
__macro(abs, AbsMKLDNNFunctor, AbsMKLDNNGradFunctor);
#define FOR_EACH_MKLDNN_KERNEL_FUNCTOR(__macro) \
__macro(relu6, Relu6MKLDNNFunctor, Relu6MKLDNNGradFunctor); \
__macro(leaky_relu, ReluMKLDNNFunctor, ReluMKLDNNGradFunctor); \
__macro(swish, SwishMKLDNNFunctor, SwishMKLDNNGradFunctor); \
__macro(hard_swish, HardSwishMKLDNNFunctor, HardSwishMKLDNNGradFunctor); \
__macro(tanh, TanhMKLDNNFunctor, TanhMKLDNNGradFunctor); \
__macro(sqrt, SqrtMKLDNNFunctor, SqrtMKLDNNGradFunctor); \
__macro(abs, AbsMKLDNNFunctor, AbsMKLDNNGradFunctor); \
__macro(elu, EluMKLDNNFunctor, EluMKLDNNGradFunctor);
FOR_EACH_MKLDNN_KERNEL_FUNCTOR
(
REGISTER_ACTIVATION_MKLDNN_KERNEL
);
REGISTER_ACTIVATION_MKLDNN_BF16_KERNEL
(
relu
,
ReluMKLDNNFunctor
,
...
...
python/paddle/fluid/tests/unittests/mkldnn/test_activation_mkldnn_op.py
浏览文件 @
ae40ee32
...
...
@@ -326,6 +326,29 @@ class TestMKLDNNSigmoidDim4(TestSigmoid):
self
.
attrs
=
{
"use_mkldnn"
:
True
}
class
TestMKLDNNEluDefaultAlpha
(
TestActivation
):
def
setUp
(
self
):
self
.
op_type
=
"elu"
self
.
set_alpha
()
x
=
np
.
random
.
random
((
5
,
5
,
4
)).
astype
(
"float32"
)
self
.
inputs
=
{
'X'
:
x
}
self
.
attrs
=
{
'use_mkldnn'
:
True
,
'alpha'
:
self
.
alpha
}
self
.
outputs
=
{
'Out'
:
np
.
maximum
(
0
,
x
)
+
np
.
minimum
(
0
,
self
.
alpha
*
(
np
.
exp
(
x
)
-
1
))
}
def
set_alpha
(
self
):
self
.
alpha
=
1.0
class
TestMKLDNNEluCustomAlpha
(
TestMKLDNNEluDefaultAlpha
):
def
set_alpha
(
self
):
self
.
alpha
=
2.5
# Check if primitives already exist in backward
class
TestMKLDNNAbsPrimitivesAlreadyExist
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录