Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
f9a4f007
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看板
未验证
提交
f9a4f007
编写于
3月 13, 2023
作者:
W
wenbin
提交者:
GitHub
3月 13, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
squeeze2_op (#51146)
* squeeze2_op * add ut * fix ut * fix static * modity ut
上级
5dfbb229
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
89 addition
and
53 deletion
+89
-53
paddle/fluid/inference/tensorrt/convert/squeeze2_op.cc
paddle/fluid/inference/tensorrt/convert/squeeze2_op.cc
+16
-2
paddle/fluid/inference/tensorrt/op_teller.cc
paddle/fluid/inference/tensorrt/op_teller.cc
+22
-3
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_squeeze2.py
...tests/unittests/ir/inference/test_trt_convert_squeeze2.py
+51
-48
未找到文件。
paddle/fluid/inference/tensorrt/convert/squeeze2_op.cc
浏览文件 @
f9a4f007
...
@@ -32,8 +32,22 @@ class Squeeze2OpConverter : public OpConverter {
...
@@ -32,8 +32,22 @@ class Squeeze2OpConverter : public OpConverter {
auto
output_name
=
op_desc
.
Output
(
"Out"
)[
0
];
auto
output_name
=
op_desc
.
Output
(
"Out"
)[
0
];
// Get Attrs
// Get Attrs
std
::
vector
<
int
>
axes
=
std
::
vector
<
int
>
axes
;
PADDLE_GET_CONST
(
std
::
vector
<
int
>
,
op_desc
.
GetAttr
(
"axes"
));
if
(
op_desc
.
HasAttr
(
"axes"
))
{
axes
=
PADDLE_GET_CONST
(
std
::
vector
<
int
>
,
op_desc
.
GetAttr
(
"axes"
));
}
if
(
axes
.
size
()
==
0
)
{
for
(
int
i
=
0
;
i
<
input_dims
.
nbDims
;
i
++
)
{
if
(
input_dims
.
d
[
i
]
==
-
1
)
{
PADDLE_THROW
(
platform
::
errors
::
InvalidArgument
(
"The necessary attributes of the squeeze2 operator axes is "
"missing."
));
}
else
if
(
input_dims
.
d
[
i
]
==
1
)
{
axes
.
push_back
(
engine_
->
with_dynamic_shape
()
?
i
:
i
+
1
);
}
}
}
PADDLE_ENFORCE_GT
(
PADDLE_ENFORCE_GT
(
axes
.
size
(),
axes
.
size
(),
0
,
0
,
...
...
paddle/fluid/inference/tensorrt/op_teller.cc
浏览文件 @
f9a4f007
...
@@ -996,10 +996,29 @@ struct SimpleOpTypeSetTeller : public Teller {
...
@@ -996,10 +996,29 @@ struct SimpleOpTypeSetTeller : public Teller {
axes
=
PADDLE_GET_CONST
(
std
::
vector
<
int
>
,
desc
.
GetAttr
(
"axes"
));
axes
=
PADDLE_GET_CONST
(
std
::
vector
<
int
>
,
desc
.
GetAttr
(
"axes"
));
}
}
if
(
axes
.
size
()
==
0
)
{
if
(
axes
.
size
()
==
0
)
{
VLOG
(
3
)
<<
"The necessary attributes of the squeeze2 operator axes is "
auto
*
block
=
desc
.
Block
();
if
(
block
)
{
auto
input_var_name
=
desc
.
Input
(
"X"
)[
0
];
auto
*
input_var_desc
=
block
->
FindVar
(
input_var_name
);
const
auto
input_shape
=
input_var_desc
->
GetShape
();
for
(
int
s
:
input_shape
)
{
if
(
s
==
-
1
)
{
VLOG
(
3
)
<<
"The necessary attributes of the squeeze2 operator "
"axes is "
"missing. ss ==== -1"
;
return
false
;
}
else
if
(
s
==
1
)
{
axes
.
push_back
(
s
);
}
}
}
if
(
axes
.
size
()
==
0
)
{
VLOG
(
3
)
<<
"The necessary attributes of the squeeze2 operator axes is "
"missing."
;
"missing."
;
return
false
;
return
false
;
}
}
}
if
(
!
with_dynamic_shape
)
{
if
(
!
with_dynamic_shape
)
{
if
(
std
::
find
(
axes
.
begin
(),
axes
.
end
(),
0
)
!=
axes
.
end
())
{
if
(
std
::
find
(
axes
.
begin
(),
axes
.
end
(),
0
)
!=
axes
.
end
())
{
VLOG
(
3
)
<<
"Invalid squeeze axes. Axes having batch axis is not "
VLOG
(
3
)
<<
"Invalid squeeze axes. Axes having batch axis is not "
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_squeeze2.py
浏览文件 @
f9a4f007
...
@@ -29,7 +29,7 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
...
@@ -29,7 +29,7 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
attrs
=
[
attrs
=
[
program_config
.
ops
[
i
].
attrs
for
i
in
range
(
len
(
program_config
.
ops
))
program_config
.
ops
[
i
].
attrs
for
i
in
range
(
len
(
program_config
.
ops
))
]
]
if
len
(
inputs
[
'in_data'
].
shape
)
<=
max
(
attrs
[
0
][
'axes'
]
):
if
len
(
inputs
[
'in_data'
].
shape
)
<=
max
(
self
.
axes
):
return
False
return
False
return
True
return
True
...
@@ -37,10 +37,13 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
...
@@ -37,10 +37,13 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
for
dims
in
[
2
,
3
,
4
]:
for
dims
in
[
2
,
3
,
4
]:
for
batch
in
[
3
,
4
]:
for
batch
in
[
3
,
4
]:
for
axes
in
[[
2
],
[
2
,
3
],
[
-
1
]]:
for
axes
in
[[
2
],
[
2
,
3
],
[
-
1
]]:
for
attr_axis
in
[
True
,
False
]:
self
.
batch
=
batch
self
.
batch
=
batch
self
.
dims
=
dims
self
.
dims
=
dims
self
.
axes
=
axes
self
.
axes
=
axes
dics
=
[{
"axes"
:
axes
}]
dics
=
[{
"axes"
:
[]}]
if
attr_axis
:
dics
[
0
][
"axes"
]
=
axes
ops_config
=
[
ops_config
=
[
{
{
"op_type"
:
"squeeze2"
,
"op_type"
:
"squeeze2"
,
...
@@ -78,7 +81,9 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
...
@@ -78,7 +81,9 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
weights
=
{},
weights
=
{},
inputs
=
{
inputs
=
{
"in_data"
:
TensorConfig
(
"in_data"
:
TensorConfig
(
data_gen
=
partial
(
generate_input1
,
dics
,
batch
)
data_gen
=
partial
(
generate_input1
,
dics
,
batch
)
)
)
},
},
outputs
=
[
"out_data"
],
outputs
=
[
"out_data"
],
...
@@ -93,8 +98,6 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
...
@@ -93,8 +98,6 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
max_shape
=
list
(
self
.
input_shape
)
max_shape
=
list
(
self
.
input_shape
)
min_shape
=
list
(
self
.
input_shape
)
min_shape
=
list
(
self
.
input_shape
)
opt_shape
=
list
(
self
.
input_shape
)
opt_shape
=
list
(
self
.
input_shape
)
for
i
in
range
(
len
(
self
.
input_shape
)):
max_shape
[
i
]
=
max_shape
[
i
]
+
1
self
.
dynamic_shape
.
min_input_shape
=
{
"in_data"
:
min_shape
}
self
.
dynamic_shape
.
min_input_shape
=
{
"in_data"
:
min_shape
}
self
.
dynamic_shape
.
max_input_shape
=
{
"in_data"
:
max_shape
}
self
.
dynamic_shape
.
max_input_shape
=
{
"in_data"
:
max_shape
}
self
.
dynamic_shape
.
opt_input_shape
=
{
"in_data"
:
opt_shape
}
self
.
dynamic_shape
.
opt_input_shape
=
{
"in_data"
:
opt_shape
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录