Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
b4b78060
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2305
Star
20932
Fork
5423
代码
文件
提交
分支
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看板
未验证
提交
b4b78060
编写于
11月 16, 2022
作者:
W
wenbin
提交者:
GitHub
11月 16, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
elementwise_floordiv (#47944)
* elementwise_op * add teller * modify ut * comments * modify ut * return * modify
上级
a2a97cbb
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
121 addition
and
36 deletion
+121
-36
paddle/fluid/inference/api/analysis_predictor.cc
paddle/fluid/inference/api/analysis_predictor.cc
+2
-0
paddle/fluid/inference/tensorrt/convert/elementwise_op.cc
paddle/fluid/inference/tensorrt/convert/elementwise_op.cc
+11
-0
paddle/fluid/inference/tensorrt/op_teller.cc
paddle/fluid/inference/tensorrt/op_teller.cc
+3
-1
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_elementwise.py
...ts/unittests/ir/inference/test_trt_convert_elementwise.py
+105
-35
未找到文件。
paddle/fluid/inference/api/analysis_predictor.cc
浏览文件 @
b4b78060
...
...
@@ -2227,6 +2227,7 @@ USE_TRT_CONVERTER(elementwise_div_weight);
USE_TRT_CONVERTER
(
elementwise_min_weight
);
USE_TRT_CONVERTER
(
elementwise_max_weight
);
USE_TRT_CONVERTER
(
elementwise_pow_weight
);
USE_TRT_CONVERTER
(
elementwise_floordiv_weight
);
USE_TRT_CONVERTER
(
elementwise_add_tensor
);
USE_TRT_CONVERTER
(
elementwise_sub_tensor
);
USE_TRT_CONVERTER
(
elementwise_div_tensor
);
...
...
@@ -2234,6 +2235,7 @@ USE_TRT_CONVERTER(elementwise_mul_tensor);
USE_TRT_CONVERTER
(
elementwise_max_tensor
);
USE_TRT_CONVERTER
(
elementwise_min_tensor
);
USE_TRT_CONVERTER
(
elementwise_pow_tensor
);
USE_TRT_CONVERTER
(
elementwise_floordiv_tensor
);
USE_TRT_CONVERTER
(
transpose
);
USE_TRT_CONVERTER
(
transpose2
);
USE_TRT_CONVERTER
(
flatten
);
...
...
paddle/fluid/inference/tensorrt/convert/elementwise_op.cc
浏览文件 @
b4b78060
...
...
@@ -167,6 +167,7 @@ const std::unordered_map<std::string, nvinfer1::ElementWiseOperation>
{
"min"
,
nvinfer1
::
ElementWiseOperation
::
kMIN
},
{
"pow"
,
nvinfer1
::
ElementWiseOperation
::
kPOW
},
{
"max"
,
nvinfer1
::
ElementWiseOperation
::
kMAX
},
{
"floordiv"
,
nvinfer1
::
ElementWiseOperation
::
kFLOOR_DIV
},
};
class
ElementwiseTensorAddOpConverter
:
public
ElementwiseTensorOpConverter
{
...
...
@@ -204,6 +205,12 @@ class ElementwiseTensorPowOpConverter : public ElementwiseTensorOpConverter {
ElementwiseTensorPowOpConverter
()
{
op_type_
=
"pow"
;
}
};
class
ElementwiseTensorFloorDivOpConverter
:
public
ElementwiseTensorOpConverter
{
public:
ElementwiseTensorFloorDivOpConverter
()
{
op_type_
=
"floordiv"
;
}
};
}
// namespace tensorrt
}
// namespace inference
}
// namespace paddle
...
...
@@ -222,6 +229,8 @@ REGISTER_TRT_OP_CONVERTER(elementwise_min_weight,
ElementwiseTensorMinOpConverter
);
REGISTER_TRT_OP_CONVERTER
(
elementwise_pow_weight
,
ElementwiseTensorPowOpConverter
);
REGISTER_TRT_OP_CONVERTER
(
elementwise_floordiv_weight
,
ElementwiseTensorFloorDivOpConverter
);
REGISTER_TRT_OP_CONVERTER
(
elementwise_add_tensor
,
ElementwiseTensorAddOpConverter
);
...
...
@@ -237,3 +246,5 @@ REGISTER_TRT_OP_CONVERTER(elementwise_min_tensor,
ElementwiseTensorMinOpConverter
);
REGISTER_TRT_OP_CONVERTER
(
elementwise_pow_tensor
,
ElementwiseTensorPowOpConverter
);
REGISTER_TRT_OP_CONVERTER
(
elementwise_floordiv_tensor
,
ElementwiseTensorFloorDivOpConverter
);
paddle/fluid/inference/tensorrt/op_teller.cc
浏览文件 @
b4b78060
...
...
@@ -1244,7 +1244,7 @@ struct SimpleOpTypeSetTeller : public Teller {
if
(
op_type
==
"elementwise_add"
||
op_type
==
"elementwise_mul"
||
op_type
==
"elementwise_sub"
||
op_type
==
"elementwise_div"
||
op_type
==
"elementwise_pow"
||
op_type
==
"elementwise_min"
||
op_type
==
"elementwise_max"
)
{
op_type
==
"elementwise_max"
||
op_type
==
"elementwise_floordiv"
)
{
if
(
desc
.
Input
(
"X"
).
size
()
!=
1
)
{
VLOG
(
3
)
<<
"The input op's Input(
\"
X
\"
).size() "
"should equal to 1, but received Input(
\"
X
\"
).size() = "
...
...
@@ -2288,6 +2288,7 @@ struct SimpleOpTypeSetTeller : public Teller {
"elementwise_pow"
,
"elementwise_min"
,
"elementwise_max"
,
"elementwise_floordiv"
,
"equal"
,
"dropout"
,
"prelu"
,
...
...
@@ -2413,6 +2414,7 @@ struct SimpleOpTypeSetTeller : public Teller {
"elementwise_pow"
,
"elementwise_min"
,
"elementwise_max"
,
"elementwise_floordiv"
,
"equal"
,
"dropout"
,
"prelu"
,
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_elementwise.py
浏览文件 @
b4b78060
...
...
@@ -28,11 +28,22 @@ class TrtConvertElementwiseTest_one_input_special_case0(TrtLayerAutoScanTest):
return
True
def
sample_program_configs
(
self
):
def
generate_input
(
shape
):
return
np
.
random
.
random
(
shape
).
astype
(
np
.
float32
)
def
generate_weight
():
return
np
.
random
.
randn
(
1
,
32
,
1
,
1
).
astype
(
np
.
float32
)
def
generate_input
(
shape
,
op_type
):
# elementwise_floordiv is integer only
if
op_type
==
"elementwise_floordiv"
:
return
np
.
random
.
randint
(
low
=
1
,
high
=
10000
,
size
=
shape
,
dtype
=
np
.
int32
)
else
:
return
np
.
random
.
random
(
shape
).
astype
(
np
.
float32
)
def
generate_weight
(
op_type
):
if
op_type
==
"elementwise_floordiv"
:
return
np
.
random
.
randint
(
low
=
1
,
high
=
10000
,
size
=
[
1
,
32
,
1
,
1
],
dtype
=
np
.
int32
)
else
:
return
np
.
random
.
randn
(
1
,
32
,
1
,
1
).
astype
(
np
.
float32
)
for
batch
in
[
1
,
4
]:
for
shape
in
[[
batch
,
32
,
16
,
32
]]:
...
...
@@ -44,6 +55,7 @@ class TrtConvertElementwiseTest_one_input_special_case0(TrtLayerAutoScanTest):
"elementwise_pow"
,
"elementwise_min"
,
"elementwise_max"
,
"elementwise_floordiv"
,
]:
for
axis
in
[
-
1
]:
self
.
dims
=
len
(
shape
)
...
...
@@ -65,12 +77,14 @@ class TrtConvertElementwiseTest_one_input_special_case0(TrtLayerAutoScanTest):
ops
=
ops
,
weights
=
{
"weight"
:
TensorConfig
(
data_gen
=
partial
(
generate_weight
)
data_gen
=
partial
(
generate_weight
,
op_type
)
)
},
inputs
=
{
"input_data"
:
TensorConfig
(
data_gen
=
partial
(
generate_input
,
shape
)
data_gen
=
partial
(
generate_input
,
shape
,
op_type
)
),
},
outputs
=
[
"output_data"
],
...
...
@@ -142,11 +156,23 @@ class TrtConvertElementwiseTest_one_input_special_case1(TrtLayerAutoScanTest):
return
True
def
sample_program_configs
(
self
):
def
generate_input
(
shape
):
return
np
.
random
.
random
(
shape
).
astype
(
np
.
float32
)
def
generate_weight
():
return
np
.
random
.
randn
(
1
).
astype
(
np
.
float32
)
def
generate_input
(
shape
,
op_type
):
# elementwise_floordiv is integer only
if
op_type
==
"elementwise_floordiv"
:
return
np
.
random
.
randint
(
low
=
1
,
high
=
10000
,
size
=
shape
,
dtype
=
np
.
int32
)
else
:
return
np
.
random
.
random
(
shape
).
astype
(
np
.
float32
)
def
generate_weight
(
op_type
):
# elementwise_floordiv is integer only
if
op_type
==
"elementwise_floordiv"
:
return
np
.
random
.
randint
(
low
=
1
,
high
=
10000
,
size
=
[
1
],
dtype
=
np
.
int32
)
else
:
return
np
.
random
.
randn
(
1
).
astype
(
np
.
float32
)
for
shape
in
[[
32
]]:
for
op_type
in
[
...
...
@@ -157,6 +183,7 @@ class TrtConvertElementwiseTest_one_input_special_case1(TrtLayerAutoScanTest):
"elementwise_pow"
,
"elementwise_min"
,
"elementwise_max"
,
"elementwise_floordiv"
,
]:
for
axis
in
[
-
1
]:
self
.
dims
=
len
(
shape
)
...
...
@@ -175,12 +202,12 @@ class TrtConvertElementwiseTest_one_input_special_case1(TrtLayerAutoScanTest):
ops
=
ops
,
weights
=
{
"weight"
:
TensorConfig
(
data_gen
=
partial
(
generate_weight
)
data_gen
=
partial
(
generate_weight
,
op_type
)
)
},
inputs
=
{
"input_data"
:
TensorConfig
(
data_gen
=
partial
(
generate_input
,
shape
)
data_gen
=
partial
(
generate_input
,
shape
,
op_type
)
),
},
outputs
=
[
"output_data"
],
...
...
@@ -245,11 +272,23 @@ class TrtConvertElementwiseTest_one_input(TrtLayerAutoScanTest):
return
True
def
sample_program_configs
(
self
):
def
generate_input
(
shape
):
return
np
.
random
.
random
(
shape
).
astype
(
np
.
float32
)
def
generate_weight
():
return
np
.
random
.
randn
(
32
).
astype
(
np
.
float32
)
def
generate_input
(
shape
,
op_type
):
# elementwise_floordiv is integer only
if
op_type
==
"elementwise_floordiv"
:
return
np
.
random
.
randint
(
low
=
1
,
high
=
10000
,
size
=
shape
,
dtype
=
np
.
int32
)
else
:
return
np
.
random
.
random
(
shape
).
astype
(
np
.
float32
)
def
generate_weight
(
op_type
):
# elementwise_floordiv is integer only
if
op_type
==
"elementwise_floordiv"
:
return
np
.
random
.
randint
(
low
=
1
,
high
=
10000
,
size
=
[
32
],
dtype
=
np
.
int32
)
else
:
return
np
.
random
.
randn
(
32
).
astype
(
np
.
float32
)
for
batch
in
[
1
,
4
]:
for
shape
in
[
...
...
@@ -266,6 +305,7 @@ class TrtConvertElementwiseTest_one_input(TrtLayerAutoScanTest):
"elementwise_pow"
,
"elementwise_min"
,
"elementwise_max"
,
"elementwise_floordiv"
,
]:
for
axis
in
[
-
1
if
len
(
shape
)
==
1
else
1
]:
self
.
dims
=
len
(
shape
)
...
...
@@ -287,12 +327,14 @@ class TrtConvertElementwiseTest_one_input(TrtLayerAutoScanTest):
ops
=
ops
,
weights
=
{
"weight"
:
TensorConfig
(
data_gen
=
partial
(
generate_weight
)
data_gen
=
partial
(
generate_weight
,
op_type
)
)
},
inputs
=
{
"input_data"
:
TensorConfig
(
data_gen
=
partial
(
generate_input
,
shape
)
data_gen
=
partial
(
generate_input
,
shape
,
op_type
)
),
},
outputs
=
[
"output_data"
],
...
...
@@ -379,8 +421,14 @@ class TrtConvertElementwiseTest_two_input_without_broadcast(
return
True
def
sample_program_configs
(
self
):
def
generate_input
(
shape
):
return
np
.
random
.
random
(
shape
).
astype
(
np
.
float32
)
def
generate_input
(
shape
,
op_type
):
# elementwise_floordiv is integer only
if
op_type
==
"elementwise_floordiv"
:
return
np
.
random
.
randint
(
low
=
1
,
high
=
10000
,
size
=
shape
,
dtype
=
np
.
int32
)
else
:
return
np
.
random
.
random
(
shape
).
astype
(
np
.
float32
)
for
shape
in
[[
4
],
[
4
,
32
],
[
2
,
32
,
16
],
[
1
,
8
,
16
,
32
]]:
for
op_type
in
[
...
...
@@ -391,6 +439,7 @@ class TrtConvertElementwiseTest_two_input_without_broadcast(
"elementwise_pow"
,
"elementwise_min"
,
"elementwise_max"
,
"elementwise_floordiv"
,
]:
for
axis
in
[
0
,
-
1
]:
self
.
dims
=
len
(
shape
)
...
...
@@ -413,10 +462,10 @@ class TrtConvertElementwiseTest_two_input_without_broadcast(
weights
=
{},
inputs
=
{
"input_data1"
:
TensorConfig
(
data_gen
=
partial
(
generate_input
,
shape
)
data_gen
=
partial
(
generate_input
,
shape
,
op_type
)
),
"input_data2"
:
TensorConfig
(
data_gen
=
partial
(
generate_input
,
shape
)
data_gen
=
partial
(
generate_input
,
shape
,
op_type
)
),
},
outputs
=
[
"output_data"
],
...
...
@@ -530,8 +579,14 @@ class TrtConvertElementwiseTest_two_input_with_broadcast(TrtLayerAutoScanTest):
return
True
def
sample_program_configs
(
self
):
def
generate_input
(
shape
):
return
np
.
random
.
random
(
shape
).
astype
(
np
.
float32
)
def
generate_input
(
shape
,
op_type
):
# elementwise_floordiv is integer only
if
op_type
==
"elementwise_floordiv"
:
return
np
.
random
.
randint
(
low
=
1
,
high
=
10000
,
size
=
shape
,
dtype
=
np
.
int32
)
else
:
return
np
.
random
.
random
(
shape
).
astype
(
np
.
float32
)
input1_shape_list
=
[[
4
,
32
],
[
2
,
4
,
32
],
[
4
,
2
,
4
,
32
]]
input2_shape1_list
=
[[
32
],
[
4
,
32
],
[
2
,
4
,
32
]]
...
...
@@ -575,6 +630,7 @@ class TrtConvertElementwiseTest_two_input_with_broadcast(TrtLayerAutoScanTest):
"elementwise_pow"
,
"elementwise_min"
,
"elementwise_max"
,
"elementwise_floordiv"
,
]:
for
axis
in
axis_list
[
j
][
i
]:
self
.
shape1
=
input1_shape
...
...
@@ -599,12 +655,12 @@ class TrtConvertElementwiseTest_two_input_with_broadcast(TrtLayerAutoScanTest):
inputs
=
{
"input_data1"
:
TensorConfig
(
data_gen
=
partial
(
generate_input
,
input1_shape
generate_input
,
input1_shape
,
op_type
)
),
"input_data2"
:
TensorConfig
(
data_gen
=
partial
(
generate_input
,
input2_shape
generate_input
,
input2_shape
,
op_type
)
),
},
...
...
@@ -676,12 +732,23 @@ class TrtConvertElementwiseTest_one_input_corner_case(TrtLayerAutoScanTest):
return
True
def
sample_program_configs
(
self
):
def
generate_input
(
shape
):
return
np
.
random
.
random
(
shape
).
astype
(
np
.
float32
)
def
generate_input
(
shape
,
op_type
):
# elementwise_floordiv is integer only
if
op_type
==
"elementwise_floordiv"
:
return
np
.
random
.
randint
(
low
=
1
,
high
=
10000
,
size
=
shape
,
dtype
=
np
.
int32
)
else
:
return
np
.
random
.
random
(
shape
).
astype
(
np
.
float32
)
# use rand not randn to avoiding pow producing `NAN`
def
generate_weight
():
return
np
.
random
.
rand
(
32
).
astype
(
np
.
float32
)
def
generate_weight
(
op_type
):
if
op_type
==
"elementwise_floordiv"
:
return
np
.
random
.
randint
(
low
=
1
,
high
=
10000
,
size
=
[
32
],
dtype
=
np
.
int32
)
else
:
return
np
.
random
.
rand
(
32
).
astype
(
np
.
float32
)
for
batch
in
[
1
,
2
,
4
]:
for
shape
in
[
...
...
@@ -698,6 +765,7 @@ class TrtConvertElementwiseTest_one_input_corner_case(TrtLayerAutoScanTest):
"elementwise_pow"
,
"elementwise_min"
,
"elementwise_max"
,
"elementwise_floordiv"
,
]:
self
.
op_type
=
op_type
for
axis
in
[
-
1
if
len
(
shape
)
==
1
else
1
]:
...
...
@@ -720,12 +788,14 @@ class TrtConvertElementwiseTest_one_input_corner_case(TrtLayerAutoScanTest):
ops
=
ops
,
weights
=
{
"weight"
:
TensorConfig
(
data_gen
=
partial
(
generate_weight
)
data_gen
=
partial
(
generate_weight
,
op_type
)
)
},
inputs
=
{
"input_data"
:
TensorConfig
(
data_gen
=
partial
(
generate_input
,
shape
)
data_gen
=
partial
(
generate_input
,
shape
,
op_type
)
),
},
outputs
=
[
"output_data"
],
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录