Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
a7397e0c
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看板
未验证
提交
a7397e0c
编写于
3月 23, 2023
作者:
Y
yeliang2258
提交者:
GitHub
3月 23, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[AMP] Add bfloat16 and float16 tests for compare ops (#51978)
* add bf16 and fp16 tests * fix dtype check
上级
9c853d1d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
48 addition
and
4 deletion
+48
-4
paddle/phi/kernels/cpu/compare_kernel.cc
paddle/phi/kernels/cpu/compare_kernel.cc
+4
-2
python/paddle/fluid/tests/unittests/test_compare_op.py
python/paddle/fluid/tests/unittests/test_compare_op.py
+42
-0
python/paddle/tensor/logic.py
python/paddle/tensor/logic.py
+2
-2
未找到文件。
paddle/phi/kernels/cpu/compare_kernel.cc
浏览文件 @
a7397e0c
...
...
@@ -94,7 +94,8 @@ PD_REGISTER_KERNEL(equal_all,
int64_t, \
float, \
double, \
phi::dtype::float16) { \
phi::dtype::float16, \
phi::dtype::bfloat16) { \
kernel->OutputAt(0).SetDataType(phi::DataType::BOOL); \
} \
PD_REGISTER_KERNEL(name##_raw, \
...
...
@@ -107,7 +108,8 @@ PD_REGISTER_KERNEL(equal_all,
int64_t, \
float, \
double, \
phi::dtype::float16) { \
phi::dtype::float16, \
phi::dtype::bfloat16) { \
kernel->OutputAt(0).SetDataType(phi::DataType::BOOL); \
}
PD_REGISTER_COMPARE_KERNEL
(
less_than
,
LessThan
)
...
...
python/paddle/fluid/tests/unittests/test_compare_op.py
浏览文件 @
a7397e0c
...
...
@@ -136,6 +136,15 @@ def create_paddle_case(op_type, callback):
self
.
assertEqual
((
out
.
numpy
()
==
self
.
real_result
).
all
(),
True
)
paddle
.
enable_static
()
def
test_dynamic_api_float16
(
self
):
paddle
.
disable_static
()
x
=
paddle
.
to_tensor
(
self
.
input_x
,
dtype
=
"float16"
)
y
=
paddle
.
to_tensor
(
self
.
input_y
,
dtype
=
"float16"
)
op
=
eval
(
"paddle.%s"
%
(
self
.
op_type
))
out
=
op
(
x
,
y
)
self
.
assertEqual
((
out
.
numpy
()
==
self
.
real_result
).
all
(),
True
)
paddle
.
enable_static
()
def
test_dynamic_api_inf_1
(
self
):
if
self
.
op_type
==
"equal"
:
paddle
.
disable_static
()
...
...
@@ -434,6 +443,39 @@ create_paddle_case('equal', lambda _a, _b: _a == _b)
create_paddle_case
(
'not_equal'
,
lambda
_a
,
_b
:
_a
!=
_b
)
# add bf16 tests
def
create_bf16_case
(
op_type
,
callback
):
class
TestCompareOpBF16Op
(
op_test
.
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
op_type
self
.
dtype
=
np
.
uint16
self
.
python_api
=
eval
(
"paddle."
+
op_type
)
x
=
np
.
random
.
uniform
(
0
,
1
,
[
5
,
5
]).
astype
(
np
.
float32
)
y
=
np
.
random
.
uniform
(
0
,
1
,
[
5
,
5
]).
astype
(
np
.
float32
)
real_result
=
callback
(
x
,
y
)
self
.
inputs
=
{
'X'
:
op_test
.
convert_float_to_uint16
(
x
),
'Y'
:
op_test
.
convert_float_to_uint16
(
y
),
}
self
.
outputs
=
{
'Out'
:
real_result
}
def
test_check_output
(
self
):
self
.
check_output
()
cls_name
=
"BF16TestCase_{}"
.
format
(
op_type
)
TestCompareOpBF16Op
.
__name__
=
cls_name
globals
()[
cls_name
]
=
TestCompareOpBF16Op
create_bf16_case
(
'less_than'
,
lambda
_a
,
_b
:
_a
<
_b
)
create_bf16_case
(
'less_equal'
,
lambda
_a
,
_b
:
_a
<=
_b
)
create_bf16_case
(
'greater_than'
,
lambda
_a
,
_b
:
_a
>
_b
)
create_bf16_case
(
'greater_equal'
,
lambda
_a
,
_b
:
_a
>=
_b
)
create_bf16_case
(
'equal'
,
lambda
_a
,
_b
:
_a
==
_b
)
create_bf16_case
(
'not_equal'
,
lambda
_a
,
_b
:
_a
!=
_b
)
class
TestCompareOpError
(
unittest
.
TestCase
):
def
test_errors
(
self
):
paddle
.
enable_static
()
...
...
python/paddle/tensor/logic.py
浏览文件 @
a7397e0c
...
...
@@ -746,13 +746,13 @@ def not_equal(x, y, name=None):
check_variable_and_dtype
(
x
,
"x"
,
[
"bool"
,
"float32"
,
"float64"
,
"int32"
,
"int64"
],
[
"bool"
,
"float
16"
,
"float
32"
,
"float64"
,
"int32"
,
"int64"
],
"not_equal"
,
)
check_variable_and_dtype
(
y
,
"y"
,
[
"bool"
,
"float32"
,
"float64"
,
"int32"
,
"int64"
],
[
"bool"
,
"float
16"
,
"float
32"
,
"float64"
,
"int32"
,
"int64"
],
"not_equal"
,
)
helper
=
LayerHelper
(
"not_equal"
,
**
locals
())
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录