Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
13992de7
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看板
未验证
提交
13992de7
编写于
1月 10, 2023
作者:
S
Sanbu
提交者:
GitHub
1月 10, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add reduce_min prod trt converter (#49615)
上级
acab7daf
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
54 addition
and
28 deletion
+54
-28
paddle/fluid/inference/api/analysis_predictor.cc
paddle/fluid/inference/api/analysis_predictor.cc
+2
-0
paddle/fluid/inference/tensorrt/convert/reduce_op.cc
paddle/fluid/inference/tensorrt/convert/reduce_op.cc
+15
-1
paddle/fluid/inference/tensorrt/op_teller.cc
paddle/fluid/inference/tensorrt/op_teller.cc
+2
-1
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_reduce.py
...d/tests/unittests/ir/inference/test_trt_convert_reduce.py
+35
-26
未找到文件。
paddle/fluid/inference/api/analysis_predictor.cc
浏览文件 @
13992de7
...
@@ -2350,7 +2350,9 @@ USE_TRT_CONVERTER(reshape2);
...
@@ -2350,7 +2350,9 @@ USE_TRT_CONVERTER(reshape2);
USE_TRT_CONVERTER
(
gather_nd
);
USE_TRT_CONVERTER
(
gather_nd
);
USE_TRT_CONVERTER
(
reduce_mean
);
USE_TRT_CONVERTER
(
reduce_mean
);
USE_TRT_CONVERTER
(
reduce_max
);
USE_TRT_CONVERTER
(
reduce_max
);
USE_TRT_CONVERTER
(
reduce_min
);
USE_TRT_CONVERTER
(
reduce_sum
);
USE_TRT_CONVERTER
(
reduce_sum
);
USE_TRT_CONVERTER
(
reduce_prod
);
USE_TRT_CONVERTER
(
tile
);
USE_TRT_CONVERTER
(
tile
);
USE_TRT_CONVERTER
(
conv3d
);
USE_TRT_CONVERTER
(
conv3d
);
USE_TRT_CONVERTER
(
conv3d_transpose
);
USE_TRT_CONVERTER
(
conv3d_transpose
);
...
...
paddle/fluid/inference/tensorrt/convert/reduce_op.cc
浏览文件 @
13992de7
...
@@ -43,7 +43,6 @@ class ReduceOpConverter : public OpConverter {
...
@@ -43,7 +43,6 @@ class ReduceOpConverter : public OpConverter {
VLOG
(
4
)
<<
"convert a paddle "
<<
op_type
<<
" op to tensorrt reduce layer"
;
VLOG
(
4
)
<<
"convert a paddle "
<<
op_type
<<
" op to tensorrt reduce layer"
;
framework
::
OpDesc
op_desc
(
op
,
nullptr
);
framework
::
OpDesc
op_desc
(
op
,
nullptr
);
auto
reduce_type
=
ops_
.
find
(
op_type
);
auto
reduce_type
=
ops_
.
find
(
op_type
);
auto
*
x
=
engine_
->
GetITensor
(
op_desc
.
Input
(
"X"
).
front
());
auto
*
x
=
engine_
->
GetITensor
(
op_desc
.
Input
(
"X"
).
front
());
nvinfer1
::
Dims
input_shape
=
x
->
getDimensions
();
nvinfer1
::
Dims
input_shape
=
x
->
getDimensions
();
int
input_dims
=
input_shape
.
nbDims
;
int
input_dims
=
input_shape
.
nbDims
;
...
@@ -104,6 +103,8 @@ const std::unordered_map<std::string, std::vector<nvinfer1::ReduceOperation>>
...
@@ -104,6 +103,8 @@ const std::unordered_map<std::string, std::vector<nvinfer1::ReduceOperation>>
{
"reduce_mean"
,
{
nvinfer1
::
ReduceOperation
::
kAVG
}},
{
"reduce_mean"
,
{
nvinfer1
::
ReduceOperation
::
kAVG
}},
{
"reduce_sum"
,
{
nvinfer1
::
ReduceOperation
::
kSUM
}},
{
"reduce_sum"
,
{
nvinfer1
::
ReduceOperation
::
kSUM
}},
{
"reduce_max"
,
{
nvinfer1
::
ReduceOperation
::
kMAX
}},
{
"reduce_max"
,
{
nvinfer1
::
ReduceOperation
::
kMAX
}},
{
"reduce_min"
,
{
nvinfer1
::
ReduceOperation
::
kMIN
}},
{
"reduce_prod"
,
{
nvinfer1
::
ReduceOperation
::
kPROD
}},
};
};
class
ReduceSumOpConverter
:
public
ReduceOpConverter
{
class
ReduceSumOpConverter
:
public
ReduceOpConverter
{
...
@@ -120,6 +121,17 @@ class ReduceMaxOpConverter : public ReduceOpConverter {
...
@@ -120,6 +121,17 @@ class ReduceMaxOpConverter : public ReduceOpConverter {
public:
public:
ReduceMaxOpConverter
()
{
op_type
=
"reduce_max"
;
}
ReduceMaxOpConverter
()
{
op_type
=
"reduce_max"
;
}
};
};
class
ReduceMinOpConverter
:
public
ReduceOpConverter
{
public:
ReduceMinOpConverter
()
{
op_type
=
"reduce_min"
;
}
};
class
ReduceProdOpConverter
:
public
ReduceOpConverter
{
public:
ReduceProdOpConverter
()
{
op_type
=
"reduce_prod"
;
}
};
}
// namespace tensorrt
}
// namespace tensorrt
}
// namespace inference
}
// namespace inference
}
// namespace paddle
}
// namespace paddle
...
@@ -127,3 +139,5 @@ class ReduceMaxOpConverter : public ReduceOpConverter {
...
@@ -127,3 +139,5 @@ class ReduceMaxOpConverter : public ReduceOpConverter {
REGISTER_TRT_OP_CONVERTER
(
reduce_sum
,
ReduceSumOpConverter
);
REGISTER_TRT_OP_CONVERTER
(
reduce_sum
,
ReduceSumOpConverter
);
REGISTER_TRT_OP_CONVERTER
(
reduce_mean
,
ReduceMeanOpConverter
);
REGISTER_TRT_OP_CONVERTER
(
reduce_mean
,
ReduceMeanOpConverter
);
REGISTER_TRT_OP_CONVERTER
(
reduce_max
,
ReduceMaxOpConverter
);
REGISTER_TRT_OP_CONVERTER
(
reduce_max
,
ReduceMaxOpConverter
);
REGISTER_TRT_OP_CONVERTER
(
reduce_min
,
ReduceMinOpConverter
);
REGISTER_TRT_OP_CONVERTER
(
reduce_prod
,
ReduceProdOpConverter
);
paddle/fluid/inference/tensorrt/op_teller.cc
浏览文件 @
13992de7
...
@@ -2088,7 +2088,8 @@ struct SimpleOpTypeSetTeller : public Teller {
...
@@ -2088,7 +2088,8 @@ struct SimpleOpTypeSetTeller : public Teller {
}
}
if
(
op_type
==
"reduce_sum"
||
op_type
==
"reduce_mean"
||
if
(
op_type
==
"reduce_sum"
||
op_type
==
"reduce_mean"
||
op_type
==
"reduce_max"
)
{
op_type
==
"reduce_max"
||
op_type
==
"reduce_min"
||
op_type
==
"reduce_prod"
)
{
if
(
!
desc
.
HasAttr
(
"dim"
,
/*with_attr_var=*/
false
))
{
if
(
!
desc
.
HasAttr
(
"dim"
,
/*with_attr_var=*/
false
))
{
VLOG
(
3
)
<<
"Skip to convert into TRT while found Attribute('dim') is "
VLOG
(
3
)
<<
"Skip to convert into TRT while found Attribute('dim') is "
"Variable type in "
"Variable type in "
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_reduce.py
浏览文件 @
13992de7
...
@@ -68,10 +68,12 @@ class TrtConvertReduceTest(TrtLayerAutoScanTest):
...
@@ -68,10 +68,12 @@ class TrtConvertReduceTest(TrtLayerAutoScanTest):
for
out_dtype
in
[
-
1
,
2
,
5
]:
for
out_dtype
in
[
-
1
,
2
,
5
]:
for
op_type
in
[
for
op_type
in
[
"reduce_max"
,
"reduce_max"
,
"reduce_min"
,
"reduce_mean"
,
"reduce_mean"
,
"reduce_sum"
,
"reduce_sum"
,
"reduce_prod"
,
]:
]:
dics
=
[
dics
1
=
[
{
{
"keep_dim"
:
keep_dim
,
"keep_dim"
:
keep_dim
,
"dim"
:
dim
,
"dim"
:
dim
,
...
@@ -81,36 +83,43 @@ class TrtConvertReduceTest(TrtLayerAutoScanTest):
...
@@ -81,36 +83,43 @@ class TrtConvertReduceTest(TrtLayerAutoScanTest):
},
},
{},
{},
]
]
dics2
=
[
ops_config
=
[
{
{
"op_type"
:
op_type
,
"out_dtype"
:
out_dtype
,
"op_inputs"
:
{
"X"
:
[
"input_data"
]},
"in_dtype"
:
out_dtype
,
"op_outputs"
:
{
},
"Out"
:
[
"reduce_output_data"
]
{},
},
"op_attrs"
:
dics
[
0
],
}
]
]
ops
=
self
.
generate_op_config
(
ops_config
)
for
dics
in
[
dics1
,
dics2
]:
ops_config
=
[
program_config
=
ProgramConfig
(
{
ops
=
ops
,
"op_type"
:
op_type
,
weights
=
{},
"op_inputs"
:
{
"X"
:
[
"input_data"
]},
inputs
=
{
"op_outputs"
:
{
"input_data"
:
TensorConfig
(
"Out"
:
[
"reduce_output_data"
]
data_gen
=
partial
(
},
generate_input1
,
out_dtype
,
dics
"op_attrs"
:
dics
[
0
],
}
]
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
ops
=
ops
,
weights
=
{},
inputs
=
{
"input_data"
:
TensorConfig
(
data_gen
=
partial
(
generate_input1
,
out_dtype
,
dics
)
)
)
)
},
},
outputs
=
[
"reduce_output_data"
],
outputs
=
[
"reduce_output_data"
],
)
)
if
not
self
.
is_program_valid
(
program_config
):
if
not
self
.
is_program_valid
(
program_config
):
continue
continue
yield
program_config
yield
program_config
def
sample_predictor_configs
(
def
sample_predictor_configs
(
self
,
program_config
self
,
program_config
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录