Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
4ae9945b
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
未验证
提交
4ae9945b
编写于
8月 09, 2023
作者:
C
cyberslack_lee
提交者:
GitHub
8月 09, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add FP16 & BF16 for nanmedian (#56056)
上级
08e46d6f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
52 addition
and
4 deletion
+52
-4
paddle/phi/kernels/gpu/nanmedian_grad_kernel.cu
paddle/phi/kernels/gpu/nanmedian_grad_kernel.cu
+2
-1
paddle/phi/kernels/gpu/nanmedian_kernel.cu
paddle/phi/kernels/gpu/nanmedian_kernel.cu
+2
-1
python/paddle/tensor/stat.py
python/paddle/tensor/stat.py
+2
-2
test/legacy_test/test_nanmedian.py
test/legacy_test/test_nanmedian.py
+46
-0
未找到文件。
paddle/phi/kernels/gpu/nanmedian_grad_kernel.cu
浏览文件 @
4ae9945b
...
@@ -123,4 +123,5 @@ PD_REGISTER_KERNEL(nanmedian_grad,
...
@@ -123,4 +123,5 @@ PD_REGISTER_KERNEL(nanmedian_grad,
double
,
double
,
int
,
int
,
int64_t
,
int64_t
,
phi
::
dtype
::
float16
)
{}
phi
::
dtype
::
float16
,
phi
::
dtype
::
bfloat16
)
{}
paddle/phi/kernels/gpu/nanmedian_kernel.cu
浏览文件 @
4ae9945b
...
@@ -287,6 +287,7 @@ PD_REGISTER_KERNEL(nanmedian,
...
@@ -287,6 +287,7 @@ PD_REGISTER_KERNEL(nanmedian,
double
,
double
,
int
,
int
,
int64_t
,
int64_t
,
phi
::
dtype
::
float16
)
{
phi
::
dtype
::
float16
,
phi
::
dtype
::
bfloat16
)
{
kernel
->
OutputAt
(
1
).
SetDataType
(
phi
::
DataType
::
INT64
);
kernel
->
OutputAt
(
1
).
SetDataType
(
phi
::
DataType
::
INT64
);
}
}
python/paddle/tensor/stat.py
浏览文件 @
4ae9945b
...
@@ -265,7 +265,7 @@ def nanmedian(x, axis=None, keepdim=False, name=None):
...
@@ -265,7 +265,7 @@ def nanmedian(x, axis=None, keepdim=False, name=None):
the average value of both elements in the middle is calculated as the median.
the average value of both elements in the middle is calculated as the median.
Args:
Args:
x (Tensor): The input Tensor, it's data type can be int32, int64, float16, float32, float64.
x (Tensor): The input Tensor, it's data type can be int32, int64, float16,
bfloat16,
float32, float64.
axis (None|int|list|tuple, optional):
axis (None|int|list|tuple, optional):
The axis along which to perform median calculations ``axis`` should be int or list of int.
The axis along which to perform median calculations ``axis`` should be int or list of int.
``axis`` should be in range [-D, D), where D is the dimensions of ``x`` .
``axis`` should be in range [-D, D), where D is the dimensions of ``x`` .
...
@@ -319,7 +319,7 @@ def nanmedian(x, axis=None, keepdim=False, name=None):
...
@@ -319,7 +319,7 @@ def nanmedian(x, axis=None, keepdim=False, name=None):
check_variable_and_dtype
(
check_variable_and_dtype
(
x
,
x
,
'X'
,
'X'
,
[
'int32'
,
'int64'
,
'float16'
,
'float32'
,
'float64'
],
[
'int32'
,
'int64'
,
'float16'
,
'float32'
,
'float64'
,
'uint16'
],
'nanmedian'
,
'nanmedian'
,
)
)
...
...
test/legacy_test/test_nanmedian.py
浏览文件 @
4ae9945b
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
import
unittest
import
unittest
import
numpy
as
np
import
numpy
as
np
from
eager_op_test
import
OpTest
,
convert_float_to_uint16
import
paddle
import
paddle
from
paddle.fluid
import
core
from
paddle.fluid
import
core
...
@@ -243,5 +244,50 @@ class TestNanmedian(unittest.TestCase):
...
@@ -243,5 +244,50 @@ class TestNanmedian(unittest.TestCase):
np
.
testing
.
assert_allclose
(
x
.
grad
,
np
.
array
(
0.0
))
np
.
testing
.
assert_allclose
(
x
.
grad
,
np
.
array
(
0.0
))
class
TestNanmedianFP16Op
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"nanmedian"
self
.
python_api
=
paddle
.
nanmedian
self
.
public_python_api
=
paddle
.
nanmedian
self
.
dtype
=
np
.
float16
self
.
python_out_sig
=
[
"Out"
]
X
=
np
.
random
.
random
((
100
,
100
)).
astype
(
'float16'
)
Out
=
np
.
nanmedian
(
X
)
self
.
inputs
=
{
'X'
:
X
}
self
.
outputs
=
{
'Out'
:
Out
}
def
test_check_output
(
self
):
self
.
check_output
()
def
test_check_grad
(
self
):
self
.
check_grad
([
'X'
],
'Out'
)
@
unittest
.
skipIf
(
not
core
.
is_compiled_with_cuda
()
or
not
core
.
is_bfloat16_supported
(
core
.
CUDAPlace
(
0
)),
"core is not complied with CUDA and not support the bfloat16"
,
)
class
TestNanmedianBF16Op
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"nanmedian"
self
.
python_api
=
paddle
.
nanmedian
self
.
public_python_api
=
paddle
.
nanmedian
self
.
dtype
=
np
.
uint16
self
.
python_out_sig
=
[
"Out"
]
X
=
np
.
random
.
random
((
100
,
100
)).
astype
(
'float32'
)
Out
=
np
.
nanmedian
(
X
)
self
.
inputs
=
{
'X'
:
convert_float_to_uint16
(
X
)}
self
.
outputs
=
{
'Out'
:
convert_float_to_uint16
(
Out
)}
def
test_check_output
(
self
):
place
=
core
.
CUDAPlace
(
0
)
self
.
check_output_with_place
(
place
)
def
test_check_grad
(
self
):
place
=
core
.
CUDAPlace
(
0
)
self
.
check_grad_with_place
(
place
,
[
'X'
],
'Out'
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unittest
.
main
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录