Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
934d25e7
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
未验证
提交
934d25e7
编写于
6月 06, 2023
作者:
zhouweiwei2014
提交者:
GitHub
6月 06, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix XPU unittest problem for shape check (#54365)
上级
9fb2c603
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
27 addition
and
26 deletion
+27
-26
python/paddle/tensor/__init__.py
python/paddle/tensor/__init__.py
+1
-0
test/xpu/test_accuracy_op_xpu.py
test/xpu/test_accuracy_op_xpu.py
+3
-5
test/xpu/test_expand_as_v2_op_xpu.py
test/xpu/test_expand_as_v2_op_xpu.py
+7
-7
test/xpu/test_gather_nd_op_xpu.py
test/xpu/test_gather_nd_op_xpu.py
+2
-2
test/xpu/test_nll_loss_op_xpu.py
test/xpu/test_nll_loss_op_xpu.py
+6
-6
test/xpu/test_reduce_any_op_xpu.py
test/xpu/test_reduce_any_op_xpu.py
+3
-3
test/xpu/test_size_op_xpu.py
test/xpu/test_size_op_xpu.py
+1
-1
test/xpu/test_unbind_op_xpu.py
test/xpu/test_unbind_op_xpu.py
+3
-1
test/xpu/test_where_index_xpu.py
test/xpu/test_where_index_xpu.py
+1
-1
未找到文件。
python/paddle/tensor/__init__.py
浏览文件 @
934d25e7
...
...
@@ -348,6 +348,7 @@ tensor_method_func = [ # noqa
'logit'
,
'exp'
,
'exp_'
,
'expm1'
,
'floor'
,
'floor_'
,
'increment'
,
...
...
test/xpu/test_accuracy_op_xpu.py
浏览文件 @
934d25e7
...
...
@@ -48,11 +48,9 @@ class XPUTestAccuracyOp(XPUOpTestWrapper):
num_correct
+=
1
break
self
.
outputs
=
{
'Accuracy'
:
np
.
array
([
num_correct
/
float
(
n
)]).
astype
(
self
.
dtype
),
'Correct'
:
np
.
array
([
num_correct
]).
astype
(
"int32"
),
'Total'
:
np
.
array
([
n
]).
astype
(
"int32"
),
'Accuracy'
:
np
.
array
(
num_correct
/
float
(
n
)).
astype
(
self
.
dtype
),
'Correct'
:
np
.
array
(
num_correct
).
astype
(
"int32"
),
'Total'
:
np
.
array
(
n
).
astype
(
"int32"
),
}
self
.
attrs
=
{
'use_xpu'
:
True
}
...
...
test/xpu/test_expand_as_v2_op_xpu.py
浏览文件 @
934d25e7
...
...
@@ -93,7 +93,7 @@ class XPUTestExpandAsV2Op(XPUOpTestWrapper):
def
set_inputs
(
self
):
x
=
np
.
random
.
rand
(
1
,
1
,
7
,
16
).
astype
(
self
.
dtype
)
self
.
inputs
=
{
'X'
:
x
}
target_tensor
=
np
.
random
.
rand
(
1
,
1
,
7
,
16
).
astype
(
self
.
dtype
)
target_tensor
=
np
.
random
.
rand
(
4
,
6
,
7
,
16
).
astype
(
self
.
dtype
)
self
.
attrs
=
{
'target_shape'
:
target_tensor
.
shape
}
def
set_output
(
self
):
...
...
@@ -105,7 +105,7 @@ class XPUTestExpandAsV2Op(XPUOpTestWrapper):
def
set_inputs
(
self
):
x
=
np
.
random
.
rand
(
1
,
1
,
7
,
16
,
1
).
astype
(
self
.
dtype
)
self
.
inputs
=
{
'X'
:
x
}
target_tensor
=
np
.
random
.
rand
(
1
,
1
,
7
,
16
,
1
).
astype
(
self
.
dtype
)
target_tensor
=
np
.
random
.
rand
(
4
,
6
,
7
,
16
,
1
).
astype
(
self
.
dtype
)
self
.
attrs
=
{
'target_shape'
:
target_tensor
.
shape
}
def
set_output
(
self
):
...
...
@@ -117,7 +117,7 @@ class XPUTestExpandAsV2Op(XPUOpTestWrapper):
def
set_inputs
(
self
):
x
=
np
.
random
.
rand
(
1
,
1
,
7
,
16
,
1
,
1
).
astype
(
self
.
dtype
)
self
.
inputs
=
{
'X'
:
x
}
target_tensor
=
np
.
random
.
rand
(
1
,
1
,
7
,
16
,
1
,
1
).
astype
(
self
.
dtype
)
target_tensor
=
np
.
random
.
rand
(
4
,
6
,
7
,
16
,
1
,
1
).
astype
(
self
.
dtype
)
self
.
attrs
=
{
'target_shape'
:
target_tensor
.
shape
}
def
set_output
(
self
):
...
...
@@ -129,8 +129,8 @@ class XPUTestExpandAsV2Op(XPUOpTestWrapper):
# Test python API
class
TestExpandAsV2API
(
unittest
.
TestCase
):
def
test_api
(
self
):
input1
=
np
.
random
.
random
([
12
,
14
]).
astype
(
"float32"
)
input2
=
np
.
random
.
random
([
2
,
12
,
14
]).
astype
(
"float32"
)
x_np
=
np
.
random
.
random
([
12
,
14
]).
astype
(
"float32"
)
y_np
=
np
.
random
.
random
([
2
,
12
,
14
]).
astype
(
"float32"
)
x
=
paddle
.
static
.
data
(
name
=
'x'
,
shape
=
[
12
,
14
],
dtype
=
"float32"
)
y
=
paddle
.
static
.
data
(
...
...
@@ -144,10 +144,10 @@ class TestExpandAsV2API(unittest.TestCase):
exe
=
fluid
.
Executor
(
place
=
fluid
.
XPUPlace
(
0
))
res_1
=
exe
.
run
(
fluid
.
default_main_program
(),
feed
=
{
"x"
:
input1
,
"target_tensor"
:
input2
},
feed
=
{
"x"
:
x_np
,
"target_tensor"
:
y_np
},
fetch_list
=
[
out_1
],
)
assert
np
.
array_equal
(
res_1
[
0
],
np
.
tile
(
input1
,
(
2
,
1
,
1
)))
assert
np
.
array_equal
(
res_1
[
0
],
np
.
tile
(
x_np
,
(
2
,
1
,
1
)))
support_types
=
get_xpu_op_support_types
(
'expand_as_v2'
)
...
...
test/xpu/test_gather_nd_op_xpu.py
浏览文件 @
934d25e7
...
...
@@ -81,13 +81,13 @@ class XPUTestGatherNd(XPUOpTestWrapper):
def
init_data
(
self
):
self
.
xnp
=
np
.
random
.
random
((
5
,
20
)).
astype
(
self
.
in_type
)
self
.
inp
=
np
.
array
([
1
]).
astype
(
"int32"
)
self
.
output
=
self
.
xnp
[
self
.
inp
]
self
.
output
=
self
.
xnp
[
tuple
(
self
.
inp
)
]
class
XPUTestGatherNdOpWithIndex2
(
XPUTestGatherNdBase
):
def
init_data
(
self
):
self
.
xnp
=
np
.
random
.
random
((
5
,
20
)).
astype
(
self
.
in_type
)
self
.
inp
=
np
.
array
([
1
]).
astype
(
"int64"
)
self
.
output
=
self
.
xnp
[
self
.
inp
]
self
.
output
=
self
.
xnp
[
tuple
(
self
.
inp
)
]
class
XPUTestGatherNdOpWithLowIndex1
(
XPUTestGatherNdBase
):
def
init_data
(
self
):
...
...
test/xpu/test_nll_loss_op_xpu.py
浏览文件 @
934d25e7
...
...
@@ -45,16 +45,16 @@ def nll_loss_1d(
out
[
i
]
=
-
logs
[
i
][
cur_target
]
*
cur_weight
if
reduction
==
'sum'
:
out
=
np
.
sum
(
out
)
total_weight
=
np
.
array
(
[
total_weight
]
).
astype
(
dtype
)
total_weight
=
np
.
array
(
total_weight
).
astype
(
dtype
)
return
{
'Out'
:
out
,
'Total_weight'
:
total_weight
}
elif
reduction
==
'mean'
:
out
=
np
.
sum
(
out
)
if
total_weight
!=
0
:
out
/=
total_weight
total_weight
=
np
.
array
(
[
total_weight
]
).
astype
(
dtype
)
total_weight
=
np
.
array
(
total_weight
).
astype
(
dtype
)
return
{
'Out'
:
out
,
'Total_weight'
:
total_weight
}
elif
reduction
==
'none'
:
total_weight
=
np
.
array
(
[
0
]
).
astype
(
dtype
)
total_weight
=
np
.
array
(
0
).
astype
(
dtype
)
return
{
'Out'
:
out
,
'Total_weight'
:
total_weight
}
...
...
@@ -79,16 +79,16 @@ def nll_loss_2d(
out
[
i
][
h
][
w
]
=
-
logs
[
i
][
cur_target
][
h
][
w
]
*
cur_weight
if
reduction
==
'sum'
:
out
=
np
.
sum
(
out
)
total_weight
=
np
.
array
(
[
total_weight
]
).
astype
(
dtype
)
total_weight
=
np
.
array
(
total_weight
).
astype
(
dtype
)
return
{
'Out'
:
out
,
'Total_weight'
:
total_weight
}
elif
reduction
==
'mean'
:
out
=
np
.
sum
(
out
)
if
total_weight
!=
0
:
out
/=
total_weight
total_weight
=
np
.
array
(
[
total_weight
]
).
astype
(
dtype
)
total_weight
=
np
.
array
(
total_weight
).
astype
(
dtype
)
return
{
'Out'
:
out
,
'Total_weight'
:
total_weight
}
elif
reduction
==
'none'
:
total_weight
=
np
.
array
(
[
0
]
).
astype
(
dtype
)
total_weight
=
np
.
array
(
0
).
astype
(
dtype
)
return
{
'Out'
:
out
,
'Total_weight'
:
total_weight
}
...
...
test/xpu/test_reduce_any_op_xpu.py
浏览文件 @
934d25e7
...
...
@@ -40,8 +40,8 @@ class XPUTestReduceAnyOp(XPUOpTestWrapper):
self
.
op_type
=
'reduce_any'
self
.
attrs
=
{
'use_xpu'
:
True
,
'reduce_all'
:
Tru
e
,
'keep_dim'
:
Tru
e
,
'reduce_all'
:
Fals
e
,
'keep_dim'
:
Fals
e
,
'dim'
:
(
3
,
5
,
4
),
}
self
.
inputs
=
{
...
...
@@ -76,7 +76,7 @@ class XPUTestReduceAnyOp(XPUOpTestWrapper):
self
.
op_type
=
'reduce_any'
self
.
attrs
=
{
'use_xpu'
:
True
,
'reduce_all'
:
Tru
e
,
'reduce_all'
:
Fals
e
,
'keep_dim'
:
False
,
'dim'
:
(
3
,
6
),
}
...
...
test/xpu/test_size_op_xpu.py
浏览文件 @
934d25e7
...
...
@@ -43,7 +43,7 @@ class XPUTestSizeOP(XPUOpTestWrapper):
self
.
inputs
=
{
'Input'
:
x
,
}
self
.
outputs
=
{
'Out'
:
np
.
array
(
[
np
.
size
(
x
)]
)}
self
.
outputs
=
{
'Out'
:
np
.
array
(
np
.
size
(
x
)
)}
def
initTestCase
(
self
):
self
.
shape
=
(
6
,
56
,
8
,
55
)
...
...
test/xpu/test_unbind_op_xpu.py
浏览文件 @
934d25e7
...
...
@@ -97,7 +97,9 @@ class XPUTestUnbindOP(XPUOpTestWrapper):
pass
def
outReshape
(
self
):
pass
self
.
out
[
0
]
=
self
.
out
[
0
].
reshape
((
2
,
2
))
self
.
out
[
1
]
=
self
.
out
[
1
].
reshape
((
2
,
2
))
self
.
out
[
2
]
=
self
.
out
[
2
].
reshape
((
2
,
2
))
def
setAxis
(
self
):
pass
...
...
test/xpu/test_where_index_xpu.py
浏览文件 @
934d25e7
...
...
@@ -58,7 +58,7 @@ class XPUTestWhereIndexOp(XPUOpTestWrapper):
self
.
inputs
=
{
'Condition'
:
np
.
array
([
False
,
False
,
False
]).
astype
(
self
.
dtype
),
}
self
.
outputs
=
{
'Out'
:
np
.
array
([],
dtype
=
'int64'
)}
self
.
outputs
=
{
'Out'
:
np
.
array
([],
dtype
=
'int64'
)
.
reshape
(
0
,
1
)
}
class
TestRank2
(
TestWhereIndexOp
):
def
init_data
(
self
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录