Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
791963ab
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看板
未验证
提交
791963ab
编写于
6月 07, 2023
作者:
C
Charles-hit
提交者:
GitHub
6月 07, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support some prim ops bf16 dtype (#54399)
上级
2f0b4ad0
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
70 addition
and
14 deletion
+70
-14
paddle/phi/kernels/cpu/reduce_sum_kernel.cc
paddle/phi/kernels/cpu/reduce_sum_kernel.cc
+1
-0
paddle/phi/kernels/reduce_sum_kernel.cc
paddle/phi/kernels/reduce_sum_kernel.cc
+1
-0
test/legacy_test/test_concat_op.py
test/legacy_test/test_concat_op.py
+8
-4
test/legacy_test/test_elementwise_max_op.py
test/legacy_test/test_elementwise_max_op.py
+17
-4
test/legacy_test/test_elementwise_pow_op.py
test/legacy_test/test_elementwise_pow_op.py
+11
-0
test/legacy_test/test_gather_nd_op.py
test/legacy_test/test_gather_nd_op.py
+28
-5
test/legacy_test/test_reduce_op.py
test/legacy_test/test_reduce_op.py
+4
-1
未找到文件。
paddle/phi/kernels/cpu/reduce_sum_kernel.cc
浏览文件 @
791963ab
...
...
@@ -49,6 +49,7 @@ PD_REGISTER_KERNEL(sum_raw,
float
,
double
,
phi
::
dtype
::
float16
,
phi
::
dtype
::
bfloat16
,
int16_t
,
int
,
int64_t
,
...
...
paddle/phi/kernels/reduce_sum_kernel.cc
浏览文件 @
791963ab
...
...
@@ -44,6 +44,7 @@ PD_REGISTER_KERNEL(sum,
float
,
double
,
phi
::
dtype
::
float16
,
phi
::
dtype
::
bfloat16
,
int16_t
,
int
,
int64_t
,
...
...
test/legacy_test/test_concat_op.py
浏览文件 @
791963ab
...
...
@@ -136,8 +136,8 @@ class TestConcatOp6(TestConcatOp):
self
.
dtype
=
self
.
get_dtype
()
self
.
python_api
=
paddle
.
concat
self
.
public_python_api
=
paddle
.
concat
self
.
enable_cinn
=
False
self
.
init_test_data
()
self
.
if_enable_cinn
()
self
.
lod
=
[[
20
,
80
]]
self
.
out_lod
=
[[
20
,
80
,
20
,
80
,
20
,
80
]]
self
.
inputs
=
{
...
...
@@ -156,6 +156,9 @@ class TestConcatOp6(TestConcatOp):
out
=
np
.
concatenate
((
self
.
x0
,
self
.
x1
,
self
.
x2
),
axis
=
self
.
actual_axis
)
self
.
outputs
=
{
'Out'
:
(
out
,
self
.
out_lod
)}
def
if_enable_cinn
(
self
):
pass
def
test_check_output
(
self
):
self
.
check_output
()
...
...
@@ -177,7 +180,7 @@ class TestConcatOp7(TestConcatOp):
self
.
python_api
=
paddle
.
concat
self
.
public_python_api
=
paddle
.
concat
self
.
prim_op_type
=
"prim"
self
.
enable_cinn
=
True
self
.
if_enable_cinn
()
self
.
dtype
=
self
.
get_dtype
()
self
.
init_test_data
()
self
.
inputs
=
{
'X'
:
[(
'x0'
,
self
.
x0
),
(
'x1'
,
self
.
x1
),
(
'x2'
,
self
.
x2
)]}
...
...
@@ -194,6 +197,9 @@ class TestConcatOp7(TestConcatOp):
)
}
def
if_enable_cinn
(
self
):
pass
def
get_dtype
(
self
):
return
"float64"
...
...
@@ -226,7 +232,6 @@ def create_test_AxisTensor(parent):
self
.
op_type
=
"concat"
self
.
python_api
=
paddle
.
concat
self
.
public_python_api
=
paddle
.
concat
self
.
enable_cinn
=
False
self
.
dtype
=
self
.
get_dtype
()
self
.
init_test_data
()
self
.
inputs
=
{
...
...
@@ -286,7 +291,6 @@ def create_test_fp16(parent):
self
.
op_type
=
"concat"
self
.
python_api
=
paddle
.
concat
self
.
public_python_api
=
paddle
.
concat
self
.
enable_cinn
=
False
self
.
dtype
=
self
.
get_dtype
()
self
.
init_test_data
()
self
.
inputs
=
{
...
...
test/legacy_test/test_elementwise_max_op.py
浏览文件 @
791963ab
...
...
@@ -198,7 +198,6 @@ class TestElementwiseBF16Op(OpTest):
self
.
python_api
=
paddle
.
maximum
self
.
public_python_api
=
paddle
.
maximum
self
.
prim_op_type
=
"prim"
self
.
enable_cinn
=
False
self
.
dtype
=
np
.
uint16
self
.
inputs
=
{
'X'
:
convert_float_to_uint16
(
self
.
x
),
...
...
@@ -207,6 +206,7 @@ class TestElementwiseBF16Op(OpTest):
self
.
outputs
=
{
'Out'
:
convert_float_to_uint16
(
np
.
maximum
(
self
.
x
,
self
.
y
))
}
self
.
if_enable_cinn
()
def
test_check_output
(
self
):
if
hasattr
(
self
,
'attrs'
):
...
...
@@ -214,6 +214,9 @@ class TestElementwiseBF16Op(OpTest):
else
:
self
.
check_output
(
check_dygraph
=
True
)
def
if_enable_cinn
(
self
):
pass
def
test_check_grad_normal
(
self
):
if
hasattr
(
self
,
'attrs'
):
# check_prim=False, bfloat16 is not supported in `less_equal`
...
...
@@ -221,16 +224,26 @@ class TestElementwiseBF16Op(OpTest):
[
'X'
,
'Y'
],
'Out'
,
numeric_grad_delta
=
0.05
,
check_dygraph
=
False
)
else
:
self
.
check_grad
([
'X'
,
'Y'
],
'Out'
,
numeric_grad_delta
=
0.05
)
self
.
check_grad
(
[
'X'
,
'Y'
],
'Out'
,
numeric_grad_delta
=
0.05
,
check_prim
=
True
)
def
test_check_grad_ingore_x
(
self
):
self
.
check_grad
(
[
'Y'
],
'Out'
,
numeric_grad_delta
=
0.05
,
no_grad_set
=
set
(
"X"
)
[
'Y'
],
'Out'
,
numeric_grad_delta
=
0.05
,
no_grad_set
=
set
(
"X"
),
check_prim
=
True
,
)
def
test_check_grad_ingore_y
(
self
):
self
.
check_grad
(
[
'X'
],
'Out'
,
numeric_grad_delta
=
0.05
,
no_grad_set
=
set
(
'Y'
)
[
'X'
],
'Out'
,
numeric_grad_delta
=
0.05
,
no_grad_set
=
set
(
'Y'
),
check_prim
=
True
,
)
...
...
test/legacy_test/test_elementwise_pow_op.py
浏览文件 @
791963ab
...
...
@@ -19,6 +19,7 @@ from eager_op_test import OpTest, convert_float_to_uint16, skip_check_grad_ci
import
paddle
from
paddle
import
fluid
from
paddle.fluid
import
core
def
pow_grad
(
x
,
y
,
dout
):
...
...
@@ -270,8 +271,10 @@ class TestElementwisePowOpFP16(OpTest):
class
TestElementwisePowBF16Op
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"elementwise_pow"
self
.
prim_op_type
=
"prim"
self
.
dtype
=
np
.
uint16
self
.
python_api
=
paddle
.
pow
self
.
public_python_api
=
paddle
.
pow
x
=
np
.
random
.
uniform
(
0
,
1
,
[
20
,
5
]).
astype
(
np
.
float32
)
y
=
np
.
random
.
uniform
(
0
,
1
,
[
20
,
5
]).
astype
(
np
.
float32
)
...
...
@@ -290,6 +293,14 @@ class TestElementwisePowBF16Op(OpTest):
def
test_check_grad
(
self
):
self
.
check_grad
([
'X'
,
'Y'
],
'Out'
)
if
core
.
is_compiled_with_cuda
():
self
.
check_grad_with_place
(
core
.
CUDAPlace
(
0
),
[
'X'
,
'Y'
],
'Out'
,
check_prim
=
True
,
only_check_prim
=
True
,
)
if
__name__
==
'__main__'
:
...
...
test/legacy_test/test_gather_nd_op.py
浏览文件 @
791963ab
...
...
@@ -15,7 +15,11 @@
import
unittest
import
numpy
as
np
from
eager_op_test
import
OpTest
,
convert_float_to_uint16
from
eager_op_test
import
(
OpTest
,
convert_float_to_uint16
,
convert_uint16_to_float
,
)
import
paddle
from
paddle
import
fluid
...
...
@@ -31,6 +35,7 @@ class TestGatherNdOpWithEmptyIndex(OpTest):
self
.
python_api
=
paddle
.
gather_nd
self
.
public_python_api
=
paddle
.
gather_nd
self
.
config_dtype
()
self
.
if_enable_cinn
()
if
self
.
dtype
==
np
.
float64
:
target_dtype
=
"float64"
elif
self
.
dtype
==
np
.
float16
:
...
...
@@ -45,6 +50,9 @@ class TestGatherNdOpWithEmptyIndex(OpTest):
self
.
inputs
=
{
'X'
:
xnp
,
'Index'
:
np
.
array
([[],
[]]).
astype
(
"int32"
)}
self
.
outputs
=
{
'Out'
:
output
}
def
if_enable_cinn
(
self
):
pass
def
config_dtype
(
self
):
self
.
dtype
=
np
.
float64
...
...
@@ -85,6 +93,7 @@ class TestGatherNdOpWithIndex1(OpTest):
self
.
python_api
=
paddle
.
gather_nd
self
.
public_python_api
=
paddle
.
gather_nd
self
.
config_dtype
()
self
.
if_enable_cinn
()
if
self
.
dtype
==
np
.
float64
:
target_dtype
=
"float64"
elif
self
.
dtype
==
np
.
float16
:
...
...
@@ -100,6 +109,9 @@ class TestGatherNdOpWithIndex1(OpTest):
self
.
inputs
=
{
'X'
:
xnp
,
'Index'
:
index
}
self
.
outputs
=
{
'Out'
:
output
}
def
if_enable_cinn
(
self
):
pass
def
config_dtype
(
self
):
self
.
dtype
=
np
.
float64
...
...
@@ -189,7 +201,9 @@ class TestGatherNdOpWithLowIndexBF16(TestGatherNdOpWithLowIndex):
def
test_check_grad
(
self
):
place
=
core
.
CUDAPlace
(
0
)
self
.
check_grad_with_place
(
place
,
[
'X'
],
'Out'
,
check_prim
=
True
)
self
.
check_grad_with_place
(
place
,
[
'X'
],
'Out'
,
check_prim
=
True
,
numeric_grad_delta
=
0.5
)
class
TestGatherNdOpIndex1
(
OpTest
):
...
...
@@ -208,6 +222,8 @@ class TestGatherNdOpIndex1(OpTest):
else
:
target_dtype
=
"float32"
xnp
=
np
.
random
.
uniform
(
0
,
100
,
(
10
,
10
)).
astype
(
target_dtype
)
if
self
.
dtype
==
np
.
uint16
:
xnp
=
convert_uint16_to_float
(
convert_float_to_uint16
(
xnp
))
index
=
np
.
array
([
1
,
2
]).
astype
(
"int32"
)
output
=
xnp
[
tuple
(
index
.
T
)]
if
self
.
dtype
==
np
.
uint16
:
...
...
@@ -215,6 +231,9 @@ class TestGatherNdOpIndex1(OpTest):
output
=
convert_float_to_uint16
(
output
)
self
.
inputs
=
{
'X'
:
xnp
,
'Index'
:
index
}
self
.
outputs
=
{
'Out'
:
output
}
self
.
if_enable_cinn
()
def
if_enable_cinn
(
self
):
# the outputs are 0D-tensor, CINN not support
self
.
enable_cinn
=
False
...
...
@@ -225,7 +244,7 @@ class TestGatherNdOpIndex1(OpTest):
self
.
check_output
()
def
test_check_grad
(
self
):
self
.
check_grad
([
'X'
],
'Out'
,
check_prim
=
True
)
self
.
check_grad
([
'X'
],
'Out'
,
check_prim
=
True
,
numeric_grad_delta
=
0.05
)
class
TestGatherNdOpIndex1FP16
(
TestGatherNdOpIndex1
):
...
...
@@ -248,7 +267,9 @@ class TestGatherNdOpIndex1BF16(TestGatherNdOpIndex1):
def
test_check_grad
(
self
):
place
=
core
.
CUDAPlace
(
0
)
self
.
check_grad_with_place
(
place
,
[
'X'
],
'Out'
,
check_prim
=
True
)
self
.
check_grad_with_place
(
place
,
[
'X'
],
'Out'
,
check_prim
=
True
,
numeric_grad_delta
=
0.5
)
class
TestGatherNdOpWithSameIndexAsX
(
OpTest
):
...
...
@@ -304,7 +325,9 @@ class TestGatherNdOpWithSameIndexAsXBF16(TestGatherNdOpWithSameIndexAsX):
def
test_check_grad
(
self
):
place
=
core
.
CUDAPlace
(
0
)
self
.
check_grad_with_place
(
place
,
[
'X'
],
'Out'
,
check_prim
=
True
)
self
.
check_grad_with_place
(
place
,
[
'X'
],
'Out'
,
check_prim
=
True
,
numeric_grad_delta
=
0.5
)
class
TestGatherNdOpWithHighRankSame
(
OpTest
):
...
...
test/legacy_test/test_reduce_op.py
浏览文件 @
791963ab
...
...
@@ -277,13 +277,16 @@ class TestMaxOp_ZeroDim(OpTest):
self
.
prim_op_type
=
"prim"
self
.
python_api
=
paddle
.
max
self
.
public_python_api
=
paddle
.
max
self
.
enable_cinn
=
False
self
.
if_enable_cinn
()
self
.
inputs
=
{
'X'
:
np
.
random
.
random
([]).
astype
(
"float64"
)}
self
.
attrs
=
{
'dim'
:
[]}
self
.
outputs
=
{
'Out'
:
self
.
inputs
[
'X'
].
max
(
axis
=
tuple
(
self
.
attrs
[
'dim'
]))
}
def
if_enable_cinn
(
self
):
self
.
enable_cinn
=
False
def
test_check_output
(
self
):
self
.
check_output
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录