Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
2e92357b
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2305
Star
20932
Fork
5423
代码
文件
提交
分支
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看板
未验证
提交
2e92357b
编写于
3月 28, 2023
作者:
H
Haohongxiang
提交者:
GitHub
3月 28, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[API/OP] Support FP16/BF16 in paddle.nonzero API/OP (#51640)
上级
ad5536eb
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
107 addition
and
0 deletion
+107
-0
paddle/phi/kernels/cpu/nonzero_kernel.cc
paddle/phi/kernels/cpu/nonzero_kernel.cc
+1
-0
paddle/phi/kernels/gpu/nonzero_kernel.cu
paddle/phi/kernels/gpu/nonzero_kernel.cu
+2
-0
python/paddle/fluid/tests/unittests/test_nonzero_api.py
python/paddle/fluid/tests/unittests/test_nonzero_api.py
+88
-0
python/paddle/tensor/search.py
python/paddle/tensor/search.py
+16
-0
未找到文件。
paddle/phi/kernels/cpu/nonzero_kernel.cc
浏览文件 @
2e92357b
...
...
@@ -90,6 +90,7 @@ PD_REGISTER_KERNEL(nonzero,
int64_t
,
int
,
int16_t
,
phi
::
dtype
::
bfloat16
,
bool
,
float
,
double
)
{
...
...
paddle/phi/kernels/gpu/nonzero_kernel.cu
浏览文件 @
2e92357b
...
...
@@ -81,6 +81,8 @@ PD_REGISTER_KERNEL(nonzero,
int64_t
,
int
,
int16_t
,
phi
::
dtype
::
float16
,
phi
::
dtype
::
bfloat16
,
bool
,
float
,
double
)
{
...
...
python/paddle/fluid/tests/unittests/test_nonzero_api.py
浏览文件 @
2e92357b
...
...
@@ -15,10 +15,17 @@
import
unittest
import
numpy
as
np
from
eager_op_test
import
OpTest
import
paddle
from
paddle
import
fluid
from
paddle.fluid
import
Program
,
program_guard
from
paddle.fluid.tests.unittests.op_test
import
convert_float_to_uint16
def
call_nonzero
(
x
):
input
=
paddle
.
to_tensor
(
x
)
return
paddle
.
nonzero
(
x
=
input
)
class
TestNonZeroAPI
(
unittest
.
TestCase
):
...
...
@@ -88,5 +95,86 @@ class TestNonZeroAPI(unittest.TestCase):
expect_out
=
np
.
array
([[
0
,
0
],
[
1
,
1
]])
# Base case
class
TestNonzeroOp
(
OpTest
):
def
setUp
(
self
):
'''Test where_index op with random value'''
np
.
random
.
seed
(
2023
)
self
.
op_type
=
"where_index"
self
.
python_api
=
call_nonzero
self
.
init_shape
()
self
.
init_dtype
()
self
.
inputs
=
self
.
create_inputs
()
self
.
outputs
=
self
.
return_outputs
()
def
test_check_output
(
self
):
self
.
check_output
()
def
init_shape
(
self
):
self
.
shape
=
[
8
,
8
]
def
init_dtype
(
self
):
self
.
dtype
=
np
.
float64
def
create_inputs
(
self
):
return
{
'Condition'
:
np
.
random
.
randint
(
5
,
size
=
self
.
shape
).
astype
(
self
.
dtype
)
}
def
return_outputs
(
self
):
return
{
'Out'
:
np
.
transpose
(
np
.
nonzero
(
self
.
inputs
[
'Condition'
]))}
class
TestNonzeroFP32Op
(
TestNonzeroOp
):
def
init_shape
(
self
):
self
.
shape
=
[
2
,
10
,
2
]
def
init_dtype
(
self
):
self
.
dtype
=
np
.
float32
class
TestNonzeroFP16Op
(
TestNonzeroOp
):
def
init_shape
(
self
):
self
.
shape
=
[
3
,
4
,
7
]
def
init_dtype
(
self
):
self
.
dtype
=
np
.
float16
class
TestNonzeroBF16
(
OpTest
):
def
setUp
(
self
):
'''Test where_index op with bfloat16 dtype'''
np
.
random
.
seed
(
2023
)
self
.
op_type
=
"where_index"
self
.
python_api
=
call_nonzero
self
.
init_shape
()
self
.
init_dtype
()
self
.
inputs
=
self
.
create_inputs
()
self
.
outputs
=
self
.
return_outputs
()
def
test_check_output
(
self
):
self
.
check_output
()
def
init_shape
(
self
):
self
.
shape
=
[
12
,
9
]
def
init_dtype
(
self
):
self
.
dtype
=
np
.
uint16
def
create_inputs
(
self
):
return
{
'Condition'
:
convert_float_to_uint16
(
np
.
random
.
randint
(
5
,
size
=
self
.
shape
).
astype
(
np
.
float32
)
)
}
def
return_outputs
(
self
):
return
{
'Out'
:
np
.
transpose
(
np
.
nonzero
(
self
.
inputs
[
'Condition'
]))}
if
__name__
==
"__main__"
:
unittest
.
main
()
python/paddle/tensor/search.py
浏览文件 @
2e92357b
...
...
@@ -430,6 +430,22 @@ def nonzero(x, as_tuple=False):
if
in_dygraph_mode
():
outs
=
_C_ops
.
nonzero
(
x
)
else
:
check_variable_and_dtype
(
x
,
'x'
,
[
'int16'
,
'int32'
,
'int64'
,
'uint16'
,
'float16'
,
'float32'
,
'float64'
,
'bool'
,
],
'where_index'
,
)
helper
=
LayerHelper
(
"where_index"
,
**
locals
())
outs
=
helper
.
create_variable_for_type_inference
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录