Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
7f93e2b0
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
7f93e2b0
编写于
3月 18, 2022
作者:
Z
zhangyikun02
提交者:
GitHub
3月 18, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update unittests for tile op and silce op on XPU, test=kunlun (#40227)
上级
86919910
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
299 addition
and
357 deletion
+299
-357
python/paddle/fluid/tests/unittests/xpu/test_slice_op_xpu.py
python/paddle/fluid/tests/unittests/xpu/test_slice_op_xpu.py
+159
-154
python/paddle/fluid/tests/unittests/xpu/test_tile_op_xpu.py
python/paddle/fluid/tests/unittests/xpu/test_tile_op_xpu.py
+140
-203
未找到文件。
python/paddle/fluid/tests/unittests/xpu/test_slice_op_xpu.py
浏览文件 @
7f93e2b0
...
@@ -18,16 +18,23 @@ import sys
...
@@ -18,16 +18,23 @@ import sys
import
unittest
import
unittest
sys
.
path
.
append
(
".."
)
sys
.
path
.
append
(
".."
)
from
op_test
import
OpTest
from
op_test
import
OpTest
from
op_test_xpu
import
XPUOpTest
from
xpu.get_test_cover_info
import
create_test_class
,
get_xpu_op_support_types
,
XPUOpTestWrapper
paddle
.
enable_static
()
paddle
.
enable_static
()
# Situation 1: starts(list, no tensor), ends(list, no tensor)
# Situation 1: starts(list, no tensor), ends(list, no tensor)
# 1.1 without attr(decrease)
# 1.1 without attr(decrease)
@
unittest
.
skipIf
(
not
paddle
.
is_compiled_with_xpu
(),
class
XPUTestSliceOp
(
XPUOpTestWrapper
):
"core is not compiled with XPU"
)
def
__init__
(
self
):
class
TestSliceOp
(
OpTest
):
self
.
op_name
=
'slice'
self
.
use_dynamic_create_class
=
False
class
TestSliceOp
(
XPUOpTest
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
dtype
=
self
.
in_type
self
.
place
=
paddle
.
XPUPlace
(
0
)
self
.
op_type
=
"slice"
self
.
op_type
=
"slice"
self
.
config
()
self
.
config
()
self
.
inputs
=
{
'Input'
:
self
.
input
}
self
.
inputs
=
{
'Input'
:
self
.
input
}
...
@@ -41,39 +48,36 @@ class TestSliceOp(OpTest):
...
@@ -41,39 +48,36 @@ class TestSliceOp(OpTest):
}
}
def
config
(
self
):
def
config
(
self
):
self
.
input
=
np
.
random
.
random
([
3
,
4
,
5
,
6
]).
astype
(
"float32"
)
self
.
input
=
np
.
random
.
random
([
3
,
4
,
5
,
6
]).
astype
(
self
.
dtype
)
self
.
starts
=
[
1
,
0
,
2
]
self
.
starts
=
[
1
,
0
,
2
]
self
.
ends
=
[
3
,
3
,
4
]
self
.
ends
=
[
3
,
3
,
4
]
self
.
axes
=
[
0
,
1
,
2
]
self
.
axes
=
[
0
,
1
,
2
]
self
.
infer_flags
=
[
1
,
1
,
1
]
self
.
infer_flags
=
[
1
,
1
,
1
]
self
.
out
=
self
.
input
[
1
:
3
,
0
:
3
,
2
:
4
,
:]
self
.
out
=
self
.
input
[
1
:
3
,
0
:
3
,
2
:
4
,
:]
def
test_check_output
(
self
):
place
=
paddle
.
XPUPlace
(
0
)
self
.
check_output_with_place
(
place
)
def
test_check_grad_normal
(
self
):
def
test_check_grad_normal
(
self
):
place
=
paddle
.
XPUPlace
(
0
)
if
self
.
dtype
==
np
.
float16
:
self
.
check_grad_with_place
(
place
,
[
'Input'
],
'Out'
)
self
.
check_grad_with_place
(
self
.
place
,
[
'Input'
],
'Out'
)
else
:
user_defined_grad_outputs
=
np
.
random
.
random
(
@
unittest
.
skipIf
(
not
paddle
.
is_compiled_with_xpu
(),
self
.
out
.
shape
).
astype
(
self
.
dtype
)
"core is not compiled with XPU"
)
self
.
check_grad_with_place
(
class
TestCase1
(
TestSliceOp
):
self
.
place
,
[
'Input'
],
'Out'
,
user_defined_grad_outputs
=
user_defined_grad_outputs
)
class
TestCase1
(
TestSliceOp
):
def
config
(
self
):
def
config
(
self
):
self
.
input
=
np
.
random
.
random
([
3
,
4
,
5
,
6
]).
astype
(
"float32"
)
self
.
input
=
np
.
random
.
random
([
3
,
4
,
5
,
6
]).
astype
(
self
.
dtype
)
self
.
starts
=
[
-
3
,
0
,
2
]
self
.
starts
=
[
-
3
,
0
,
2
]
self
.
ends
=
[
3
,
100
,
-
1
]
self
.
ends
=
[
3
,
100
,
-
1
]
self
.
axes
=
[
0
,
1
,
2
]
self
.
axes
=
[
0
,
1
,
2
]
self
.
infer_flags
=
[
1
,
1
,
1
]
self
.
infer_flags
=
[
1
,
1
,
1
]
self
.
out
=
self
.
input
[
-
3
:
3
,
0
:
100
,
2
:
-
1
,
:]
self
.
out
=
self
.
input
[
-
3
:
3
,
0
:
100
,
2
:
-
1
,
:]
class
TestCase2
(
TestSliceOp
):
@
unittest
.
skipIf
(
not
paddle
.
is_compiled_with_xpu
(),
"core is not compiled with XPU"
)
class
TestCase2
(
TestSliceOp
):
def
config
(
self
):
def
config
(
self
):
self
.
input
=
np
.
random
.
random
([
3
,
4
,
5
,
6
]).
astype
(
"float32"
)
self
.
input
=
np
.
random
.
random
([
3
,
4
,
5
,
6
]).
astype
(
self
.
dtype
)
self
.
starts
=
[
-
3
,
0
,
2
]
self
.
starts
=
[
-
3
,
0
,
2
]
self
.
ends
=
[
3
,
100
,
-
1
]
self
.
ends
=
[
3
,
100
,
-
1
]
self
.
axes
=
[
0
,
1
,
3
]
self
.
axes
=
[
0
,
1
,
3
]
...
@@ -82,10 +86,15 @@ class TestCase2(TestSliceOp):
...
@@ -82,10 +86,15 @@ class TestCase2(TestSliceOp):
# 1.2 with attr(decrease)
# 1.2 with attr(decrease)
@
unittest
.
skipIf
(
not
paddle
.
is_compiled_with_xpu
(),
class
XPUTestSliceOp_decs_dim
(
XPUOpTestWrapper
):
"core is not compiled with XPU"
)
def
__init__
(
self
):
class
TestSliceOp_decs_dim
(
OpTest
):
self
.
op_name
=
'slice'
self
.
use_dynamic_create_class
=
False
class
TestSliceOp_decs_dim
(
XPUOpTest
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
dtype
=
self
.
in_type
self
.
place
=
paddle
.
XPUPlace
(
0
)
self
.
op_type
=
"slice"
self
.
op_type
=
"slice"
self
.
config
()
self
.
config
()
self
.
inputs
=
{
'Input'
:
self
.
input
}
self
.
inputs
=
{
'Input'
:
self
.
input
}
...
@@ -100,7 +109,7 @@ class TestSliceOp_decs_dim(OpTest):
...
@@ -100,7 +109,7 @@ class TestSliceOp_decs_dim(OpTest):
}
}
def
config
(
self
):
def
config
(
self
):
self
.
input
=
np
.
random
.
random
([
3
,
4
,
5
,
6
]).
astype
(
"float32"
)
self
.
input
=
np
.
random
.
random
([
3
,
4
,
5
,
6
]).
astype
(
self
.
dtype
)
self
.
starts
=
[
1
,
0
,
2
]
self
.
starts
=
[
1
,
0
,
2
]
self
.
ends
=
[
2
,
3
,
4
]
self
.
ends
=
[
2
,
3
,
4
]
self
.
axes
=
[
0
,
1
,
2
]
self
.
axes
=
[
0
,
1
,
2
]
...
@@ -109,19 +118,22 @@ class TestSliceOp_decs_dim(OpTest):
...
@@ -109,19 +118,22 @@ class TestSliceOp_decs_dim(OpTest):
self
.
out
=
self
.
input
[
1
,
0
:
3
,
2
:
4
,
:]
self
.
out
=
self
.
input
[
1
,
0
:
3
,
2
:
4
,
:]
def
test_check_output
(
self
):
def
test_check_output
(
self
):
place
=
paddle
.
XPUPlace
(
0
)
self
.
check_output_with_place
(
self
.
place
)
self
.
check_output_with_place
(
place
)
def
test_check_grad_normal
(
self
):
def
test_check_grad_normal
(
self
):
place
=
paddle
.
XPUPlace
(
0
)
if
self
.
dtype
==
np
.
float16
:
self
.
check_grad_with_place
(
place
,
[
'Input'
],
'Out'
)
self
.
check_grad_with_place
(
self
.
place
,
[
'Input'
],
'Out'
)
else
:
user_defined_grad_outputs
=
np
.
random
.
random
(
@
unittest
.
skipIf
(
not
paddle
.
is_compiled_with_xpu
(),
self
.
out
.
shape
).
astype
(
self
.
dtype
)
"core is not compiled with XPU"
)
self
.
check_grad_with_place
(
class
TestSliceOp_decs_dim_2
(
TestSliceOp_decs_dim
):
self
.
place
,
[
'Input'
],
'Out'
,
user_defined_grad_outputs
=
user_defined_grad_outputs
)
class
TestSliceOp_decs_dim_2
(
TestSliceOp_decs_dim
):
def
config
(
self
):
def
config
(
self
):
self
.
input
=
np
.
random
.
random
([
3
,
4
,
5
,
6
]).
astype
(
"float32"
)
self
.
input
=
np
.
random
.
random
([
3
,
4
,
5
,
6
]).
astype
(
self
.
dtype
)
self
.
starts
=
[
1
,
0
,
2
]
self
.
starts
=
[
1
,
0
,
2
]
self
.
ends
=
[
2
,
1
,
4
]
self
.
ends
=
[
2
,
1
,
4
]
self
.
axes
=
[
0
,
1
,
2
]
self
.
axes
=
[
0
,
1
,
2
]
...
@@ -129,12 +141,9 @@ class TestSliceOp_decs_dim_2(TestSliceOp_decs_dim):
...
@@ -129,12 +141,9 @@ class TestSliceOp_decs_dim_2(TestSliceOp_decs_dim):
self
.
infer_flags
=
[
1
,
1
,
1
]
self
.
infer_flags
=
[
1
,
1
,
1
]
self
.
out
=
self
.
input
[
1
,
0
,
2
:
4
,
:]
self
.
out
=
self
.
input
[
1
,
0
,
2
:
4
,
:]
class
TestSliceOp_decs_dim_3
(
TestSliceOp_decs_dim
):
@
unittest
.
skipIf
(
not
paddle
.
is_compiled_with_xpu
(),
"core is not compiled with XPU"
)
class
TestSliceOp_decs_dim_3
(
TestSliceOp_decs_dim
):
def
config
(
self
):
def
config
(
self
):
self
.
input
=
np
.
random
.
random
([
3
,
4
,
5
,
6
]).
astype
(
"float32"
)
self
.
input
=
np
.
random
.
random
([
3
,
4
,
5
,
6
]).
astype
(
self
.
dtype
)
self
.
starts
=
[
-
1
,
0
,
2
]
self
.
starts
=
[
-
1
,
0
,
2
]
self
.
ends
=
[
1000000
,
1
,
4
]
self
.
ends
=
[
1000000
,
1
,
4
]
self
.
axes
=
[
0
,
1
,
2
]
self
.
axes
=
[
0
,
1
,
2
]
...
@@ -142,12 +151,9 @@ class TestSliceOp_decs_dim_3(TestSliceOp_decs_dim):
...
@@ -142,12 +151,9 @@ class TestSliceOp_decs_dim_3(TestSliceOp_decs_dim):
self
.
infer_flags
=
[
1
,
1
,
1
]
self
.
infer_flags
=
[
1
,
1
,
1
]
self
.
out
=
self
.
input
[
-
1
,
0
,
2
:
4
,
:]
self
.
out
=
self
.
input
[
-
1
,
0
,
2
:
4
,
:]
class
TestSliceOp_decs_dim_4
(
TestSliceOp_decs_dim
):
@
unittest
.
skipIf
(
not
paddle
.
is_compiled_with_xpu
(),
"core is not compiled with XPU"
)
class
TestSliceOp_decs_dim_4
(
TestSliceOp_decs_dim
):
def
config
(
self
):
def
config
(
self
):
self
.
input
=
np
.
random
.
random
([
3
,
4
,
5
,
7
]).
astype
(
"float32"
)
self
.
input
=
np
.
random
.
random
([
3
,
4
,
5
,
7
]).
astype
(
self
.
dtype
)
self
.
starts
=
[
0
,
1
,
2
,
3
]
self
.
starts
=
[
0
,
1
,
2
,
3
]
self
.
ends
=
[
1
,
2
,
3
,
4
]
self
.
ends
=
[
1
,
2
,
3
,
4
]
self
.
axes
=
[
0
,
1
,
2
,
3
]
self
.
axes
=
[
0
,
1
,
2
,
3
]
...
@@ -155,12 +161,9 @@ class TestSliceOp_decs_dim_4(TestSliceOp_decs_dim):
...
@@ -155,12 +161,9 @@ class TestSliceOp_decs_dim_4(TestSliceOp_decs_dim):
self
.
infer_flags
=
[
1
,
1
,
1
]
self
.
infer_flags
=
[
1
,
1
,
1
]
self
.
out
=
self
.
input
[
0
,
1
,
2
,
3
:
4
]
self
.
out
=
self
.
input
[
0
,
1
,
2
,
3
:
4
]
class
TestSliceOp_decs_dim_5
(
TestSliceOp_decs_dim
):
@
unittest
.
skipIf
(
not
paddle
.
is_compiled_with_xpu
(),
"core is not compiled with XPU"
)
class
TestSliceOp_decs_dim_5
(
TestSliceOp_decs_dim
):
def
config
(
self
):
def
config
(
self
):
self
.
input
=
np
.
random
.
random
([
3
,
4
,
5
,
6
]).
astype
(
"float32"
)
self
.
input
=
np
.
random
.
random
([
3
,
4
,
5
,
6
]).
astype
(
self
.
dtype
)
self
.
starts
=
[
-
1
]
self
.
starts
=
[
-
1
]
self
.
ends
=
[
1000000
]
self
.
ends
=
[
1000000
]
self
.
axes
=
[
3
]
self
.
axes
=
[
3
]
...
@@ -168,12 +171,9 @@ class TestSliceOp_decs_dim_5(TestSliceOp_decs_dim):
...
@@ -168,12 +171,9 @@ class TestSliceOp_decs_dim_5(TestSliceOp_decs_dim):
self
.
infer_flags
=
[
1
,
1
,
1
]
self
.
infer_flags
=
[
1
,
1
,
1
]
self
.
out
=
self
.
input
[:,
:,
:,
-
1
]
self
.
out
=
self
.
input
[:,
:,
:,
-
1
]
class
TestSliceOp_decs_dim_6
(
TestSliceOp_decs_dim
):
@
unittest
.
skipIf
(
not
paddle
.
is_compiled_with_xpu
(),
"core is not compiled with XPU"
)
class
TestSliceOp_decs_dim_6
(
TestSliceOp_decs_dim
):
def
config
(
self
):
def
config
(
self
):
self
.
input
=
np
.
random
.
random
([
3
,
4
,
5
,
6
]).
astype
(
"float32"
)
self
.
input
=
np
.
random
.
random
([
3
,
4
,
5
,
6
]).
astype
(
self
.
dtype
)
self
.
starts
=
[
0
,
1
,
2
,
3
]
self
.
starts
=
[
0
,
1
,
2
,
3
]
self
.
ends
=
[
1
,
2
,
3
,
4
]
self
.
ends
=
[
1
,
2
,
3
,
4
]
self
.
axes
=
[
0
,
1
,
2
,
3
]
self
.
axes
=
[
0
,
1
,
2
,
3
]
...
@@ -182,5 +182,10 @@ class TestSliceOp_decs_dim_6(TestSliceOp_decs_dim):
...
@@ -182,5 +182,10 @@ class TestSliceOp_decs_dim_6(TestSliceOp_decs_dim):
self
.
out
=
self
.
input
[
0
,
1
,
2
,
3
:
4
]
self
.
out
=
self
.
input
[
0
,
1
,
2
,
3
:
4
]
support_types
=
get_xpu_op_support_types
(
'slice'
)
for
stype
in
support_types
:
create_test_class
(
globals
(),
XPUTestSliceOp
,
stype
)
create_test_class
(
globals
(),
XPUTestSliceOp_decs_dim
,
stype
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
python/paddle/fluid/tests/unittests/xpu/test_tile_op_xpu.py
浏览文件 @
7f93e2b0
...
@@ -24,27 +24,32 @@ import paddle
...
@@ -24,27 +24,32 @@ import paddle
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
from
paddle.fluid
import
compiler
,
Program
,
program_guard
from
paddle.fluid
import
compiler
,
Program
,
program_guard
from
paddle.fluid
import
core
from
paddle.fluid
import
core
from
xpu.get_test_cover_info
import
create_test_class
,
get_xpu_op_support_types
,
XPUOpTestWrapper
paddle
.
enable_static
()
paddle
.
enable_static
()
np
.
random
.
seed
(
10
)
np
.
random
.
seed
(
10
)
#Situation 1: repeat_times is a list (without tensor)
#Situation 1: repeat_times is a list (without tensor)
class
TestTileOpRank1
(
XPUOpTest
):
class
XPUTestTileOpRank1
(
XPUOpTestWrapper
):
def
__init__
(
self
):
self
.
op_name
=
'tile'
self
.
use_dynamic_create_class
=
False
class
TestTileOpRank1
(
XPUOpTest
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
set_xpu
()
self
.
dtype
=
self
.
in_type
self
.
__class__
.
no_need_check_grad
=
True
self
.
place
=
paddle
.
XPUPlace
(
0
)
self
.
place
=
paddle
.
XPUPlace
(
0
)
self
.
op_type
=
"tile"
self
.
op_type
=
"tile"
self
.
init_data
()
self
.
init_data
()
self
.
inputs
=
{
self
.
inputs
=
{
'X'
:
np
.
random
.
random
(
self
.
ori_shape
).
astype
(
"float32"
)}
'X'
:
np
.
random
.
random
(
self
.
ori_shape
).
astype
(
self
.
dtype
)
}
self
.
attrs
=
{
'repeat_times'
:
self
.
repeat_times
}
self
.
attrs
=
{
'repeat_times'
:
self
.
repeat_times
}
output
=
np
.
tile
(
self
.
inputs
[
'X'
],
self
.
repeat_times
)
output
=
np
.
tile
(
self
.
inputs
[
'X'
],
self
.
repeat_times
)
self
.
outputs
=
{
'Out'
:
output
}
self
.
outputs
=
{
'Out'
:
output
}
def
set_xpu
(
self
):
self
.
__class__
.
use_xpu
=
True
def
init_data
(
self
):
def
init_data
(
self
):
self
.
ori_shape
=
[
100
]
self
.
ori_shape
=
[
100
]
self
.
repeat_times
=
[
2
]
self
.
repeat_times
=
[
2
]
...
@@ -52,51 +57,48 @@ class TestTileOpRank1(XPUOpTest):
...
@@ -52,51 +57,48 @@ class TestTileOpRank1(XPUOpTest):
def
test_check_output
(
self
):
def
test_check_output
(
self
):
self
.
check_output_with_place
(
self
.
place
)
self
.
check_output_with_place
(
self
.
place
)
def
test_check_grad
(
self
):
#with dimension expanding
pass
class
TestTileOpRank2Expanding
(
TestTileOpRank1
):
#with dimension expanding
class
TestTileOpRank2Expanding
(
TestTileOpRank1
):
def
init_data
(
self
):
def
init_data
(
self
):
self
.
ori_shape
=
[
120
]
self
.
ori_shape
=
[
120
]
self
.
repeat_times
=
[
2
,
2
]
self
.
repeat_times
=
[
2
,
2
]
class
TestTileOpRank2
(
TestTileOpRank1
):
class
TestTileOpRank2
(
TestTileOpRank1
):
def
init_data
(
self
):
def
init_data
(
self
):
self
.
ori_shape
=
[
12
,
14
]
self
.
ori_shape
=
[
12
,
14
]
self
.
repeat_times
=
[
2
,
3
]
self
.
repeat_times
=
[
2
,
3
]
class
TestTileOpRank3_Corner
(
TestTileOpRank1
):
class
TestTileOpRank3_Corner
(
TestTileOpRank1
):
def
init_data
(
self
):
def
init_data
(
self
):
self
.
ori_shape
=
(
2
,
10
,
5
)
self
.
ori_shape
=
(
2
,
10
,
5
)
self
.
repeat_times
=
(
1
,
1
,
1
)
self
.
repeat_times
=
(
1
,
1
,
1
)
class
TestTileOpRank3_Corner2
(
TestTileOpRank1
):
class
TestTileOpRank3_Corner2
(
TestTileOpRank1
):
def
init_data
(
self
):
def
init_data
(
self
):
self
.
ori_shape
=
(
2
,
10
,
5
)
self
.
ori_shape
=
(
2
,
10
,
5
)
self
.
repeat_times
=
(
2
,
2
)
self
.
repeat_times
=
(
2
,
2
)
class
TestTileOpRank3
(
TestTileOpRank1
):
class
TestTileOpRank3
(
TestTileOpRank1
):
def
init_data
(
self
):
def
init_data
(
self
):
self
.
ori_shape
=
(
2
,
4
,
15
)
self
.
ori_shape
=
(
2
,
4
,
15
)
self
.
repeat_times
=
(
2
,
1
,
4
)
self
.
repeat_times
=
(
2
,
1
,
4
)
class
TestTileOpRank4
(
TestTileOpRank1
):
class
TestTileOpRank4
(
TestTileOpRank1
):
def
init_data
(
self
):
def
init_data
(
self
):
self
.
ori_shape
=
(
2
,
4
,
5
,
7
)
self
.
ori_shape
=
(
2
,
4
,
5
,
7
)
self
.
repeat_times
=
(
3
,
2
,
1
,
2
)
self
.
repeat_times
=
(
3
,
2
,
1
,
2
)
# Situation 2: repeat_times is a list (with tensor)
# Situation 2: repeat_times is a list (with tensor)
class
TestTileOpRank1_tensor_attr
(
XPUOpTest
):
class
XPUTestTileOpRank1_tensor_attr
(
XPUOpTestWrapper
):
def
__init__
(
self
):
self
.
op_name
=
'tile'
self
.
use_dynamic_create_class
=
False
class
TestTileOpRank1_tensor_attr
(
XPUOpTest
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
set_xpu
()
self
.
dtype
=
self
.
in_type
self
.
__class__
.
no_need_check_grad
=
True
self
.
place
=
paddle
.
XPUPlace
(
0
)
self
.
place
=
paddle
.
XPUPlace
(
0
)
self
.
op_type
=
"tile"
self
.
op_type
=
"tile"
self
.
init_data
()
self
.
init_data
()
...
@@ -106,16 +108,13 @@ class TestTileOpRank1_tensor_attr(XPUOpTest):
...
@@ -106,16 +108,13 @@ class TestTileOpRank1_tensor_attr(XPUOpTest):
(
1
)).
astype
(
'int32'
)
*
ele
))
(
1
)).
astype
(
'int32'
)
*
ele
))
self
.
inputs
=
{
self
.
inputs
=
{
'X'
:
np
.
random
.
random
(
self
.
ori_shape
).
astype
(
"float32"
),
'X'
:
np
.
random
.
random
(
self
.
ori_shape
).
astype
(
self
.
dtype
),
'repeat_times_tensor'
:
repeat_times_tensor
,
'repeat_times_tensor'
:
repeat_times_tensor
,
}
}
self
.
attrs
=
{
"repeat_times"
:
self
.
infer_repeat_times
}
self
.
attrs
=
{
"repeat_times"
:
self
.
infer_repeat_times
}
output
=
np
.
tile
(
self
.
inputs
[
'X'
],
self
.
repeat_times
)
output
=
np
.
tile
(
self
.
inputs
[
'X'
],
self
.
repeat_times
)
self
.
outputs
=
{
'Out'
:
output
}
self
.
outputs
=
{
'Out'
:
output
}
def
set_xpu
(
self
):
self
.
__class__
.
use_xpu
=
True
def
init_data
(
self
):
def
init_data
(
self
):
self
.
ori_shape
=
[
100
]
self
.
ori_shape
=
[
100
]
self
.
repeat_times
=
[
2
]
self
.
repeat_times
=
[
2
]
...
@@ -124,18 +123,13 @@ class TestTileOpRank1_tensor_attr(XPUOpTest):
...
@@ -124,18 +123,13 @@ class TestTileOpRank1_tensor_attr(XPUOpTest):
def
test_check_output
(
self
):
def
test_check_output
(
self
):
self
.
check_output_with_place
(
self
.
place
)
self
.
check_output_with_place
(
self
.
place
)
def
test_check_grad
(
self
):
class
TestTileOpRank2_Corner_tensor_attr
(
TestTileOpRank1_tensor_attr
):
pass
class
TestTileOpRank2_Corner_tensor_attr
(
TestTileOpRank1_tensor_attr
):
def
init_data
(
self
):
def
init_data
(
self
):
self
.
ori_shape
=
[
12
,
14
]
self
.
ori_shape
=
[
12
,
14
]
self
.
repeat_times
=
[
1
,
1
]
self
.
repeat_times
=
[
1
,
1
]
self
.
infer_repeat_times
=
[
1
,
-
1
]
self
.
infer_repeat_times
=
[
1
,
-
1
]
class
TestTileOpRank2_attr_tensor
(
TestTileOpRank1_tensor_attr
):
class
TestTileOpRank2_attr_tensor
(
TestTileOpRank1_tensor_attr
):
def
init_data
(
self
):
def
init_data
(
self
):
self
.
ori_shape
=
[
12
,
14
]
self
.
ori_shape
=
[
12
,
14
]
self
.
repeat_times
=
[
2
,
3
]
self
.
repeat_times
=
[
2
,
3
]
...
@@ -143,24 +137,27 @@ class TestTileOpRank2_attr_tensor(TestTileOpRank1_tensor_attr):
...
@@ -143,24 +137,27 @@ class TestTileOpRank2_attr_tensor(TestTileOpRank1_tensor_attr):
# Situation 3: repeat_times is a tensor
# Situation 3: repeat_times is a tensor
class
TestTileOpRank1_tensor
(
XPUOpTest
):
class
XPUTestTileOpRank1_tensor
(
XPUOpTestWrapper
):
def
__init__
(
self
):
self
.
op_name
=
'tile'
self
.
use_dynamic_create_class
=
False
class
TestTileOpRank1_tensor
(
XPUOpTest
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
set_xpu
()
self
.
dtype
=
self
.
in_type
self
.
__class__
.
no_need_check_grad
=
True
self
.
place
=
paddle
.
XPUPlace
(
0
)
self
.
place
=
paddle
.
XPUPlace
(
0
)
self
.
op_type
=
"tile"
self
.
op_type
=
"tile"
self
.
init_data
()
self
.
init_data
()
self
.
inputs
=
{
self
.
inputs
=
{
'X'
:
np
.
random
.
random
(
self
.
ori_shape
).
astype
(
"float32"
),
'X'
:
np
.
random
.
random
(
self
.
ori_shape
).
astype
(
self
.
dtype
),
'RepeatTimes'
:
np
.
array
(
self
.
repeat_times
).
astype
(
"int32"
),
'RepeatTimes'
:
np
.
array
(
self
.
repeat_times
).
astype
(
"int32"
),
}
}
self
.
attrs
=
{}
self
.
attrs
=
{}
output
=
np
.
tile
(
self
.
inputs
[
'X'
],
self
.
repeat_times
)
output
=
np
.
tile
(
self
.
inputs
[
'X'
],
self
.
repeat_times
)
self
.
outputs
=
{
'Out'
:
output
}
self
.
outputs
=
{
'Out'
:
output
}
def
set_xpu
(
self
):
self
.
__class__
.
use_xpu
=
True
def
init_data
(
self
):
def
init_data
(
self
):
self
.
ori_shape
=
[
100
]
self
.
ori_shape
=
[
100
]
self
.
repeat_times
=
[
2
]
self
.
repeat_times
=
[
2
]
...
@@ -168,77 +165,17 @@ class TestTileOpRank1_tensor(XPUOpTest):
...
@@ -168,77 +165,17 @@ class TestTileOpRank1_tensor(XPUOpTest):
def
test_check_output
(
self
):
def
test_check_output
(
self
):
self
.
check_output_with_place
(
self
.
place
)
self
.
check_output_with_place
(
self
.
place
)
def
test_check_grad
(
self
):
class
TestTileOpRank2_tensor
(
TestTileOpRank1_tensor
):
pass
class
TestTileOpRank2_tensor
(
TestTileOpRank1_tensor
):
def
init_data
(
self
):
def
init_data
(
self
):
self
.
ori_shape
=
[
12
,
14
]
self
.
ori_shape
=
[
12
,
14
]
self
.
repeat_times
=
[
2
,
3
]
self
.
repeat_times
=
[
2
,
3
]
# Situation 4: input x is Integer
support_types
=
get_xpu_op_support_types
(
'tile'
)
class
TestTileOpInteger
(
XPUOpTest
):
for
stype
in
support_types
:
def
setUp
(
self
):
create_test_class
(
globals
(),
XPUTestTileOpRank1
,
stype
)
self
.
set_xpu
()
create_test_class
(
globals
(),
XPUTestTileOpRank1_tensor_attr
,
stype
)
self
.
place
=
paddle
.
XPUPlace
(
0
)
create_test_class
(
globals
(),
XPUTestTileOpRank1_tensor
,
stype
)
self
.
op_type
=
"tile"
self
.
inputs
=
{
'X'
:
np
.
random
.
randint
(
10
,
size
=
(
4
,
4
,
5
)).
astype
(
"int32"
)
}
self
.
attrs
=
{
'repeat_times'
:
[
2
,
1
,
4
]}
output
=
np
.
tile
(
self
.
inputs
[
'X'
],
(
2
,
1
,
4
))
self
.
outputs
=
{
'Out'
:
output
}
def
set_xpu
(
self
):
self
.
__class__
.
use_xpu
=
True
def
test_check_output
(
self
):
self
.
check_output_with_place
(
self
.
place
)
# Situation 5: input x is Integer
class
TestTileOpInt64_t
(
XPUOpTest
):
def
setUp
(
self
):
self
.
set_xpu
()
self
.
place
=
paddle
.
XPUPlace
(
0
)
self
.
op_type
=
"tile"
self
.
inputs
=
{
'X'
:
np
.
random
.
randint
(
10
,
size
=
(
2
,
4
,
5
)).
astype
(
"int64"
)
}
self
.
attrs
=
{
'repeat_times'
:
[
2
,
1
,
4
]}
output
=
np
.
tile
(
self
.
inputs
[
'X'
],
(
2
,
1
,
4
))
self
.
outputs
=
{
'Out'
:
output
}
def
set_xpu
(
self
):
self
.
__class__
.
use_xpu
=
True
def
test_check_output
(
self
):
self
.
check_output_with_place
(
self
.
place
)
# Situation 6: input x is Bool
class
TestTileOpBool
(
XPUOpTest
):
def
setUp
(
self
):
self
.
set_xpu
()
self
.
place
=
paddle
.
XPUPlace
(
0
)
self
.
op_type
=
"tile"
self
.
inputs
=
{
'X'
:
np
.
random
.
randint
(
10
,
size
=
(
2
,
4
,
5
)).
astype
(
"bool"
)
}
self
.
attrs
=
{
'repeat_times'
:
[
2
,
1
,
4
]}
output
=
np
.
tile
(
self
.
inputs
[
'X'
],
(
2
,
1
,
4
))
self
.
outputs
=
{
'Out'
:
output
}
def
set_xpu
(
self
):
self
.
__class__
.
use_xpu
=
True
def
test_check_output
(
self
):
self
.
check_output_with_place
(
self
.
place
)
# Test python API
# Test python API
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录