Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
f21d7957
P
Paddle
项目概览
机器未来
/
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看板
未验证
提交
f21d7957
编写于
2月 16, 2022
作者:
T
TTerror
提交者:
GitHub
2月 16, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor huber_loss/argsor unittests for kunlun, *test=kunlun (#39527)
上级
6eb95caf
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
133 addition
and
267 deletion
+133
-267
python/paddle/fluid/tests/unittests/xpu/get_test_cover_info.py
...n/paddle/fluid/tests/unittests/xpu/get_test_cover_info.py
+3
-3
python/paddle/fluid/tests/unittests/xpu/test_argsort_op_xpu.py
...n/paddle/fluid/tests/unittests/xpu/test_argsort_op_xpu.py
+67
-208
python/paddle/fluid/tests/unittests/xpu/test_huber_loss_op_xpu.py
...addle/fluid/tests/unittests/xpu/test_huber_loss_op_xpu.py
+63
-56
未找到文件。
python/paddle/fluid/tests/unittests/xpu/get_test_cover_info.py
浏览文件 @
f21d7957
...
@@ -83,8 +83,8 @@ type_dict_str_to_numpy = {
...
@@ -83,8 +83,8 @@ type_dict_str_to_numpy = {
}
}
xpu_test_op_white_list
=
[]
xpu_test_op_white_list
=
[]
xpu_test_type_white_list
=
[]
xpu_test_type_white_list
=
[
'float64'
]
xpu_test_op_type_white_list
=
[
'float64'
]
xpu_test_op_type_white_list
=
[]
xpu_test_device_op_white_list
=
[]
xpu_test_device_op_white_list
=
[]
xpu_test_device_op_type_white_list
=
[]
xpu_test_device_op_type_white_list
=
[]
...
@@ -186,7 +186,7 @@ def get_xpu_op_support_types(op_name, dev_id=0):
...
@@ -186,7 +186,7 @@ def get_xpu_op_support_types(op_name, dev_id=0):
paddle
.
bfloat16
])
paddle
.
bfloat16
])
else
:
else
:
support_type_str_list
.
append
(
type_dict_paddle_to_str
[
stype
])
support_type_str_list
.
append
(
type_dict_paddle_to_str
[
stype
])
type_white_list
=
get_
op_
type_white_list
()
type_white_list
=
get_type_white_list
()
return
[
return
[
stype
for
stype
in
support_type_str_list
if
stype
not
in
type_white_list
stype
for
stype
in
support_type_str_list
if
stype
not
in
type_white_list
]
]
...
...
python/paddle/fluid/tests/unittests/xpu/test_argsort_op_xpu.py
浏览文件 @
f21d7957
...
@@ -18,220 +18,79 @@ import numpy as np
...
@@ -18,220 +18,79 @@ import numpy as np
import
unittest
import
unittest
import
sys
import
sys
sys
.
path
.
append
(
".."
)
sys
.
path
.
append
(
".."
)
import
paddle
from
op_test
import
OpTest
from
op_test
import
OpTest
from
op_test_xpu
import
XPUOpTest
from
op_test_xpu
import
XPUOpTest
import
paddle
from
xpu.get_test_cover_info
import
create_test_class
,
get_xpu_op_support_types
,
XPUOpTestWrapper
import
paddle.fluid
as
fluid
import
paddle.fluid.core
as
core
from
paddle.fluid
import
ParamAttr
from
paddle.fluid.framework
import
Program
,
grad_var_name
from
paddle.fluid.executor
import
Executor
from
paddle.fluid.backward
import
append_backward
paddle
.
enable_static
()
paddle
.
enable_static
()
class
TestArgsortOp
(
XPUOpTest
):
class
XPUTestArgsortOp
(
XPUOpTestWrapper
):
def
setUp
(
self
):
def
__init__
(
self
):
self
.
set_xpu
()
self
.
op_name
=
'argsort'
self
.
op_type
=
"argsort"
self
.
use_dynamic_create_class
=
True
self
.
place
=
paddle
.
XPUPlace
(
0
)
self
.
init_dtype
()
def
dynamic_create_class
(
self
):
self
.
init_inputshape
()
base_class
=
self
.
TestArgsortOp
self
.
init_axis
()
classes
=
[]
self
.
init_direction
()
for
descending
in
[
True
,
False
]:
for
axis
in
[
0
,
1
,
2
,
-
1
,
-
2
]:
self
.
x
=
np
.
random
.
random
(
self
.
input_shape
).
astype
(
self
.
dtype
)
class_name
=
'XPUTestArgsortOp_axis_'
+
str
(
axis
)
+
'_'
+
str
(
self
.
inputs
=
{
"X"
:
self
.
x
}
descending
)
self
.
attrs
=
{
"axis"
:
self
.
axis
,
"descending"
:
self
.
descending
}
attr_dict
=
{
'init_axis'
:
axis
,
'init_descending'
:
descending
}
self
.
get_output
()
classes
.
append
([
class_name
,
attr_dict
])
self
.
outputs
=
{
"Out"
:
self
.
sorted_x
,
"Indices"
:
self
.
indices
}
return
base_class
,
classes
def
get_output
(
self
):
class
TestArgsortOp
(
XPUOpTest
):
if
self
.
descending
:
def
setUp
(
self
):
self
.
indices
=
np
.
flip
(
self
.
set_xpu
()
np
.
argsort
(
self
.
op_type
=
"argsort"
self
.
x
,
kind
=
'heapsort'
,
axis
=
self
.
axis
),
self
.
axis
)
self
.
place
=
paddle
.
XPUPlace
(
0
)
self
.
sorted_x
=
np
.
flip
(
self
.
dtype
=
self
.
in_type
np
.
sort
(
self
.
input_shape
=
(
2
,
2
,
2
,
3
,
3
)
self
.
x
,
kind
=
'heapsort'
,
axis
=
self
.
axis
),
self
.
axis
)
self
.
axis
=
-
1
if
not
hasattr
(
self
,
'init_axis'
)
else
self
.
init_axis
else
:
self
.
descending
=
False
if
not
hasattr
(
self
.
indices
=
np
.
argsort
(
self
.
x
,
kind
=
'heapsort'
,
axis
=
self
.
axis
)
self
,
'init_descending'
)
else
self
.
init_descending
self
.
sorted_x
=
np
.
sort
(
self
.
x
,
kind
=
'heapsort'
,
axis
=
self
.
axis
)
if
self
.
dtype
==
np
.
float32
:
def
set_xpu
(
self
):
self
.
x
=
np
.
random
.
random
(
self
.
input_shape
).
astype
(
self
.
dtype
)
self
.
__class__
.
use_xpu
=
True
else
:
self
.
__class__
.
no_need_check_grad
=
True
self
.
x
=
np
.
random
.
randint
(
low
=-
1000
,
high
=
1000
,
def
init_inputshape
(
self
):
size
=
self
.
input_shape
).
astype
(
self
.
dtype
)
self
.
input_shape
=
(
2
,
2
,
2
,
3
,
3
)
self
.
inputs
=
{
"X"
:
self
.
x
}
def
init_dtype
(
self
):
self
.
attrs
=
{
"axis"
:
self
.
axis
,
"descending"
:
self
.
descending
}
self
.
dtype
=
'float32'
self
.
get_output
()
self
.
outputs
=
{
"Out"
:
self
.
sorted_x
,
"Indices"
:
self
.
indices
}
def
init_axis
(
self
):
self
.
axis
=
-
1
def
get_output
(
self
):
if
self
.
descending
:
def
test_check_output
(
self
):
self
.
indices
=
np
.
flip
(
self
.
check_output_with_place
(
self
.
place
)
np
.
argsort
(
self
.
x
,
kind
=
'heapsort'
,
axis
=
self
.
axis
),
def
init_direction
(
self
):
self
.
axis
)
self
.
descending
=
False
self
.
sorted_x
=
np
.
flip
(
np
.
sort
(
self
.
x
,
kind
=
'heapsort'
,
axis
=
self
.
axis
),
self
.
axis
)
class
TestArgsortOpAxis0XPU
(
TestArgsortOp
):
else
:
def
init_axis
(
self
):
self
.
indices
=
np
.
argsort
(
self
.
axis
=
0
self
.
x
,
kind
=
'heapsort'
,
axis
=
self
.
axis
)
self
.
sorted_x
=
np
.
sort
(
self
.
x
,
kind
=
'heapsort'
,
axis
=
self
.
axis
)
class
TestArgsortOpAxis1XPU
(
TestArgsortOp
):
def
set_xpu
(
self
):
def
init_axis
(
self
):
self
.
__class__
.
use_xpu
=
True
self
.
axis
=
1
self
.
__class__
.
no_need_check_grad
=
True
def
test_check_output
(
self
):
class
TestArgsortOpAxis2XPU
(
TestArgsortOp
):
self
.
check_output_with_place
(
self
.
place
)
def
init_axis
(
self
):
self
.
axis
=
2
support_types
=
get_xpu_op_support_types
(
'argsort'
)
for
stype
in
support_types
:
class
TestArgsortOpAxisNeg1XPU
(
TestArgsortOp
):
create_test_class
(
globals
(),
XPUTestArgsortOp
,
stype
)
def
init_axis
(
self
):
self
.
axis
=
-
1
class
TestArgsortOpAxisNeg2XPU
(
TestArgsortOp
):
def
init_axis
(
self
):
self
.
axis
=
-
2
class
TestArgsortOpDescendingAxisXPU
(
TestArgsortOp
):
def
init_direction
(
self
):
self
.
descending
=
True
class
TestArgsortOpDescendingAxis0XPU
(
TestArgsortOpAxis0XPU
):
def
init_direction
(
self
):
self
.
descending
=
True
class
TestArgsortOpDescendingAxis1XPU
(
TestArgsortOpAxis1XPU
):
def
init_direction
(
self
):
self
.
descending
=
True
class
TestArgsortOpDescendingAxis2XPU
(
TestArgsortOpAxis2XPU
):
def
init_direction
(
self
):
self
.
descending
=
True
class
TestArgsortOpDescendingAxisNeg1XPU
(
TestArgsortOpAxisNeg1XPU
):
def
init_direction
(
self
):
self
.
descending
=
True
class
TestArgsortOpDescendingAxisNeg2XPU
(
TestArgsortOpAxisNeg2XPU
):
def
init_direction
(
self
):
self
.
descending
=
True
class
TestArgsortOpAxis0XPUINT64
(
TestArgsortOp
):
def
setUp
(
self
):
self
.
set_xpu
()
self
.
op_type
=
"argsort"
self
.
place
=
paddle
.
XPUPlace
(
0
)
self
.
init_dtype
()
self
.
init_inputshape
()
self
.
init_axis
()
self
.
init_direction
()
self
.
x
=
np
.
random
.
randint
(
low
=-
1000
,
high
=
1000
,
size
=
self
.
input_shape
).
astype
(
self
.
dtype
)
self
.
inputs
=
{
"X"
:
self
.
x
}
self
.
attrs
=
{
"axis"
:
self
.
axis
,
"descending"
:
self
.
descending
}
self
.
get_output
()
self
.
outputs
=
{
"Out"
:
self
.
sorted_x
,
"Indices"
:
self
.
indices
}
def
init_axis
(
self
):
self
.
axis
=
0
def
init_dtype
(
self
):
self
.
dtype
=
'int64'
class
TestArgsortOpAxis1XPUINT64
(
TestArgsortOpAxis0XPUINT64
):
def
init_axis
(
self
):
self
.
axis
=
1
class
TestArgsortOpAxis2XPUINT64
(
TestArgsortOpAxis0XPUINT64
):
def
init_axis
(
self
):
self
.
axis
=
2
class
TestArgsortOpAxisNeg1XPUINT64
(
TestArgsortOpAxis0XPUINT64
):
def
init_axis
(
self
):
self
.
axis
=
-
1
class
TestArgsortOpAxisNeg2XPUINT64
(
TestArgsortOpAxis0XPUINT64
):
def
init_axis
(
self
):
self
.
axis
=
-
2
class
TestArgsortOpDescendingAxisXPUINT64
(
TestArgsortOpAxis0XPUINT64
):
def
init_direction
(
self
):
self
.
descending
=
True
class
TestArgsortOpDescendingAxis0XPUINT64
(
TestArgsortOpAxis0XPUINT64
):
def
init_direction
(
self
):
self
.
descending
=
True
class
TestArgsortOpDescendingAxis1XPUINT64
(
TestArgsortOpAxis1XPUINT64
):
def
init_direction
(
self
):
self
.
descending
=
True
class
TestArgsortOpDescendingAxis2XPUINT64
(
TestArgsortOpAxis2XPUINT64
):
def
init_direction
(
self
):
self
.
descending
=
True
class
TestArgsortOpDescendingAxisNeg1XPUINT64
(
TestArgsortOpAxisNeg1XPUINT64
):
def
init_direction
(
self
):
self
.
descending
=
True
class
TestArgsortOpDescendingAxisNeg2XPUINT64
(
TestArgsortOpAxisNeg2XPUINT64
):
def
init_direction
(
self
):
self
.
descending
=
True
class
TestArgsortOpAxis0XPUINT
(
TestArgsortOp
):
def
setUp
(
self
):
self
.
set_xpu
()
self
.
op_type
=
"argsort"
self
.
place
=
paddle
.
XPUPlace
(
0
)
self
.
init_dtype
()
self
.
init_inputshape
()
self
.
init_axis
()
self
.
init_direction
()
self
.
x
=
np
.
random
.
randint
(
low
=-
1000
,
high
=
1000
,
size
=
self
.
input_shape
).
astype
(
self
.
dtype
)
self
.
inputs
=
{
"X"
:
self
.
x
}
self
.
attrs
=
{
"axis"
:
self
.
axis
,
"descending"
:
self
.
descending
}
self
.
get_output
()
self
.
outputs
=
{
"Out"
:
self
.
sorted_x
,
"Indices"
:
self
.
indices
}
def
init_axis
(
self
):
self
.
axis
=
0
def
init_dtype
(
self
):
self
.
dtype
=
'int'
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
python/paddle/fluid/tests/unittests/xpu/test_huber_loss_op_xpu.py
浏览文件 @
f21d7957
...
@@ -18,11 +18,13 @@ import unittest
...
@@ -18,11 +18,13 @@ import unittest
import
numpy
as
np
import
numpy
as
np
import
sys
import
sys
sys
.
path
.
append
(
".."
)
sys
.
path
.
append
(
".."
)
from
op_test
import
OpTest
from
op_test_xpu
import
XPUOpTest
import
paddle
import
paddle
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
from
paddle.fluid
import
compiler
,
Program
,
program_guard
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
()
...
@@ -35,76 +37,81 @@ def huber_loss_forward(val, delta):
...
@@ -35,76 +37,81 @@ def huber_loss_forward(val, delta):
return
delta
*
(
abs_val
-
0.5
*
delta
)
return
delta
*
(
abs_val
-
0.5
*
delta
)
class
TestHuberLossOp
(
XPUOpTest
):
class
XPUTestHuberLossOp
(
XPUOpTestWrapper
):
def
setUp
(
self
):
def
__init__
(
self
):
self
.
set_xpu
()
self
.
op_name
=
'huber_loss'
self
.
op_type
=
'huber_loss'
self
.
use_dynamic_create_class
=
False
self
.
place
=
paddle
.
XPUPlace
(
0
)
self
.
init_dtype
()
self
.
set_inputs
()
self
.
set_attrs
()
self
.
set_outputs
()
def
set_inputs
(
self
):
class
TestHuberLossOp
(
XPUOpTest
):
shape
=
self
.
set_shape
()
def
setUp
(
self
):
x
=
np
.
random
.
uniform
(
0
,
1.
,
shape
).
astype
(
self
.
dtype
)
self
.
set_xpu
()
y
=
np
.
random
.
uniform
(
0
,
1.
,
shape
).
astype
(
self
.
dtype
)
self
.
op_type
=
'huber_loss'
self
.
inputs
=
{
self
.
place
=
paddle
.
XPUPlace
(
0
)
'X'
:
OpTest
.
np_dtype_to_fluid_dtype
(
x
),
'Y'
:
OpTest
.
np_dtype_to_fluid_dtype
(
y
)
}
def
set_attrs
(
self
):
self
.
init_dtype
()
self
.
attrs
=
{
'delta'
:
0.5
}
self
.
set_inputs
()
self
.
set_attrs
()
self
.
set_outputs
()
def
set_outputs
(
self
):
def
set_inputs
(
self
):
delta
=
self
.
attrs
[
'delta'
]
shape
=
self
.
set_shape
()
shape
=
self
.
set_shape
()
x
=
np
.
random
.
uniform
(
0
,
1.
,
shape
).
astype
(
self
.
dtype
)
residual
=
self
.
inputs
[
'Y'
]
-
self
.
inputs
[
'X'
]
y
=
np
.
random
.
uniform
(
0
,
1.
,
shape
).
astype
(
self
.
dtype
)
loss
=
np
.
vectorize
(
huber_loss_forward
)(
residual
,
self
.
inputs
=
{
delta
).
astype
(
self
.
dtype
)
'X'
:
OpTest
.
np_dtype_to_fluid_dtype
(
x
),
self
.
outputs
=
{
'Residual'
:
residual
,
'Out'
:
loss
.
reshape
(
shape
)}
'Y'
:
OpTest
.
np_dtype_to_fluid_dtype
(
y
)
}
def
set_shape
(
self
):
def
set_attrs
(
self
):
return
(
100
,
1
)
self
.
attrs
=
{
'delta'
:
0.5
}
def
set_xpu
(
self
):
def
set_outputs
(
self
):
self
.
__class__
.
use_xpu
=
True
delta
=
self
.
attrs
[
'delta'
]
shape
=
self
.
set_shape
()
residual
=
self
.
inputs
[
'Y'
]
-
self
.
inputs
[
'X'
]
loss
=
np
.
vectorize
(
huber_loss_forward
)(
residual
,
delta
).
astype
(
self
.
dtype
)
self
.
outputs
=
{
'Residual'
:
residual
,
'Out'
:
loss
.
reshape
(
shape
)}
def
init_dty
pe
(
self
):
def
set_sha
pe
(
self
):
self
.
dtype
=
np
.
float32
return
(
100
,
1
)
def
test_check_output
(
self
):
def
set_xpu
(
self
):
self
.
check_output_with_place
(
self
.
place
)
self
.
__class__
.
use_xpu
=
True
def
test_check_grad_normal
(
self
):
def
init_dtype
(
self
):
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
,
'Y'
],
'Out'
)
self
.
dtype
=
self
.
in_type
def
test_check_grad_ingore_x
(
self
):
def
test_check_output
(
self
):
self
.
check_grad_with_place
(
self
.
check_output_with_place
(
self
.
place
)
self
.
place
,
[
'Y'
],
'Out'
,
no_grad_set
=
set
(
"residual"
))
def
test_check_grad_ingore_y
(
self
):
def
test_check_grad_normal
(
self
):
self
.
check_grad_with_place
(
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
,
'Y'
],
'Out'
)
self
.
place
,
[
'X'
],
'Out'
,
no_grad_set
=
set
(
'residual'
))
def
test_check_grad_ingore_x
(
self
):
self
.
check_grad_with_place
(
self
.
place
,
[
'Y'
],
'Out'
,
no_grad_set
=
set
(
"residual"
))
def
TestHuberLossOp1
(
TestHuberLossOp
):
def
test_check_grad_ingore_y
(
self
):
def
set_shape
(
self
):
self
.
check_grad_with_place
(
return
(
64
)
self
.
place
,
[
'X'
],
'Out'
,
no_grad_set
=
set
(
'residual'
)
)
class
TestHuberLossOp1
(
TestHuberLossOp
):
def
set_shape
(
self
):
return
(
640
)
def
TestHuberLossOp2
(
TestHuberLossOp
):
class
TestHuberLossOp2
(
TestHuberLossOp
):
def
set_shape
(
self
):
def
set_shape
(
self
):
return
(
6
,
6
)
return
(
10
,
10
)
class
TestHuberLossOp3
(
TestHuberLossOp
):
def
set_shape
(
self
):
return
(
10
,
10
,
1
)
def
TestHuberLossOp3
(
TestHuberLossOp
):
def
set_shape
(
self
):
return
(
6
,
6
,
1
)
support_types
=
get_xpu_op_support_types
(
'huber_loss'
)
for
stype
in
support_types
:
create_test_class
(
globals
(),
XPUTestHuberLossOp
,
stype
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录