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 {
auto
output_name
=
op_desc
.
Output
(
"Out"
)[
0
];
// Get Attrs
std
::
vector
<
int
>
axes
=
PADDLE_GET_CONST
(
std
::
vector
<
int
>
,
op_desc
.
GetAttr
(
"axes"
));
std
::
vector
<
int
>
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
(
axes
.
size
(),
0
,
...
...
paddle/fluid/inference/tensorrt/op_teller.cc
浏览文件 @
f9a4f007
...
...
@@ -996,9 +996,28 @@ struct SimpleOpTypeSetTeller : public Teller {
axes
=
PADDLE_GET_CONST
(
std
::
vector
<
int
>
,
desc
.
GetAttr
(
"axes"
));
}
if
(
axes
.
size
()
==
0
)
{
VLOG
(
3
)
<<
"The necessary attributes of the squeeze2 operator axes is "
"missing."
;
return
false
;
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."
;
return
false
;
}
}
if
(
!
with_dynamic_shape
)
{
if
(
std
::
find
(
axes
.
begin
(),
axes
.
end
(),
0
)
!=
axes
.
end
())
{
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_squeeze2.py
浏览文件 @
f9a4f007
...
...
@@ -29,7 +29,7 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
attrs
=
[
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
True
...
...
@@ -37,54 +37,59 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
for
dims
in
[
2
,
3
,
4
]:
for
batch
in
[
3
,
4
]:
for
axes
in
[[
2
],
[
2
,
3
],
[
-
1
]]:
self
.
batch
=
batch
self
.
dims
=
dims
self
.
axes
=
axes
dics
=
[{
"axes"
:
axes
}]
ops_config
=
[
{
"op_type"
:
"squeeze2"
,
"op_inputs"
:
{
"X"
:
[
"in_data"
]},
"op_outputs"
:
{
"Out"
:
[
"out_data"
],
"XShape"
:
[
"XShape_data"
],
for
attr_axis
in
[
True
,
False
]:
self
.
batch
=
batch
self
.
dims
=
dims
self
.
axes
=
axes
dics
=
[{
"axes"
:
[]}]
if
attr_axis
:
dics
[
0
][
"axes"
]
=
axes
ops_config
=
[
{
"op_type"
:
"squeeze2"
,
"op_inputs"
:
{
"X"
:
[
"in_data"
]},
"op_outputs"
:
{
"Out"
:
[
"out_data"
],
"XShape"
:
[
"XShape_data"
],
},
"op_attrs"
:
dics
[
0
],
}
]
# new_axes is the update of axes
new_axes
=
list
(
axes
)
for
i
in
range
(
len
(
new_axes
)):
if
new_axes
[
i
]
<
0
:
new_axes
[
i
]
+=
dims
if
max
(
new_axes
)
>=
dims
:
continue
# generate input data
self
.
input_shape
=
[
1
]
*
dims
for
i
in
range
(
dims
):
self
.
input_shape
[
i
]
=
np
.
random
.
randint
(
1
,
20
)
def
generate_input1
(
attrs
:
List
[
Dict
[
str
,
Any
]],
batch
):
self
.
input_shape
[
0
]
=
batch
for
i
in
new_axes
:
self
.
input_shape
[
i
]
=
1
return
np
.
random
.
random
(
self
.
input_shape
).
astype
(
np
.
float32
)
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
ops
=
ops
,
weights
=
{},
inputs
=
{
"in_data"
:
TensorConfig
(
data_gen
=
partial
(
generate_input1
,
dics
,
batch
)
)
},
"op_attrs"
:
dics
[
0
],
}
]
# new_axes is the update of axes
new_axes
=
list
(
axes
)
for
i
in
range
(
len
(
new_axes
)):
if
new_axes
[
i
]
<
0
:
new_axes
[
i
]
+=
dims
if
max
(
new_axes
)
>=
dims
:
continue
# generate input data
self
.
input_shape
=
[
1
]
*
dims
for
i
in
range
(
dims
):
self
.
input_shape
[
i
]
=
np
.
random
.
randint
(
1
,
20
)
def
generate_input1
(
attrs
:
List
[
Dict
[
str
,
Any
]],
batch
):
self
.
input_shape
[
0
]
=
batch
for
i
in
new_axes
:
self
.
input_shape
[
i
]
=
1
return
np
.
random
.
random
(
self
.
input_shape
).
astype
(
np
.
float32
outputs
=
[
"out_data"
],
)
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
ops
=
ops
,
weights
=
{},
inputs
=
{
"in_data"
:
TensorConfig
(
data_gen
=
partial
(
generate_input1
,
dics
,
batch
)
)
},
outputs
=
[
"out_data"
],
)
yield
program_config
yield
program_config
def
sample_predictor_configs
(
self
,
program_config
...
...
@@ -93,8 +98,6 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
max_shape
=
list
(
self
.
input_shape
)
min_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
.
max_input_shape
=
{
"in_data"
:
max_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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录