Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
17fec4e9
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看板
未验证
提交
17fec4e9
编写于
4月 11, 2023
作者:
C
cyberslack_lee
提交者:
GitHub
4月 11, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
【Hackathon4 No58】empty_like fp16&bf16 API test (#52668)
上级
3e66845f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
102 addition
and
9 deletion
+102
-9
python/paddle/fluid/tests/unittests/test_empty_like_op.py
python/paddle/fluid/tests/unittests/test_empty_like_op.py
+83
-7
python/paddle/tensor/attribute.py
python/paddle/tensor/attribute.py
+1
-0
python/paddle/tensor/creation.py
python/paddle/tensor/creation.py
+18
-2
未找到文件。
python/paddle/fluid/tests/unittests/test_empty_like_op.py
浏览文件 @
17fec4e9
...
...
@@ -15,6 +15,7 @@
import
unittest
import
numpy
as
np
from
eager_op_test
import
convert_uint16_to_float
import
paddle
from
paddle.fluid
import
core
...
...
@@ -38,7 +39,7 @@ class TestEmptyLikeAPICommon(unittest.TestCase):
f
'shape should be
{
self
.
dst_shape
}
, but get
{
shape
}
'
,
)
if
data_type
in
[
'float32'
,
'float64'
,
'int32'
,
'int64'
]:
if
data_type
in
[
'float
16'
,
'float
32'
,
'float64'
,
'int32'
,
'int64'
]:
max_value
=
np
.
nanmax
(
out
)
min_value
=
np
.
nanmin
(
out
)
always_non_full_zero
=
max_value
>=
min_value
...
...
@@ -47,6 +48,16 @@ class TestEmptyLikeAPICommon(unittest.TestCase):
always_full_zero
or
always_non_full_zero
,
'always_full_zero or always_non_full_zero.'
,
)
elif
data_type
in
[
'uint16'
]:
uout
=
convert_uint16_to_float
(
out
)
max_value
=
np
.
nanmax
(
uout
)
min_value
=
np
.
nanmin
(
uout
)
always_non_full_zero
=
max_value
>=
min_value
always_full_zero
=
max_value
==
0.0
and
min_value
==
0.0
self
.
assertTrue
(
always_full_zero
or
always_non_full_zero
,
'always_full_zero or always_non_full_zero.'
,
)
elif
data_type
in
[
'bool'
]:
total_num
=
out
.
size
true_num
=
np
.
sum
(
out
)
...
...
@@ -154,16 +165,13 @@ class TestEmptyLikeAPI_Static(TestEmptyLikeAPICommon):
def
test_static_graph
(
self
):
paddle
.
enable_static
()
dtype
=
'float32'
train_program
=
Program
()
startup_program
=
Program
()
with
program_guard
(
train_program
,
startup_program
):
x
=
np
.
random
.
random
(
self
.
x_shape
).
astype
(
dtype
)
x
=
np
.
random
.
random
(
self
.
x_shape
).
astype
(
self
.
dtype
)
data_x
=
paddle
.
static
.
data
(
'x'
,
shape
=
self
.
data_x_shape
,
dtype
=
dtype
'x'
,
shape
=
self
.
data_x_shape
,
dtype
=
self
.
dtype
)
out
=
paddle
.
empty_like
(
data_x
)
...
...
@@ -176,7 +184,7 @@ class TestEmptyLikeAPI_Static(TestEmptyLikeAPICommon):
exe
=
paddle
.
static
.
Executor
(
place
)
res
=
exe
.
run
(
train_program
,
feed
=
{
'x'
:
x
},
fetch_list
=
[
out
])
self
.
dst_dtype
=
dtype
self
.
dst_dtype
=
self
.
dtype
self
.
dst_shape
=
x
.
shape
self
.
__check_out__
(
res
[
0
])
...
...
@@ -185,12 +193,80 @@ class TestEmptyLikeAPI_Static(TestEmptyLikeAPICommon):
def
init_config
(
self
):
self
.
x_shape
=
(
200
,
3
)
self
.
data_x_shape
=
[
200
,
3
]
self
.
dtype
=
'float32'
class
TestEmptyLikeAPI_Static2
(
TestEmptyLikeAPI_Static
):
def
init_config
(
self
):
self
.
x_shape
=
(
3
,
200
,
3
)
self
.
data_x_shape
=
[
-
1
,
200
,
3
]
self
.
dtype
=
'float32'
class
TestEmptyLikeAPI_StaticForFP16Op
(
TestEmptyLikeAPICommon
):
def
setUp
(
self
):
self
.
init_config
()
def
init_config
(
self
):
self
.
x_shape
=
(
200
,
3
)
self
.
data_x_shape
=
[
200
,
3
]
self
.
dtype
=
'float16'
def
test_static_graph
(
self
):
paddle
.
enable_static
()
if
paddle
.
fluid
.
core
.
is_compiled_with_cuda
():
place
=
paddle
.
CUDAPlace
(
0
)
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
(),
paddle
.
static
.
Program
()
):
x
=
np
.
random
.
random
([
200
,
3
]).
astype
(
self
.
dtype
)
data_x
=
paddle
.
static
.
data
(
name
=
"x"
,
shape
=
[
200
,
3
],
dtype
=
self
.
dtype
)
out
=
paddle
.
empty_like
(
data_x
)
exe
=
paddle
.
static
.
Executor
(
place
)
res
=
exe
.
run
(
paddle
.
static
.
default_main_program
(),
feed
=
{
'x'
:
x
},
fetch_list
=
[
out
],
)
self
.
dst_dtype
=
self
.
dtype
self
.
dst_shape
=
x
.
shape
self
.
__check_out__
(
res
[
0
])
class
TestEmptyLikeAPI_StaticForBF16Op
(
TestEmptyLikeAPICommon
):
def
setUp
(
self
):
self
.
init_config
()
def
init_config
(
self
):
self
.
x_shape
=
(
200
,
3
)
self
.
data_x_shape
=
[
200
,
3
]
self
.
dtype
=
'uint16'
def
test_static_graph
(
self
):
paddle
.
enable_static
()
if
paddle
.
fluid
.
core
.
is_compiled_with_cuda
():
place
=
paddle
.
CUDAPlace
(
0
)
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
(),
paddle
.
static
.
Program
()
):
x
=
np
.
random
.
random
([
200
,
3
]).
astype
(
np
.
uint16
)
data_x
=
paddle
.
static
.
data
(
name
=
"x"
,
shape
=
[
200
,
3
],
dtype
=
np
.
uint16
)
out
=
paddle
.
empty_like
(
data_x
)
exe
=
paddle
.
static
.
Executor
(
place
)
res
=
exe
.
run
(
paddle
.
static
.
default_main_program
(),
feed
=
{
'x'
:
x
},
fetch_list
=
[
out
],
)
self
.
dst_dtype
=
self
.
dtype
self
.
dst_shape
=
x
.
shape
self
.
__check_out__
(
res
[
0
])
class
TestEmptyError
(
unittest
.
TestCase
):
...
...
python/paddle/tensor/attribute.py
浏览文件 @
17fec4e9
...
...
@@ -120,6 +120,7 @@ def shape(input):
'int64'
,
'complex64'
,
'complex128'
,
'uint16'
,
],
'shape'
,
)
...
...
python/paddle/tensor/creation.py
浏览文件 @
17fec4e9
...
...
@@ -1954,13 +1954,29 @@ def empty_like(x, dtype=None, name=None):
check_variable_and_dtype
(
x
,
'x'
,
[
'bool'
,
'float16'
,
'float32'
,
'float64'
,
'int32'
,
'int64'
],
[
'bool'
,
'float16'
,
'float32'
,
'float64'
,
'int32'
,
'int64'
,
'uint16'
,
],
'empty_like'
,
)
check_dtype
(
dtype
,
'dtype'
,
[
'bool'
,
'float16'
,
'float32'
,
'float64'
,
'int32'
,
'int64'
],
[
'bool'
,
'float16'
,
'float32'
,
'float64'
,
'int32'
,
'int64'
,
'uint16'
,
],
'empty_like'
,
)
out
=
helper
.
create_variable_for_type_inference
(
dtype
=
dtype
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录