Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
da2395f3
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看板
未验证
提交
da2395f3
编写于
7月 21, 2023
作者:
H
HongyuJia
提交者:
GitHub
7月 21, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[0D-Tensor] CINN supports argmin, fix infershape (#55505)
上级
f172b02f
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
88 addition
and
11 deletion
+88
-11
paddle/cinn/hlir/op/contrib/argmin.cc
paddle/cinn/hlir/op/contrib/argmin.cc
+11
-10
test/cinn/ops/test_zero_dim_tensor.py
test/cinn/ops/test_zero_dim_tensor.py
+77
-1
未找到文件。
paddle/cinn/hlir/op/contrib/argmin.cc
浏览文件 @
da2395f3
...
@@ -183,17 +183,22 @@ std::vector<shape_t> InferShapeForArgmin(
...
@@ -183,17 +183,22 @@ std::vector<shape_t> InferShapeForArgmin(
const
framework
::
AttrMapType
&
attrs
)
{
const
framework
::
AttrMapType
&
attrs
)
{
CHECK_EQ
(
inputs_shape
.
size
(),
1UL
);
CHECK_EQ
(
inputs_shape
.
size
(),
1UL
);
auto
ndim
=
inputs_shape
[
0
].
size
();
auto
ndim
=
inputs_shape
[
0
].
size
();
CHECK_GT
(
ndim
,
0
)
<<
"tensor's dim must be more than 0"
;
int
axis
;
int
axis
;
bool
keep_dim
;
bool
keep_dim
;
CHECK
(
attrs
.
find
(
"axis"
)
!=
attrs
.
end
());
CHECK
(
attrs
.
find
(
"axis"
)
!=
attrs
.
end
());
axis
=
absl
::
get
<
int
>
(
attrs
.
at
(
"axis"
));
axis
=
absl
::
get
<
int
>
(
attrs
.
at
(
"axis"
));
if
(
ndim
>
0
)
{
if
(
axis
<
0
)
{
if
(
axis
<
0
)
{
axis
=
static_cast
<
int
>
(
ndim
)
+
axis
;
axis
=
static_cast
<
int
>
(
ndim
)
+
axis
;
}
}
CHECK_LT
(
axis
,
ndim
)
<<
"Axis must be less than tensor's dim"
;
CHECK_LT
(
axis
,
ndim
)
<<
"Axis must be less than tensor's dim"
;
CHECK_GE
(
axis
,
0
)
<<
"Axis must be more than 0"
;
CHECK_GE
(
axis
,
0
)
<<
"Axis must be more than 0"
;
}
else
{
// 0D Tensor
CHECK
(
axis
==
0
||
axis
==
-
1
)
<<
"Axis must be 0 or -1 if input tensor is 0-dim"
;
}
CHECK
(
attrs
.
find
(
"keep_dim"
)
!=
attrs
.
end
());
CHECK
(
attrs
.
find
(
"keep_dim"
)
!=
attrs
.
end
());
keep_dim
=
absl
::
get
<
bool
>
(
attrs
.
at
(
"keep_dim"
));
keep_dim
=
absl
::
get
<
bool
>
(
attrs
.
at
(
"keep_dim"
));
...
@@ -212,11 +217,7 @@ std::vector<shape_t> InferShapeForArgmin(
...
@@ -212,11 +217,7 @@ std::vector<shape_t> InferShapeForArgmin(
if
(
keep_dim
)
{
if
(
keep_dim
)
{
CHECK_EQ
(
ndim
,
out_shapes
.
size
());
CHECK_EQ
(
ndim
,
out_shapes
.
size
());
}
else
{
}
else
{
CHECK_EQ
(
ndim
-
1
,
out_shapes
.
size
());
CHECK
(
ndim
-
1
==
out_shapes
.
size
()
||
ndim
==
0
&&
out_shapes
.
empty
());
}
if
(
out_shapes
.
empty
())
{
out_shapes
.
push_back
(
1
);
}
}
return
{
out_shapes
};
return
{
out_shapes
};
...
...
test/cinn/ops/test_zero_dim_tensor.py
浏览文件 @
da2395f3
...
@@ -698,7 +698,7 @@ class TestArgmaxOp(OpTest):
...
@@ -698,7 +698,7 @@ class TestArgmaxOp(OpTest):
self
.
paddle_outputs
=
[
out
]
self
.
paddle_outputs
=
[
out
]
def
build_cinn_program
(
self
,
target
):
def
build_cinn_program
(
self
,
target
):
builder
=
NetBuilder
(
"
squeeze
_op"
)
builder
=
NetBuilder
(
"
argmax
_op"
)
x
=
builder
.
create_input
(
x
=
builder
.
create_input
(
cinn_dtype_convert
(
self
.
dtype
),
self
.
inputs
[
"x"
].
shape
,
"x"
cinn_dtype_convert
(
self
.
dtype
),
self
.
inputs
[
"x"
].
shape
,
"x"
)
)
...
@@ -750,6 +750,82 @@ class TestArgmaxOp2DKeepDim(TestArgmaxOp):
...
@@ -750,6 +750,82 @@ class TestArgmaxOp2DKeepDim(TestArgmaxOp):
self
.
target_shape
=
(
1
,
5
)
self
.
target_shape
=
(
1
,
5
)
@
OpTestTool
.
skip_if
(
not
is_compiled_with_cuda
(),
"x86 test will be skipped due to timeout."
)
class
TestArgminOp
(
OpTest
):
def
setUp
(
self
):
np
.
random
.
seed
(
2023
)
self
.
dtype
=
"float32"
self
.
init_input
()
def
init_input
(
self
):
self
.
inputs
=
{
"x"
:
np
.
random
.
randint
(
-
10
,
10
,
[]).
astype
(
self
.
dtype
),
}
self
.
param
=
(
0
,)
self
.
target_shape
=
()
def
build_paddle_program
(
self
,
target
):
x
=
paddle
.
to_tensor
(
self
.
inputs
[
"x"
],
stop_gradient
=
False
)
out
=
paddle
.
argmin
(
x
,
*
self
.
param
)
out
=
paddle
.
cast
(
out
,
'int32'
)
self
.
paddle_outputs
=
[
out
]
def
build_cinn_program
(
self
,
target
):
builder
=
NetBuilder
(
"argmin_op"
)
x
=
builder
.
create_input
(
cinn_dtype_convert
(
self
.
dtype
),
self
.
inputs
[
"x"
].
shape
,
"x"
)
out
=
builder
.
argmin
(
x
,
*
self
.
param
)
prog
=
builder
.
build
()
res
=
self
.
get_cinn_output
(
prog
,
target
,
[
x
],
[
self
.
inputs
[
"x"
]],
[
out
])
self
.
cinn_outputs
=
res
self
.
assertEqual
(
res
[
0
].
shape
,
self
.
target_shape
)
def
test_check_results
(
self
):
self
.
check_outputs_and_grads
()
class
TestArgminOp2
(
TestArgminOp
):
def
init_input
(
self
):
self
.
inputs
=
{
"x"
:
np
.
random
.
randint
(
-
10
,
10
,
[]).
astype
(
self
.
dtype
),
}
self
.
param
=
(
-
1
,)
self
.
target_shape
=
()
class
TestArgminOp1D
(
TestArgminOp
):
def
init_input
(
self
):
self
.
inputs
=
{
"x"
:
np
.
random
.
randint
(
-
10
,
10
,
[
5
]).
astype
(
self
.
dtype
),
}
self
.
param
=
(
0
,)
self
.
target_shape
=
()
class
TestArgminOp2D
(
TestArgminOp
):
def
init_input
(
self
):
self
.
inputs
=
{
"x"
:
np
.
random
.
randint
(
-
10
,
10
,
[
3
,
5
]).
astype
(
self
.
dtype
),
}
self
.
param
=
(
0
,)
self
.
target_shape
=
(
5
,)
class
TestArgminOp2DKeepDim
(
TestArgminOp
):
def
init_input
(
self
):
self
.
inputs
=
{
"x"
:
np
.
random
.
randint
(
-
10
,
10
,
[
3
,
5
]).
astype
(
self
.
dtype
),
}
self
.
param
=
(
0
,
True
)
self
.
target_shape
=
(
1
,
5
)
@
OpTestTool
.
skip_if
(
@
OpTestTool
.
skip_if
(
not
is_compiled_with_cuda
(),
"x86 test will be skipped due to timeout."
not
is_compiled_with_cuda
(),
"x86 test will be skipped due to timeout."
)
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录