Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
7a8635d8
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看板
未验证
提交
7a8635d8
编写于
5月 10, 2023
作者:
C
co63oc
提交者:
GitHub
5月 10, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add elementwise_heaviside tests (#53549)
上级
ee1aa69c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
51 addition
and
5 deletion
+51
-5
paddle/phi/kernels/gpu/elementwise_grad_kernel.cu
paddle/phi/kernels/gpu/elementwise_grad_kernel.cu
+1
-0
paddle/phi/kernels/kps/elementwise_kernel.cu
paddle/phi/kernels/kps/elementwise_kernel.cu
+1
-0
python/paddle/fluid/tests/unittests/test_elementwise_heaviside_op.py
...le/fluid/tests/unittests/test_elementwise_heaviside_op.py
+49
-5
未找到文件。
paddle/phi/kernels/gpu/elementwise_grad_kernel.cu
浏览文件 @
7a8635d8
...
@@ -139,6 +139,7 @@ PD_REGISTER_KERNEL(heaviside_grad,
...
@@ -139,6 +139,7 @@ PD_REGISTER_KERNEL(heaviside_grad,
double
,
double
,
int
,
int
,
phi
::
dtype
::
float16
,
phi
::
dtype
::
float16
,
phi
::
dtype
::
bfloat16
,
int64_t
)
{}
int64_t
)
{}
PD_REGISTER_KERNEL
(
elementwise_pow_grad
,
PD_REGISTER_KERNEL
(
elementwise_pow_grad
,
...
...
paddle/phi/kernels/kps/elementwise_kernel.cu
浏览文件 @
7a8635d8
...
@@ -177,5 +177,6 @@ PD_REGISTER_KERNEL(heaviside,
...
@@ -177,5 +177,6 @@ PD_REGISTER_KERNEL(heaviside,
double
,
double
,
int
,
int
,
float16
,
float16
,
bfloat16
,
int64_t
)
{}
int64_t
)
{}
#endif
#endif
python/paddle/fluid/tests/unittests/test_elementwise_heaviside_op.py
浏览文件 @
7a8635d8
...
@@ -15,15 +15,19 @@
...
@@ -15,15 +15,19 @@
import
unittest
import
unittest
import
numpy
as
np
import
numpy
as
np
from
eager_op_test
import
OpTest
from
eager_op_test
import
OpTest
,
convert_float_to_uint16
import
paddle
import
paddle
from
paddle.fluid
import
core
def
Heaviside_grad
(
x
,
y
,
dout
):
def
Heaviside_grad
(
x
,
y
,
dout
,
astype
=
"float16"
,
is_bfloat16
=
False
):
tmp
=
np
.
zeros
(
x
.
shape
).
astype
(
"float16"
)
tmp
=
np
.
zeros
(
x
.
shape
).
astype
(
astype
)
dx
=
np
.
multiply
(
tmp
,
dout
)
dx
=
np
.
multiply
(
tmp
,
dout
)
dy
=
np
.
multiply
(
np
.
equal
(
x
,
0
),
dout
).
astype
(
"float16"
)
dy
=
np
.
multiply
(
np
.
equal
(
x
,
0
),
dout
).
astype
(
astype
)
if
is_bfloat16
:
dx
=
convert_float_to_uint16
(
dx
)
dy
=
convert_float_to_uint16
(
dy
)
return
dx
,
dy
return
dx
,
dy
...
@@ -161,7 +165,7 @@ class TestHeavisideAPI_int32(TestHeavisideAPI_float64):
...
@@ -161,7 +165,7 @@ class TestHeavisideAPI_int32(TestHeavisideAPI_float64):
self
.
dtype
=
"int32"
self
.
dtype
=
"int32"
class
TestHeaviside
API_float16
(
OpTest
):
class
TestHeaviside
FP16Op
(
OpTest
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
dtype
=
np
.
float16
self
.
dtype
=
np
.
float16
self
.
op_type
=
"elementwise_heaviside"
self
.
op_type
=
"elementwise_heaviside"
...
@@ -185,6 +189,46 @@ class TestHeavisideAPI_float16(OpTest):
...
@@ -185,6 +189,46 @@ class TestHeavisideAPI_float16(OpTest):
)
)
@
unittest
.
skipIf
(
not
core
.
is_compiled_with_cuda
()
or
not
core
.
is_bfloat16_supported
(
core
.
CUDAPlace
(
0
)),
"core is not compiled with CUDA or not support bfloat16"
,
)
class
TestHeavisideBF16Op
(
OpTest
):
def
setUp
(
self
):
self
.
dtype
=
np
.
uint16
self
.
np_dtype
=
np
.
float32
self
.
op_type
=
"elementwise_heaviside"
self
.
python_api
=
paddle
.
heaviside
self
.
inputs
=
{
'X'
:
np
.
random
.
uniform
(
1
,
2
,
[
20
,
5
]).
astype
(
self
.
np_dtype
),
'Y'
:
np
.
random
.
uniform
(
1
,
2
,
[
20
,
5
]).
astype
(
self
.
np_dtype
),
}
self
.
outputs
=
{
'Out'
:
np
.
heaviside
(
self
.
inputs
[
'X'
],
self
.
inputs
[
'Y'
])}
self
.
place
=
core
.
CUDAPlace
(
0
)
self
.
inputs
[
'X'
]
=
convert_float_to_uint16
(
self
.
inputs
[
'X'
])
self
.
inputs
[
'Y'
]
=
convert_float_to_uint16
(
self
.
inputs
[
'Y'
])
self
.
outputs
[
'Out'
]
=
convert_float_to_uint16
(
self
.
outputs
[
'Out'
])
def
test_check_output
(
self
):
self
.
check_output_with_place
(
self
.
place
)
def
test_check_grad
(
self
):
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
,
'Y'
],
'Out'
,
user_defined_grads
=
Heaviside_grad
(
self
.
inputs
[
'X'
],
self
.
inputs
[
'Y'
],
1
/
self
.
inputs
[
'X'
].
size
,
self
.
np_dtype
,
True
,
),
)
class
TestHeavisideError
(
unittest
.
TestCase
):
class
TestHeavisideError
(
unittest
.
TestCase
):
def
test_input
(
self
):
def
test_input
(
self
):
paddle
.
disable_static
()
paddle
.
disable_static
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录