Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
b9e6364e
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
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看板
未验证
提交
b9e6364e
编写于
3月 21, 2018
作者:
K
Kexin Zhao
提交者:
GitHub
3月 21, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9267 from kexinzhao/new_relu_fp16
Add float16 support to relu op
上级
7c147242
018f3bda
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
50 addition
and
4 deletion
+50
-4
paddle/fluid/operators/activation_op.cc
paddle/fluid/operators/activation_op.cc
+11
-0
paddle/fluid/operators/activation_op.cu
paddle/fluid/operators/activation_op.cu
+14
-0
paddle/fluid/operators/activation_op.h
paddle/fluid/operators/activation_op.h
+0
-1
python/paddle/fluid/tests/unittests/test_activation_op.py
python/paddle/fluid/tests/unittests/test_activation_op.py
+25
-3
未找到文件。
paddle/fluid/operators/activation_op.cc
浏览文件 @
b9e6364e
...
...
@@ -613,3 +613,14 @@ REGISTER_OP(swish, ops::ActivationOp, ops::SwishOpMaker, swish_grad,
ops::grad_functor<double>>);
FOR_EACH_KERNEL_FUNCTOR
(
REGISTER_ACTIVATION_CPU_KERNEL
);
REGISTER_OP_CPU_KERNEL
(
relu
,
ops
::
ActivationKernel
<
paddle
::
platform
::
CPUDeviceContext
,
ops
::
ReluFunctor
<
float
>>
,
ops
::
ActivationKernel
<
paddle
::
platform
::
CPUDeviceContext
,
ops
::
ReluFunctor
<
double
>>
);
REGISTER_OP_CPU_KERNEL
(
relu_grad
,
ops
::
ActivationGradKernel
<
paddle
::
platform
::
CPUDeviceContext
,
ops
::
ReluGradFunctor
<
float
>>
,
ops
::
ActivationGradKernel
<
paddle
::
platform
::
CPUDeviceContext
,
ops
::
ReluGradFunctor
<
double
>>
);
paddle/fluid/operators/activation_op.cu
浏览文件 @
b9e6364e
...
...
@@ -14,6 +14,7 @@ limitations under the License. */
#define EIGEN_USE_GPU
#include "paddle/fluid/operators/activation_op.h"
#include "paddle/fluid/platform/float16.h"
namespace
ops
=
paddle
::
operators
;
...
...
@@ -31,3 +32,16 @@ namespace ops = paddle::operators;
ops::grad_functor<double>>);
FOR_EACH_KERNEL_FUNCTOR
(
REGISTER_ACTIVATION_CUDA_KERNEL
);
REGISTER_OP_CUDA_KERNEL
(
relu
,
ops
::
ActivationKernel
<
paddle
::
platform
::
CUDADeviceContext
,
ops
::
ReluFunctor
<
float
>>
,
ops
::
ActivationKernel
<
paddle
::
platform
::
CUDADeviceContext
,
ops
::
ReluFunctor
<
double
>>
,
ops
::
ActivationKernel
<
paddle
::
platform
::
CUDADeviceContext
,
ops
::
ReluFunctor
<
paddle
::
platform
::
float16
>>
);
REGISTER_OP_CUDA_KERNEL
(
relu_grad
,
ops
::
ActivationGradKernel
<
paddle
::
platform
::
CUDADeviceContext
,
ops
::
ReluGradFunctor
<
float
>>
,
ops
::
ActivationGradKernel
<
paddle
::
platform
::
CUDADeviceContext
,
ops
::
ReluGradFunctor
<
double
>>
);
paddle/fluid/operators/activation_op.h
浏览文件 @
b9e6364e
...
...
@@ -772,7 +772,6 @@ struct SwishGradFunctor : public BaseActivationFunctor<T> {
__macro(sigmoid, SigmoidFunctor, SigmoidGradFunctor); \
__macro(logsigmoid, LogSigmoidFunctor, LogSigmoidGradFunctor); \
__macro(exp, ExpFunctor, ExpGradFunctor); \
__macro(relu, ReluFunctor, ReluGradFunctor); \
__macro(tanh, TanhFunctor, TanhGradFunctor); \
__macro(softshrink, SoftShrinkFunctor, SoftShrinkGradFunctor); \
__macro(sqrt, SqrtFunctor, SqrtGradFunctor); \
...
...
python/paddle/fluid/tests/unittests/test_activation_op.py
浏览文件 @
b9e6364e
...
...
@@ -14,6 +14,7 @@
import
unittest
import
numpy
as
np
import
paddle.fluid.core
as
core
from
op_test
import
OpTest
from
scipy.special
import
expit
...
...
@@ -212,18 +213,39 @@ class TestRound(OpTest):
class
TestRelu
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"relu"
x
=
np
.
random
.
uniform
(
-
1
,
1
,
[
11
,
17
]).
astype
(
"float32"
)
self
.
dtype
=
np
.
float32
self
.
init_dtype
()
x
=
np
.
random
.
uniform
(
-
1
,
1
,
[
11
,
17
]).
astype
(
self
.
dtype
)
# The same reason with TestAbs
x
[
np
.
abs
(
x
)
<
0.005
]
=
0.02
self
.
inputs
=
{
'X'
:
x
}
self
.
outputs
=
{
'Out'
:
np
.
maximum
(
self
.
inputs
[
'X'
],
0
)}
out
=
np
.
maximum
(
x
,
0
)
self
.
inputs
=
{
'X'
:
OpTest
.
np_dtype_to_fluid_dtype
(
x
)}
self
.
outputs
=
{
'Out'
:
out
}
def
test_check_output
(
self
):
self
.
check_output
()
def
test_check_grad
(
self
):
if
self
.
dtype
==
np
.
float16
:
return
self
.
check_grad
([
'X'
],
'Out'
,
max_relative_error
=
0.007
)
def
init_dtype
(
self
):
pass
class
TestFP16Relu
(
TestRelu
):
def
init_dtype
(
self
):
self
.
dtype
=
np
.
float16
def
test_check_output
(
self
):
if
core
.
is_compiled_with_cuda
():
place
=
core
.
CUDAPlace
(
0
)
if
core
.
is_float16_supported
(
place
):
self
.
check_output_with_place
(
place
,
atol
=
1e-3
)
class
TestBRelu
(
OpTest
):
def
setUp
(
self
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录