Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
e6cabea1
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
e6cabea1
编写于
12月 14, 2022
作者:
Z
Zhang Jun
提交者:
GitHub
12月 14, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[inference][trt] add more unary op and square (#48534)
* add more unary op and square
上级
ceba70c3
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
262 addition
and
22 deletion
+262
-22
paddle/fluid/inference/api/analysis_predictor.cc
paddle/fluid/inference/api/analysis_predictor.cc
+26
-4
paddle/fluid/inference/tensorrt/convert/CMakeLists.txt
paddle/fluid/inference/tensorrt/convert/CMakeLists.txt
+1
-0
paddle/fluid/inference/tensorrt/convert/square_op.cc
paddle/fluid/inference/tensorrt/convert/square_op.cc
+47
-0
paddle/fluid/inference/tensorrt/convert/unary_op.cc
paddle/fluid/inference/tensorrt/convert/unary_op.cc
+18
-6
paddle/fluid/inference/tensorrt/op_teller.cc
paddle/fluid/inference/tensorrt/op_teller.cc
+20
-12
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_activation.py
...sts/unittests/ir/inference/test_trt_convert_activation.py
+4
-0
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_square.py
...d/tests/unittests/ir/inference/test_trt_convert_square.py
+140
-0
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_unary.py
...id/tests/unittests/ir/inference/test_trt_convert_unary.py
+6
-0
未找到文件。
paddle/fluid/inference/api/analysis_predictor.cc
浏览文件 @
e6cabea1
...
...
@@ -2284,13 +2284,9 @@ USE_TRT_CONVERTER(flatten_contiguous_range);
USE_TRT_CONVERTER
(
matmul
);
USE_TRT_CONVERTER
(
matmul_v2
);
USE_TRT_CONVERTER
(
bmm
);
USE_TRT_CONVERTER
(
rsqrt
);
USE_TRT_CONVERTER
(
conv2d
);
USE_TRT_CONVERTER
(
relu
);
USE_TRT_CONVERTER
(
exp
);
USE_TRT_CONVERTER
(
log
);
USE_TRT_CONVERTER
(
sigmoid
);
USE_TRT_CONVERTER
(
tanh
);
USE_TRT_CONVERTER
(
fc
);
USE_TRT_CONVERTER
(
pool2d
);
USE_TRT_CONVERTER
(
softmax
);
...
...
@@ -2346,6 +2342,32 @@ USE_TRT_CONVERTER(conv3d_transpose);
USE_TRT_CONVERTER
(
mish
);
USE_TRT_CONVERTER
(
deformable_conv
);
USE_TRT_CONVERTER
(
pool3d
)
USE_TRT_CONVERTER
(
square
);
// unary op
USE_TRT_CONVERTER
(
exp
);
USE_TRT_CONVERTER
(
log
);
USE_TRT_CONVERTER
(
sqrt
);
USE_TRT_CONVERTER
(
reciprocal
);
USE_TRT_CONVERTER
(
abs
);
USE_TRT_CONVERTER
(
sin
);
USE_TRT_CONVERTER
(
cos
);
USE_TRT_CONVERTER
(
tan
);
USE_TRT_CONVERTER
(
sinh
);
USE_TRT_CONVERTER
(
cosh
);
USE_TRT_CONVERTER
(
tanh
);
USE_TRT_CONVERTER
(
asin
);
USE_TRT_CONVERTER
(
acos
);
USE_TRT_CONVERTER
(
atan
);
USE_TRT_CONVERTER
(
asinh
);
USE_TRT_CONVERTER
(
acosh
);
USE_TRT_CONVERTER
(
atanh
);
USE_TRT_CONVERTER
(
ceil
);
USE_TRT_CONVERTER
(
floor
);
#if IS_TRT_VERSION_GE(8200)
USE_TRT_CONVERTER
(
round
);
USE_TRT_CONVERTER
(
sign
);
#endif
USE_TRT_CONVERTER
(
rsqrt
);
USE_TRT_CONVERTER
(
fused_preln_embedding_eltwise_layernorm
)
USE_TRT_CONVERTER
(
fused_embedding_eltwise_layernorm
);
USE_TRT_CONVERTER
(
preln_skip_layernorm
)
...
...
paddle/fluid/inference/tensorrt/convert/CMakeLists.txt
浏览文件 @
e6cabea1
...
...
@@ -18,6 +18,7 @@ list(
group_norm_op.cc
pad_op.cc
split_op.cc
square_op.cc
prelu_op.cc
leaky_relu_op.cc
gelu_op.cc
...
...
paddle/fluid/inference/tensorrt/convert/square_op.cc
0 → 100644
浏览文件 @
e6cabea1
/* Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/fluid/inference/tensorrt/convert/op_converter.h"
namespace
paddle
{
namespace
inference
{
namespace
tensorrt
{
class
SquareOpConverter
:
public
OpConverter
{
public:
SquareOpConverter
()
{}
void
operator
()(
const
framework
::
proto
::
OpDesc
&
op
,
const
framework
::
Scope
&
scope
,
bool
test_mode
)
override
{
framework
::
OpDesc
op_desc
(
op
,
nullptr
);
VLOG
(
3
)
<<
"convert a fluid sqaure op to tensorrt layer "
;
nvinfer1
::
ITensor
*
input_tensor
=
engine_
->
GetITensor
(
op_desc
.
Input
(
"X"
)[
0
]);
auto
*
layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
ElementWise
,
*
input_tensor
,
*
input_tensor
,
nvinfer1
::
ElementWiseOperation
::
kPROD
);
auto
output_name
=
op_desc
.
Output
(
"Out"
)[
0
];
RreplenishLayerAndOutput
(
layer
,
"square"
,
{
output_name
},
test_mode
);
}
};
}
// namespace tensorrt
}
// namespace inference
}
// namespace paddle
REGISTER_TRT_OP_CONVERTER
(
square
,
SquareOpConverter
);
paddle/fluid/inference/tensorrt/convert/unary_op.cc
浏览文件 @
e6cabea1
...
...
@@ -85,6 +85,7 @@ const std::unordered_map<std::string, std::vector<nvinfer1::UnaryOperation>>
{
"acos"
,
{
nvinfer1
::
UnaryOperation
::
kACOS
}},
{
"atan"
,
{
nvinfer1
::
UnaryOperation
::
kATAN
}},
{
"asinh"
,
{
nvinfer1
::
UnaryOperation
::
kASINH
}},
{
"acosh"
,
{
nvinfer1
::
UnaryOperation
::
kACOSH
}},
{
"atanh"
,
{
nvinfer1
::
UnaryOperation
::
kATANH
}},
{
"ceil"
,
{
nvinfer1
::
UnaryOperation
::
kCEIL
}},
{
"floor"
,
{
nvinfer1
::
UnaryOperation
::
kFLOOR
}},
...
...
@@ -92,12 +93,13 @@ const std::unordered_map<std::string, std::vector<nvinfer1::UnaryOperation>>
{
nvinfer1
::
UnaryOperation
::
kSQRT
,
nvinfer1
::
UnaryOperation
::
kRECIP
}},
{
"logical_not"
,
{
nvinfer1
::
UnaryOperation
::
kNOT
}},
{
"reciprocal"
,
{
nvinfer1
::
UnaryOperation
::
kRECIP
}},
#if IS_TRT_VERSION_GE(8200)
{
"sign"
,
{
nvinfer1
::
UnaryOperation
::
kSIGN
}},
#endif
#if IS_TRT_VERSION_GE(7000)
{
"erf"
,
{
nvinfer1
::
UnaryOperation
::
kERF
}},
#endif
#if IS_TRT_VERSION_GE(8200)
{
"sign"
,
{
nvinfer1
::
UnaryOperation
::
kSIGN
}},
{
"round"
,
{
nvinfer1
::
UnaryOperation
::
kROUND
}},
#endif
};
class
ExpOpConverter
:
public
UnaryOpConverter
{
...
...
@@ -154,6 +156,10 @@ class AsinhOpConverter : public UnaryOpConverter {
public:
AsinhOpConverter
()
{
op_type_
=
"asinh"
;
}
};
class
AcoshOpConverter
:
public
UnaryOpConverter
{
public:
AcoshOpConverter
()
{
op_type_
=
"acosh"
;
}
};
class
AtanhOpConverter
:
public
UnaryOpConverter
{
public:
AtanhOpConverter
()
{
op_type_
=
"atanh"
;
}
...
...
@@ -194,6 +200,10 @@ class ErfOpConverter : public UnaryOpConverter {
public:
ErfOpConverter
()
{
op_type_
=
"erf"
;
}
};
class
RoundOpConverter
:
public
UnaryOpConverter
{
public:
RoundOpConverter
()
{
op_type_
=
"round"
;
}
};
#endif
}
// namespace tensorrt
...
...
@@ -213,15 +223,17 @@ REGISTER_TRT_OP_CONVERTER(asin, AsinOpConverter);
REGISTER_TRT_OP_CONVERTER
(
acos
,
AcosOpConverter
);
REGISTER_TRT_OP_CONVERTER
(
atan
,
AtanOpConverter
);
REGISTER_TRT_OP_CONVERTER
(
asinh
,
AsinhOpConverter
);
REGISTER_TRT_OP_CONVERTER
(
acosh
,
AcoshOpConverter
);
REGISTER_TRT_OP_CONVERTER
(
atanh
,
AtanhOpConverter
);
REGISTER_TRT_OP_CONVERTER
(
ceil
,
CeilOpConverter
);
REGISTER_TRT_OP_CONVERTER
(
floor
,
FloorOpConverter
);
REGISTER_TRT_OP_CONVERTER
(
rsqrt
,
RsqrtOpConverter
);
REGISTER_TRT_OP_CONVERTER
(
logical_not
,
LogicalNotOpConverter
);
REGISTER_TRT_OP_CONVERTER
(
reciprocal
,
ReciprocalOpConverter
);
#if IS_TRT_VERSION_GE(8200)
REGISTER_TRT_OP_CONVERTER
(
sign
,
SignOpConverter
);
#endif
#if IS_TRT_VERSION_GE(7000)
REGISTER_TRT_OP_CONVERTER
(
erf
,
ErfOpConverter
);
#endif
#if IS_TRT_VERSION_GE(8200)
REGISTER_TRT_OP_CONVERTER
(
sign
,
SignOpConverter
);
REGISTER_TRT_OP_CONVERTER
(
round
,
RoundOpConverter
);
#endif
paddle/fluid/inference/tensorrt/op_teller.cc
浏览文件 @
e6cabea1
...
...
@@ -65,6 +65,10 @@ struct SimpleOpTypeSetTeller : public Teller {
int8_teller_set
.
insert
(
"sparse_fc"
);
teller_set
.
insert
(
"sparse_multihead_matmul"
);
int8_teller_set
.
insert
(
"sparse_multihead_matmul"
);
#endif
#if IS_TRT_VERSION_GE(8200)
teller_set
.
insert
(
"round"
);
int8_teller_set
.
insert
(
"round"
);
#endif
}
...
...
@@ -86,11 +90,11 @@ struct SimpleOpTypeSetTeller : public Teller {
"abs"
,
"sin"
,
"cos"
,
"tan"
,
"tanh"
,
"sinh"
,
"cosh"
,
"asin"
,
"acos"
,
"atan"
,
"asinh"
,
"atan
h"
,
"
ceil"
,
"floor"
,
"erf
"
,
"
reciprocal"
,
"silu"
,
"celu
"
,
"
tanh_shrink"
,
"logsigmoid"
,
"sign
"
,
"
logical_not
"
};
"atan"
,
"asinh"
,
"acos
h"
,
"
atanh"
,
"ceil"
,
"celu
"
,
"
erf"
,
"floor"
,
"round
"
,
"
sign"
,
"silu"
,
"logical_not
"
,
"
reciprocal"
,
"tanh_shrink"
,
"logsigmoid
"
};
if
(
act_op_list
.
find
(
op_type
)
!=
act_op_list
.
end
())
{
auto
*
block
=
desc
.
Block
();
if
(
block
==
nullptr
)
{
...
...
@@ -2456,6 +2460,7 @@ struct SimpleOpTypeSetTeller : public Teller {
"acos"
,
"atan"
,
"asinh"
,
"acosh"
,
"atanh"
,
"ceil"
,
"floor"
,
...
...
@@ -2464,6 +2469,7 @@ struct SimpleOpTypeSetTeller : public Teller {
"reciprocal"
,
"logical_not"
,
"erf"
,
"square"
,
"softmax"
,
"sigmoid"
,
"hard_swish"
,
...
...
@@ -2599,6 +2605,7 @@ struct SimpleOpTypeSetTeller : public Teller {
"acos"
,
"atan"
,
"asinh"
,
"acosh"
,
"atanh"
,
"ceil"
,
"floor"
,
...
...
@@ -2607,6 +2614,7 @@ struct SimpleOpTypeSetTeller : public Teller {
"reciprocal"
,
"logical_not"
,
"erf"
,
"square"
,
"softmax"
,
"sigmoid"
,
"hard_swish"
,
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_activation.py
浏览文件 @
e6cabea1
...
...
@@ -25,6 +25,10 @@ import paddle.inference as paddle_infer
class
TrtConvertActivationTest
(
TrtLayerAutoScanTest
):
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
ver
=
paddle_infer
.
get_trt_compile_version
()
if
ver
[
0
]
*
1000
+
ver
[
1
]
*
100
+
ver
[
0
]
*
10
<
8200
:
if
program_config
.
ops
[
0
].
type
==
"round"
:
return
False
return
True
def
sample_program_configs
(
self
):
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_square.py
0 → 100644
浏览文件 @
e6cabea1
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
unittest
from
functools
import
partial
from
typing
import
List
import
numpy
as
np
from
program_config
import
ProgramConfig
,
TensorConfig
from
trt_layer_auto_scan_test
import
TrtLayerAutoScanTest
import
paddle.inference
as
paddle_infer
class
TrtConvertSquareTest
(
TrtLayerAutoScanTest
):
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
return
True
def
sample_program_configs
(
self
):
def
generate_input1
(
dims
):
if
dims
==
1
:
return
np
.
ones
([
3
]).
astype
(
np
.
float32
)
elif
dims
==
2
:
return
np
.
ones
([
3
,
64
]).
astype
(
np
.
float32
)
elif
dims
==
3
:
return
np
.
ones
([
3
,
64
,
64
]).
astype
(
np
.
float32
)
else
:
return
np
.
ones
([
1
,
3
,
64
,
64
]).
astype
(
np
.
float32
)
for
dims
in
[
1
,
2
,
3
,
4
]:
for
alpha
in
[
1.0
,
2.0
,
3.0
]:
self
.
dims
=
dims
ops_config
=
[
{
"op_type"
:
"square"
,
"op_inputs"
:
{
"X"
:
[
"input_data"
],
},
"op_outputs"
:
{
"Out"
:
[
"output_data"
]},
"op_attrs"
:
{},
}
]
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
ops
=
ops
,
weights
=
{},
inputs
=
{
"input_data"
:
TensorConfig
(
data_gen
=
partial
(
generate_input1
,
dims
)
)
},
outputs
=
[
"output_data"
],
)
yield
program_config
def
sample_predictor_configs
(
self
,
program_config
)
->
(
paddle_infer
.
Config
,
List
[
int
],
float
):
def
generate_dynamic_shape
(
attrs
):
if
self
.
dims
==
1
:
self
.
dynamic_shape
.
min_input_shape
=
{
"input_data"
:
[
1
]}
self
.
dynamic_shape
.
max_input_shape
=
{
"input_data"
:
[
128
]}
self
.
dynamic_shape
.
opt_input_shape
=
{
"input_data"
:
[
64
]}
elif
self
.
dims
==
2
:
self
.
dynamic_shape
.
min_input_shape
=
{
"input_data"
:
[
1
,
32
]}
self
.
dynamic_shape
.
max_input_shape
=
{
"input_data"
:
[
4
,
64
]}
self
.
dynamic_shape
.
opt_input_shape
=
{
"input_data"
:
[
3
,
64
]}
elif
self
.
dims
==
3
:
self
.
dynamic_shape
.
min_input_shape
=
{
"input_data"
:
[
1
,
32
,
32
]}
self
.
dynamic_shape
.
max_input_shape
=
{
"input_data"
:
[
10
,
64
,
64
]
}
self
.
dynamic_shape
.
opt_input_shape
=
{
"input_data"
:
[
3
,
64
,
64
]}
else
:
self
.
dynamic_shape
.
min_input_shape
=
{
"input_data"
:
[
1
,
3
,
32
,
32
]
}
self
.
dynamic_shape
.
max_input_shape
=
{
"input_data"
:
[
4
,
3
,
64
,
64
]
}
self
.
dynamic_shape
.
opt_input_shape
=
{
"input_data"
:
[
1
,
3
,
64
,
64
]
}
def
clear_dynamic_shape
():
self
.
dynamic_shape
.
min_input_shape
=
{}
self
.
dynamic_shape
.
max_input_shape
=
{}
self
.
dynamic_shape
.
opt_input_shape
=
{}
def
generate_trt_nodes_num
(
attrs
,
dynamic_shape
):
if
not
dynamic_shape
and
self
.
dims
==
1
:
return
0
,
3
return
1
,
2
attrs
=
[
program_config
.
ops
[
i
].
attrs
for
i
in
range
(
len
(
program_config
.
ops
))
]
# for static_shape
clear_dynamic_shape
()
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
False
),
1e-5
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
False
),
(
1e-3
,
1e-3
)
# for dynamic_shape
generate_dynamic_shape
(
attrs
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
True
),
1e-5
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
True
),
(
1e-3
,
1e-3
)
def
test
(
self
):
self
.
run_test
()
if
__name__
==
"__main__"
:
unittest
.
main
()
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_unary.py
浏览文件 @
e6cabea1
...
...
@@ -25,6 +25,10 @@ import paddle.inference as paddle_infer
class
TrtConvertActivationTest
(
TrtLayerAutoScanTest
):
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
ver
=
paddle_infer
.
get_trt_compile_version
()
if
ver
[
0
]
*
1000
+
ver
[
1
]
*
100
+
ver
[
0
]
*
10
<
8200
:
if
program_config
.
ops
[
0
].
type
==
"round"
:
return
False
return
True
def
sample_program_configs
(
self
):
...
...
@@ -54,11 +58,13 @@ class TrtConvertActivationTest(TrtLayerAutoScanTest):
"acos"
,
"atan"
,
"asinh"
,
"acosh"
,
"atanh"
,
"ceil"
,
"floor"
,
"rsqrt"
,
"reciprocal"
,
"round"
,
"sign"
,
]:
self
.
dims
=
dims
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录