Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
bc91012f
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看板
未验证
提交
bc91012f
编写于
4月 18, 2023
作者:
C
chenxujun
提交者:
GitHub
4月 18, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
【Hackathon No.60】randperm, split, split_with_num 算子FP16/BF16单测完善 (#52683)
* Add split, split_with_num tests * Add randperm tests * Fix code
上级
8b82f77e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
97 addition
and
23 deletion
+97
-23
paddle/phi/kernels/gpu/randperm_kernel.cu
paddle/phi/kernels/gpu/randperm_kernel.cu
+4
-1
python/paddle/fluid/tests/unittests/test_randperm_op.py
python/paddle/fluid/tests/unittests/test_randperm_op.py
+57
-3
python/paddle/fluid/tests/unittests/test_split_op.py
python/paddle/fluid/tests/unittests/test_split_op.py
+35
-19
python/paddle/tensor/manipulation.py
python/paddle/tensor/manipulation.py
+1
-0
未找到文件。
paddle/phi/kernels/gpu/randperm_kernel.cu
浏览文件 @
bc91012f
...
...
@@ -28,6 +28,7 @@ namespace cub = hipcub;
#include "gflags/gflags.h"
#include "paddle/phi/backends/gpu/gpu_launch_config.h"
#include "paddle/phi/common/amp_type_traits.h"
#include "paddle/phi/common/memory_utils.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/empty_kernel.h"
...
...
@@ -165,4 +166,6 @@ PD_REGISTER_KERNEL(randperm,
float
,
double
,
int
,
int64_t
)
{}
int64_t
,
phi
::
dtype
::
float16
,
phi
::
dtype
::
bfloat16
)
{}
python/paddle/fluid/tests/unittests/test_randperm_op.py
浏览文件 @
bc91012f
...
...
@@ -15,7 +15,11 @@
import
unittest
import
numpy
as
np
from
eager_op_test
import
OpTest
from
eager_op_test
import
(
OpTest
,
convert_float_to_uint16
,
convert_uint16_to_float
,
)
import
paddle
from
paddle.fluid
import
core
...
...
@@ -40,12 +44,21 @@ def error_msg(data_np):
def
convert_dtype
(
dtype_str
):
dtype_str_list
=
[
"int32"
,
"int64"
,
"float32"
,
"float64"
]
dtype_str_list
=
[
"int32"
,
"int64"
,
"float16"
,
"float32"
,
"float64"
,
"uint16"
,
]
dtype_num_list
=
[
core
.
VarDesc
.
VarType
.
INT32
,
core
.
VarDesc
.
VarType
.
INT64
,
core
.
VarDesc
.
VarType
.
FP16
,
core
.
VarDesc
.
VarType
.
FP32
,
core
.
VarDesc
.
VarType
.
FP64
,
core
.
VarDesc
.
VarType
.
BF16
,
]
assert
dtype_str
in
dtype_str_list
,
(
dtype_str
+
" should in "
+
str
(
dtype_str_list
)
...
...
@@ -62,9 +75,9 @@ class TestRandpermOp(OpTest):
self
.
n
=
200
self
.
dtype
=
"int64"
self
.
init_attrs
()
self
.
inputs
=
{}
self
.
outputs
=
{
"Out"
:
np
.
zeros
(
self
.
n
).
astype
(
self
.
dtype
)}
self
.
init_attrs
()
self
.
attrs
=
{
"n"
:
self
.
n
,
"dtype"
:
convert_dtype
(
self
.
dtype
),
...
...
@@ -103,6 +116,47 @@ class TestRandpermOpFloat64(TestRandpermOp):
self
.
dtype
=
"float64"
class
TestRandpermFP16Op
(
TestRandpermOp
):
def
init_attrs
(
self
):
self
.
dtype
=
"float16"
@
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
TestRandpermBF16Op
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"randperm"
self
.
python_api
=
paddle
.
randperm
self
.
n
=
200
self
.
init_attrs
()
self
.
inputs
=
{}
self
.
outputs
=
{
"Out"
:
np
.
zeros
(
self
.
n
).
astype
(
self
.
np_dtype
)}
self
.
attrs
=
{
"n"
:
self
.
n
,
"dtype"
:
convert_dtype
(
self
.
dtype
),
}
self
.
outputs
[
'Out'
]
=
convert_float_to_uint16
(
self
.
outputs
[
'Out'
])
self
.
place
=
core
.
CUDAPlace
(
0
)
def
init_attrs
(
self
):
self
.
dtype
=
"uint16"
self
.
np_dtype
=
np
.
float32
def
test_check_output
(
self
):
self
.
check_output_with_place_customized
(
self
.
verify_output
,
self
.
place
)
def
verify_output
(
self
,
outs
):
out_np
=
convert_uint16_to_float
(
np
.
array
(
outs
[
0
]))
self
.
assertTrue
(
check_randperm_out
(
self
.
n
,
out_np
),
msg
=
error_msg
(
out_np
)
)
class
TestRandpermOpError
(
unittest
.
TestCase
):
def
test_errors
(
self
):
with
program_guard
(
Program
(),
Program
()):
...
...
python/paddle/fluid/tests/unittests/test_split_op.py
浏览文件 @
bc91012f
...
...
@@ -65,7 +65,7 @@ class TestSplitOp(OpTest):
# test with attr(num)
class
TestSplit
Op_2
(
OpTest
):
class
TestSplit
WithNumOp
(
OpTest
):
def
setUp
(
self
):
self
.
python_api
=
paddle
.
split
self
.
public_python_api
=
paddle
.
split
...
...
@@ -74,18 +74,32 @@ class TestSplitOp_2(OpTest):
self
.
prim_op_type
=
"prim"
self
.
dtype
=
self
.
get_dtype
()
self
.
init_data
()
self
.
inputs
=
{
'X'
:
self
.
x
}
self
.
attrs
=
{
'axis'
:
self
.
axis
,
'sections'
:
self
.
sections
,
'num'
:
self
.
num
,
}
out
=
np
.
split
(
self
.
x
,
self
.
indices_or_sections
,
self
.
axis
)
self
.
outputs
=
{
'Out'
:
[(
'out%d'
%
i
,
out
[
i
])
for
i
in
range
(
len
(
out
))]}
if
self
.
dtype
==
np
.
uint16
:
self
.
inputs
=
{
'X'
:
convert_float_to_uint16
(
self
.
x
)}
out
=
np
.
split
(
self
.
x
,
self
.
indices_or_sections
,
self
.
axis
)
self
.
outputs
=
{
'Out'
:
[
(
'out%d'
%
i
,
convert_float_to_uint16
(
out
[
i
]))
for
i
in
range
(
len
(
out
))
]
}
else
:
self
.
inputs
=
{
'X'
:
self
.
x
}
out
=
np
.
split
(
self
.
x
,
self
.
indices_or_sections
,
self
.
axis
)
self
.
outputs
=
{
'Out'
:
[(
'out%d'
%
i
,
out
[
i
])
for
i
in
range
(
len
(
out
))]
}
def
init_data
(
self
):
self
.
x
=
np
.
random
.
random
((
4
,
5
,
6
)).
astype
(
self
.
dtype
)
if
self
.
dtype
==
np
.
uint16
:
self
.
x
=
np
.
random
.
random
((
4
,
5
,
6
)).
astype
(
np
.
float32
)
else
:
self
.
x
=
np
.
random
.
random
((
4
,
5
,
6
)).
astype
(
self
.
dtype
)
self
.
axis
=
2
self
.
sections
=
[]
self
.
num
=
3
...
...
@@ -240,28 +254,28 @@ def create_test_fp16(parent):
@
unittest
.
skipIf
(
not
core
.
is_compiled_with_cuda
(),
"core is not compiled with CUDA"
)
class
TestSplitF
p16
(
parent
):
class
TestSplitF
P16Op
(
parent
):
def
get_dtype
(
self
):
return
np
.
float16
def
test_check_grad
(
self
):
pass
cls_name
=
"{}_{}"
.
format
(
parent
.
__name__
,
"Fp16"
)
TestSplitFp16
.
__name__
=
cls_name
globals
()[
cls_name
]
=
TestSplitFp16
cls_name
=
"{}_{}"
.
format
(
parent
.
__name__
,
"FP16Op"
)
TestSplitFP16Op
.
__name__
=
cls_name
globals
()[
cls_name
]
=
TestSplitFP16Op
create_test_fp16
(
TestSplitOp
)
create_test_fp16
(
TestSplitWithNumOp
)
# ----------------Split Bf16----------------
def
create_test_bf16
(
parent
):
@
unittest
.
skipIf
(
not
core
.
is_compiled_with_cuda
(),
"core is not compiled with CUDA"
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
TestSplitB
f16
(
parent
):
class
TestSplitB
F16Op
(
parent
):
def
get_dtype
(
self
):
return
np
.
uint16
...
...
@@ -270,14 +284,16 @@ def create_test_bf16(parent):
self
.
check_output_with_place
(
place
)
def
test_check_grad
(
self
):
pass
place
=
core
.
CUDAPlace
(
0
)
self
.
check_grad_with_place
(
place
,
[
'X'
],
'out2'
)
cls_name
=
"{}_{}"
.
format
(
parent
.
__name__
,
"B
f16
"
)
TestSplitB
f16
.
__name__
=
cls_name
globals
()[
cls_name
]
=
TestSplitB
f16
cls_name
=
"{}_{}"
.
format
(
parent
.
__name__
,
"B
F16Op
"
)
TestSplitB
F16Op
.
__name__
=
cls_name
globals
()[
cls_name
]
=
TestSplitB
F16Op
create_test_bf16
(
TestSplitOp
)
create_test_bf16
(
TestSplitWithNumOp
)
class
TestSplitAPI
(
unittest
.
TestCase
):
...
...
python/paddle/tensor/manipulation.py
浏览文件 @
bc91012f
...
...
@@ -1976,6 +1976,7 @@ def split(x, num_or_sections, axis=0, name=None):
'int32'
,
'int64'
,
'uint8'
,
'uint16'
,
'int8'
,
],
'split'
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录