Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
1bd9cfef
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
1bd9cfef
编写于
10月 08, 2021
作者:
A
arlesniak
提交者:
GitHub
10月 08, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added oneDNN BF16 relu (#36265)
* Added oneDNN BF16 relu * fixed typo * refactored test, review fixes
上级
9814f895
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
40 addition
and
7 deletion
+40
-7
paddle/fluid/operators/mkldnn/activation_mkldnn_op.cc
paddle/fluid/operators/mkldnn/activation_mkldnn_op.cc
+2
-1
python/paddle/fluid/tests/unittests/mkldnn/test_activation_bf16_mkldnn_op.py
.../tests/unittests/mkldnn/test_activation_bf16_mkldnn_op.py
+38
-6
未找到文件。
paddle/fluid/operators/mkldnn/activation_mkldnn_op.cc
浏览文件 @
1bd9cfef
...
...
@@ -257,7 +257,6 @@ namespace ops = paddle::operators;
ops::grad_functor<paddle::platform::bfloat16>>);
#define FOR_EACH_MKLDNN_KERNEL_FUNCTOR(__macro) \
__macro(relu, ReluMKLDNNFunctor, ReluMKLDNNGradFunctor); \
__macro(relu6, Relu6MKLDNNFunctor, Relu6MKLDNNGradFunctor); \
__macro(leaky_relu, ReluMKLDNNFunctor, ReluMKLDNNGradFunctor); \
__macro(swish, SwishMKLDNNFunctor, SwishMKLDNNGradFunctor); \
...
...
@@ -267,6 +266,8 @@ namespace ops = paddle::operators;
__macro(abs, AbsMKLDNNFunctor, AbsMKLDNNGradFunctor);
FOR_EACH_MKLDNN_KERNEL_FUNCTOR
(
REGISTER_ACTIVATION_MKLDNN_KERNEL
);
REGISTER_ACTIVATION_MKLDNN_BF16_KERNEL
(
relu
,
ReluMKLDNNFunctor
,
ReluMKLDNNGradFunctor
);
REGISTER_ACTIVATION_MKLDNN_BF16_KERNEL
(
gelu
,
GeluMKLDNNFunctor
,
GeluMKLDNNGradFunctor
);
REGISTER_ACTIVATION_MKLDNN_BF16_KERNEL
(
sigmoid
,
SigmoidMKLDNNFunctor
,
...
...
python/paddle/fluid/tests/unittests/mkldnn/test_activation_bf16_mkldnn_op.py
浏览文件 @
1bd9cfef
...
...
@@ -14,6 +14,8 @@
from
__future__
import
print_function
import
six
import
abc
import
unittest
import
numpy
as
np
from
scipy.special
import
expit
,
erf
...
...
@@ -24,15 +26,19 @@ from paddle.fluid.tests.unittests.test_gelu_op import gelu
@
OpTestTool
.
skip_if_not_cpu_bf16
()
class
TestMKLDNNSigmoidBF16Op
(
TestActivation
):
@
six
.
add_metaclass
(
abc
.
ABCMeta
)
class
MKLDNNBF16ActivationOp
(
object
):
@
abc
.
abstractmethod
def
config
(
self
):
self
.
op_type
=
"sigmoid"
pass
@
abc
.
abstractmethod
def
op_forward
(
self
,
x
):
return
1
/
(
1
+
np
.
exp
(
-
x
))
pass
@
abc
.
abstractmethod
def
op_grad
(
self
,
dout
,
x
):
return
dout
*
self
.
op_forward
(
x
)
*
(
1
-
self
.
op_forward
(
x
))
pass
def
set_attrs
(
self
):
self
.
attrs
=
{
"use_mkldnn"
:
True
}
...
...
@@ -65,7 +71,18 @@ class TestMKLDNNSigmoidBF16Op(TestActivation):
user_defined_grad_outputs
=
[
convert_float_to_uint16
(
self
.
out
)])
class
TestMKLDNNGeluErfBF16Op
(
TestMKLDNNSigmoidBF16Op
):
class
TestMKLDNNSigmoidBF16Op
(
MKLDNNBF16ActivationOp
,
TestActivation
):
def
config
(
self
):
self
.
op_type
=
"sigmoid"
def
op_forward
(
self
,
x
):
return
1
/
(
1
+
np
.
exp
(
-
x
))
def
op_grad
(
self
,
dout
,
x
):
return
dout
*
self
.
op_forward
(
x
)
*
(
1
-
self
.
op_forward
(
x
))
class
TestMKLDNNGeluErfBF16Op
(
MKLDNNBF16ActivationOp
,
TestActivation
):
def
config
(
self
):
self
.
op_type
=
"gelu"
...
...
@@ -83,7 +100,7 @@ class TestMKLDNNGeluErfDim2BF16Op(TestMKLDNNGeluErfBF16Op):
self
.
x
=
np
.
random
.
uniform
(
-
1
,
1
,
[
11
,
17
]).
astype
(
np
.
float32
)
class
TestMKLDNNGeluTanhBF16Op
(
TestMKLDNNSigmoidBF16Op
):
class
TestMKLDNNGeluTanhBF16Op
(
MKLDNNBF16ActivationOp
,
TestActivation
):
def
config
(
self
):
self
.
op_type
=
"gelu"
...
...
@@ -104,3 +121,18 @@ class TestMKLDNNGeluTanhBF16Op(TestMKLDNNSigmoidBF16Op):
class
TestMKLDNNGeluTanhDim2BF16Op
(
TestMKLDNNGeluTanhBF16Op
):
def
init_data
(
self
):
self
.
x
=
np
.
random
.
uniform
(
-
1
,
1
,
[
11
,
17
]).
astype
(
np
.
float32
)
class
TestMKLDNNReluBF16Op
(
MKLDNNBF16ActivationOp
,
TestActivation
):
def
config
(
self
):
self
.
op_type
=
"relu"
def
op_forward
(
self
,
x
):
return
np
.
maximum
(
x
,
0
)
def
op_grad
(
self
,
dout
,
x
):
return
dout
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录