Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
96d2f337
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 2 年 前同步成功
通知
2325
Star
20933
Fork
5424
代码
文件
提交
分支
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看板
未验证
提交
96d2f337
编写于
3月 17, 2022
作者:
T
tanzhipeng
提交者:
GitHub
3月 17, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify sequence_conv_xpu op test. test=kunlun (#40347)
上级
7dad9f70
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
193 addition
and
181 deletion
+193
-181
python/paddle/fluid/tests/unittests/xpu/test_sequence_conv_op_xpu.py
...le/fluid/tests/unittests/xpu/test_sequence_conv_op_xpu.py
+193
-181
未找到文件。
python/paddle/fluid/tests/unittests/xpu/test_sequence_conv_op_xpu.py
浏览文件 @
96d2f337
...
@@ -21,6 +21,8 @@ import random
...
@@ -21,6 +21,8 @@ import random
import
sys
import
sys
sys
.
path
.
append
(
"../"
)
sys
.
path
.
append
(
"../"
)
from
op_test_xpu
import
XPUOpTest
from
op_test_xpu
import
XPUOpTest
from
xpu.get_test_cover_info
import
create_test_class
,
get_xpu_op_support_types
from
xpu.get_test_cover_info
import
XPUOpTestWrapper
paddle
.
enable_static
()
paddle
.
enable_static
()
np
.
set_printoptions
(
threshold
=
np
.
inf
)
np
.
set_printoptions
(
threshold
=
np
.
inf
)
...
@@ -73,188 +75,198 @@ def seqconv(x,
...
@@ -73,188 +75,198 @@ def seqconv(x,
return
np
.
dot
(
col
,
filter
)
return
np
.
dot
(
col
,
filter
)
class
TestSeqProject
(
XPUOpTest
):
class
XPUTestSequenceConv
(
XPUOpTestWrapper
):
def
setUp
(
self
):
def
__init__
(
self
):
self
.
init_test_case
()
self
.
op_name
=
'sequence_conv'
self
.
op_type
=
'sequence_conv'
self
.
use_xpu
=
True
class
TestSeqProject
(
XPUOpTest
):
def
setUp
(
self
):
if
self
.
context_length
==
1
\
self
.
init_test_case
()
and
self
.
context_start
==
0
\
self
.
op_type
=
'sequence_conv'
and
self
.
padding_trainable
:
self
.
dtype
=
self
.
in_type
print
(
"If context_start is 0 "
\
self
.
use_xpu
=
True
"and context_length is 1,"
\
" padding_trainable should be false."
)
if
self
.
context_length
==
1
\
return
and
self
.
context_start
==
0
\
and
self
.
padding_trainable
:
# one level, batch size
print
(
"If context_start is 0 "
\
x
=
np
.
random
.
uniform
(
-
6.10907e-05
,
0.000104218
,
"and context_length is 1,"
\
[
self
.
input_size
[
0
],
" padding_trainable should be false."
)
self
.
input_size
[
1
]]).
astype
(
'float32'
)
return
w
=
np
.
random
.
uniform
(
-
3.17068e-05
,
0.000159822
,
[
self
.
context_length
*
self
.
input_size
[
1
],
self
.
output_represention
# one level, batch size
]).
astype
(
'float32'
)
x
=
np
.
random
.
uniform
(
-
6.10907e-05
,
0.000104218
,
[
self
.
input_size
[
0
],
begin_pad
=
np
.
max
([
0
,
-
self
.
context_start
])
self
.
input_size
[
1
]]).
astype
(
self
.
dtype
)
end_pad
=
np
.
max
([
0
,
self
.
context_start
+
self
.
context_length
-
1
])
w
=
np
.
random
.
uniform
(
-
3.17068e-05
,
0.000159822
,
[
total_pad
=
begin_pad
+
end_pad
self
.
context_length
*
self
.
input_size
[
1
],
padding_data
=
np
.
random
.
uniform
(
self
.
output_represention
0
,
0
,
[
total_pad
,
self
.
input_size
[
1
]]).
astype
(
'float32'
)
]).
astype
(
self
.
dtype
)
self
.
pad_data
=
padding_data
self
.
inputs
=
{
begin_pad
=
np
.
max
([
0
,
-
self
.
context_start
])
'X'
:
(
x
,
self
.
lod
),
end_pad
=
np
.
max
([
0
,
self
.
context_start
+
self
.
context_length
-
1
])
'Filter'
:
w
,
total_pad
=
begin_pad
+
end_pad
}
padding_data
=
np
.
random
.
uniform
(
self
.
inputs_val
=
[
'X'
,
'Filter'
]
0
,
0
,
[
total_pad
,
self
.
input_size
[
1
]]).
astype
(
self
.
dtype
)
self
.
inputs_val_no_x
=
[
'Filter'
]
self
.
pad_data
=
padding_data
self
.
inputs_val_no_f
=
[
'X'
]
self
.
inputs
=
{
'X'
:
(
x
,
self
.
lod
),
if
total_pad
!=
0
:
'Filter'
:
w
,
self
.
inputs
[
'PaddingData'
]
=
padding_data
}
self
.
inputs_val
=
[
'X'
,
'PaddingData'
,
'Filter'
]
self
.
inputs_val
=
[
'X'
,
'Filter'
]
self
.
inputs_val_no_x
=
[
'PaddingData'
,
'Filter'
]
self
.
inputs_val_no_x
=
[
'Filter'
]
self
.
inputs_val_no_f
=
[
'PaddingData'
,
'X'
]
self
.
inputs_val_no_f
=
[
'X'
]
self
.
attrs
=
{
if
total_pad
!=
0
:
'contextStart'
:
self
.
context_start
,
self
.
inputs
[
'PaddingData'
]
=
padding_data
'contextLength'
:
self
.
context_length
,
self
.
inputs_val
=
[
'X'
,
'PaddingData'
,
'Filter'
]
'paddingTrainable'
:
self
.
padding_trainable
,
self
.
inputs_val_no_x
=
[
'PaddingData'
,
'Filter'
]
'contextStride'
:
self
.
context_stride
self
.
inputs_val_no_f
=
[
'PaddingData'
,
'X'
]
}
out
=
seqconv
(
x
,
self
.
lod
,
w
,
self
.
context_length
,
self
.
context_start
,
self
.
attrs
=
{
self
.
padding_trainable
,
self
.
pad_data
)
'contextStart'
:
self
.
context_start
,
self
.
outputs
=
{
'Out'
:
out
}
'contextLength'
:
self
.
context_length
,
'paddingTrainable'
:
self
.
padding_trainable
,
def
test_check_output
(
self
):
'contextStride'
:
self
.
context_stride
place
=
paddle
.
XPUPlace
(
0
)
}
self
.
check_output_with_place
(
place
)
out
=
seqconv
(
x
,
self
.
lod
,
w
,
self
.
context_length
,
self
.
context_start
,
self
.
padding_trainable
,
def
test_check_grad_input
(
self
):
self
.
pad_data
)
self
.
check_grad
([
'X'
],
'Out'
,
no_grad_set
=
set
(
self
.
inputs_val_no_x
))
self
.
outputs
=
{
'Out'
:
out
}
def
test_check_grad_padding_data
(
self
):
def
test_check_output
(
self
):
if
self
.
padding_trainable
:
place
=
paddle
.
XPUPlace
(
0
)
self
.
check_output_with_place
(
place
)
def
test_check_grad_input
(
self
):
self
.
check_grad
([
'X'
],
'Out'
,
no_grad_set
=
set
(
self
.
inputs_val_no_x
))
def
test_check_grad_padding_data
(
self
):
if
self
.
padding_trainable
:
self
.
check_grad
(
[
'PaddingData'
],
'Out'
,
no_grad_set
=
set
([
'X'
,
'Filter'
]))
def
test_check_grad_Filter
(
self
):
self
.
check_grad
(
self
.
check_grad
(
[
'PaddingData'
],
'Out'
,
no_grad_set
=
set
([
'X'
,
'Filter'
]))
[
'Filter'
],
'Out'
,
no_grad_set
=
set
(
self
.
inputs_val_no_f
))
def
test_check_grad_Filter
(
self
):
def
test_check_grad_input_filter
(
self
):
self
.
check_grad
(
if
self
.
padding_trainable
:
[
'Filter'
],
'Out'
,
no_grad_set
=
set
(
self
.
inputs_val_no_f
))
self
.
check_grad
(
[
'X'
,
'Filter'
],
'Out'
,
no_grad_set
=
set
([
'PaddingData'
]))
def
test_check_grad_input_filter
(
self
):
if
self
.
padding_trainable
:
def
test_check_grad_padding_input
(
self
):
self
.
check_grad
(
if
self
.
padding_trainable
:
[
'X'
,
'Filter'
],
'Out'
,
no_grad_set
=
set
([
'PaddingData'
]))
self
.
check_grad
(
self
.
inputs_val_no_f
,
'Out'
,
no_grad_set
=
set
([
'Filter'
]))
def
test_check_grad_padding_input
(
self
):
if
self
.
padding_trainable
:
def
test_check_grad_padding_filter
(
self
):
self
.
check_grad
(
if
self
.
padding_trainable
:
self
.
inputs_val_no_f
,
'Out'
,
no_grad_set
=
set
([
'Filter'
]))
self
.
check_grad
(
self
.
inputs_val_no_x
,
'Out'
,
no_grad_set
=
set
([
'X'
]))
def
test_check_grad_padding_filter
(
self
):
if
self
.
padding_trainable
:
def
init_test_case
(
self
):
self
.
check_grad
(
self
.
inputs_val_no_x
,
'Out'
,
no_grad_set
=
set
([
'X'
]))
self
.
input_row
=
7
self
.
input_col
=
25
def
init_test_case
(
self
):
self
.
context_start
=
-
2
self
.
input_row
=
7
self
.
context_length
=
5
self
.
input_col
=
25
self
.
padding_trainable
=
False
self
.
context_start
=
-
2
self
.
context_stride
=
1
self
.
context_length
=
5
self
.
padding_trainable
=
False
self
.
input_size
=
[
self
.
input_row
,
self
.
input_col
]
self
.
context_stride
=
1
offset_lod
=
[[
0
,
1
,
self
.
input_row
]]
self
.
lod
=
[[]]
self
.
input_size
=
[
self
.
input_row
,
self
.
input_col
]
# convert from offset-based lod to length-based lod
offset_lod
=
[[
0
,
1
,
self
.
input_row
]]
for
i
in
range
(
len
(
offset_lod
[
0
])
-
1
):
self
.
lod
=
[[]]
self
.
lod
[
0
].
append
(
offset_lod
[
0
][
i
+
1
]
-
offset_lod
[
0
][
i
])
# convert from offset-based lod to length-based lod
self
.
output_represention
=
8
# output feature size
for
i
in
range
(
len
(
offset_lod
[
0
])
-
1
):
self
.
lod
[
0
].
append
(
offset_lod
[
0
][
i
+
1
]
-
offset_lod
[
0
][
i
])
class
TestSeqProjectCase1
(
TestSeqProject
):
self
.
output_represention
=
8
# output feature size
def
init_test_case
(
self
):
self
.
input_row
=
11
self
.
context_start
=
-
2
class
TestSeqProjectCase1
(
TestSeqProject
):
self
.
context_length
=
5
def
init_test_case
(
self
):
self
.
padding_trainable
=
False
self
.
input_row
=
11
self
.
context_stride
=
1
self
.
context_start
=
-
2
self
.
context_length
=
5
self
.
input_size
=
[
self
.
input_row
,
50
]
self
.
padding_trainable
=
False
offset_lod
=
[[
0
,
4
,
5
,
8
,
self
.
input_row
]]
self
.
context_stride
=
1
self
.
lod
=
[[]]
# convert from offset-based lod to length-based lod
self
.
input_size
=
[
self
.
input_row
,
50
]
for
i
in
range
(
len
(
offset_lod
[
0
])
-
1
):
offset_lod
=
[[
0
,
4
,
5
,
8
,
self
.
input_row
]]
self
.
lod
[
0
].
append
(
offset_lod
[
0
][
i
+
1
]
-
offset_lod
[
0
][
i
])
self
.
lod
=
[[]]
self
.
output_represention
=
8
# output feature size
# convert from offset-based lod to length-based lod
for
i
in
range
(
len
(
offset_lod
[
0
])
-
1
):
class
TestSeqProjectCase2Len0
(
TestSeqProject
):
self
.
lod
[
0
].
append
(
offset_lod
[
0
][
i
+
1
]
-
offset_lod
[
0
][
i
])
def
init_test_case
(
self
):
self
.
output_represention
=
8
# output feature size
self
.
input_row
=
11
self
.
context_start
=
-
2
self
.
context_length
=
5
class
TestSeqProjectCase2Len0
(
TestSeqProject
):
self
.
padding_trainable
=
False
def
init_test_case
(
self
):
self
.
context_stride
=
1
self
.
input_row
=
11
self
.
context_start
=
-
2
self
.
input_size
=
[
self
.
input_row
,
50
]
self
.
context_length
=
5
offset_lod
=
[[
0
,
0
,
4
,
5
,
5
,
8
,
self
.
input_row
,
self
.
input_row
]]
self
.
padding_trainable
=
False
self
.
lod
=
[[]]
self
.
context_stride
=
1
# convert from offset-based lod to length-based lod
for
i
in
range
(
len
(
offset_lod
[
0
])
-
1
):
self
.
input_size
=
[
self
.
input_row
,
50
]
self
.
lod
[
0
].
append
(
offset_lod
[
0
][
i
+
1
]
-
offset_lod
[
0
][
i
])
offset_lod
=
[[
0
,
0
,
4
,
5
,
5
,
8
,
self
.
input_row
,
self
.
input_row
]]
self
.
output_represention
=
8
# output feature size
self
.
lod
=
[[]]
# convert from offset-based lod to length-based lod
class
TestSeqProjectCase3
(
TestSeqProject
):
for
i
in
range
(
len
(
offset_lod
[
0
])
-
1
):
def
init_test_case
(
self
):
self
.
lod
[
0
].
append
(
offset_lod
[
0
][
i
+
1
]
-
offset_lod
[
0
][
i
])
self
.
input_row
=
25
self
.
output_represention
=
8
# output feature size
self
.
context_start
=
-
2
self
.
context_length
=
5
self
.
padding_trainable
=
False
class
TestSeqProjectCase3
(
TestSeqProject
):
self
.
context_stride
=
1
def
init_test_case
(
self
):
self
.
input_row
=
25
self
.
input_size
=
[
self
.
input_row
,
25
]
self
.
context_start
=
-
2
idx
=
list
(
range
(
self
.
input_size
[
0
]))
self
.
context_length
=
5
del
idx
[
0
]
self
.
padding_trainable
=
False
offset_lod
=
[[
0
]
+
np
.
sort
(
random
.
sample
(
idx
,
8
)).
tolist
()
+
self
.
context_stride
=
1
[
self
.
input_size
[
0
]]]
self
.
lod
=
[[]]
self
.
input_size
=
[
self
.
input_row
,
25
]
# convert from offset-based lod to length-based lod
idx
=
list
(
range
(
self
.
input_size
[
0
]))
for
i
in
range
(
len
(
offset_lod
[
0
])
-
1
):
del
idx
[
0
]
self
.
lod
[
0
].
append
(
offset_lod
[
0
][
i
+
1
]
-
offset_lod
[
0
][
i
])
offset_lod
=
[[
0
]
+
np
.
sort
(
random
.
sample
(
idx
,
8
)).
tolist
()
+
self
.
output_represention
=
8
# output feature size
[
self
.
input_size
[
0
]]]
self
.
lod
=
[[]]
class
TestSeqProjectCase4
(
TestSeqProject
):
# convert from offset-based lod to length-based lod
def
init_test_case
(
self
):
for
i
in
range
(
len
(
offset_lod
[
0
])
-
1
):
self
.
input_row
=
7835
self
.
lod
[
0
].
append
(
offset_lod
[
0
][
i
+
1
]
-
offset_lod
[
0
][
i
])
self
.
input_col
=
128
self
.
output_represention
=
8
# output feature size
self
.
context_start
=
-
2
self
.
context_length
=
5
self
.
padding_trainable
=
False
class
TestSeqProjectCase4
(
TestSeqProject
):
self
.
context_stride
=
1
def
init_test_case
(
self
):
self
.
input_row
=
7835
self
.
input_size
=
[
self
.
input_row
,
self
.
input_col
]
self
.
input_col
=
128
offset_lod
=
[[
self
.
context_start
=
-
2
0
,
1
,
2
,
3
,
131
,
241
,
242
,
263
,
264
,
265
,
266
,
267
,
268
,
387
,
self
.
context_length
=
5
515
,
516
,
644
,
645
,
772
,
794
,
922
,
923
,
924
,
944
,
945
,
1073
,
self
.
padding_trainable
=
False
1074
,
1202
,
1330
,
1458
,
1556
,
1557
,
1558
,
1686
,
1748
,
1876
,
self
.
context_stride
=
1
1912
,
1913
,
1914
,
2032
,
2066
,
2194
,
2308
,
2309
,
2347
,
2475
,
2476
,
2477
,
2478
,
2606
,
2607
,
2735
,
2736
,
2737
,
2738
,
2838
,
self
.
input_size
=
[
self
.
input_row
,
self
.
input_col
]
2966
,
2967
,
2968
,
2969
,
3097
,
3225
,
3353
,
3481
,
3482
,
3520
,
offset_lod
=
[[
3642
,
3643
,
3754
,
3882
,
3883
,
4010
,
4011
,
4012
,
4140
,
4219
,
0
,
1
,
2
,
3
,
131
,
241
,
242
,
263
,
264
,
265
,
266
,
267
,
268
,
387
,
515
,
4228
,
4356
,
4357
,
4415
,
4475
,
4476
,
4604
,
4605
,
4606
,
4694
,
516
,
644
,
645
,
772
,
794
,
922
,
923
,
924
,
944
,
945
,
1073
,
1074
,
1202
,
4695
,
4808
,
4936
,
4961
,
4962
,
5004
,
5132
,
5260
,
5312
,
5440
,
1330
,
1458
,
1556
,
1557
,
1558
,
1686
,
1748
,
1876
,
1912
,
1913
,
1914
,
5441
,
5569
,
5570
,
5675
,
5676
,
5750
,
5810
,
5811
,
5939
,
6021
,
2032
,
2066
,
2194
,
2308
,
2309
,
2347
,
2475
,
2476
,
2477
,
2478
,
2606
,
6149
,
6277
,
6278
,
6364
,
6425
,
6519
,
6647
,
6648
,
6739
,
6867
,
2607
,
2735
,
2736
,
2737
,
2738
,
2838
,
2966
,
2967
,
2968
,
2969
,
3097
,
6995
,
6996
,
7120
,
7223
,
7244
,
7367
,
7407
,
7408
,
7467
,
7595
,
3225
,
3353
,
3481
,
3482
,
3520
,
3642
,
3643
,
3754
,
3882
,
3883
,
4010
,
7699
,
7827
,
7835
4011
,
4012
,
4140
,
4219
,
4228
,
4356
,
4357
,
4415
,
4475
,
4476
,
4604
,
]]
4605
,
4606
,
4694
,
4695
,
4808
,
4936
,
4961
,
4962
,
5004
,
5132
,
5260
,
self
.
lod
=
[[]]
5312
,
5440
,
5441
,
5569
,
5570
,
5675
,
5676
,
5750
,
5810
,
5811
,
5939
,
# convert from offset-based lod to length-based lod
6021
,
6149
,
6277
,
6278
,
6364
,
6425
,
6519
,
6647
,
6648
,
6739
,
6867
,
for
i
in
range
(
len
(
offset_lod
[
0
])
-
1
):
6995
,
6996
,
7120
,
7223
,
7244
,
7367
,
7407
,
7408
,
7467
,
7595
,
7699
,
self
.
lod
[
0
].
append
(
offset_lod
[
0
][
i
+
1
]
-
offset_lod
[
0
][
i
])
7827
,
7835
self
.
output_represention
=
8
# output feature size
]]
self
.
lod
=
[[]]
# convert from offset-based lod to length-based lod
support_types
=
get_xpu_op_support_types
(
'sequence_conv'
)
for
i
in
range
(
len
(
offset_lod
[
0
])
-
1
):
for
stype
in
support_types
:
self
.
lod
[
0
].
append
(
offset_lod
[
0
][
i
+
1
]
-
offset_lod
[
0
][
i
])
create_test_class
(
globals
(),
XPUTestSequenceConv
,
stype
)
self
.
output_represention
=
8
# output feature size
class
TestSeqConvApi
(
unittest
.
TestCase
):
class
TestSeqConvApi
(
unittest
.
TestCase
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录