Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
f860de4a
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
f860de4a
编写于
12月 07, 2020
作者:
P
Pei Yang
提交者:
GitHub
12月 07, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support clip op trt converter (#29411)
上级
1dd7b97b
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
76 addition
and
4 deletion
+76
-4
paddle/fluid/inference/api/analysis_predictor.cc
paddle/fluid/inference/api/analysis_predictor.cc
+1
-0
paddle/fluid/inference/api/paddle_api.h
paddle/fluid/inference/api/paddle_api.h
+1
-1
paddle/fluid/inference/tensorrt/convert/CMakeLists.txt
paddle/fluid/inference/tensorrt/convert/CMakeLists.txt
+1
-1
paddle/fluid/inference/tensorrt/convert/clip_op.cc
paddle/fluid/inference/tensorrt/convert/clip_op.cc
+63
-0
paddle/fluid/inference/tensorrt/op_teller.cc
paddle/fluid/inference/tensorrt/op_teller.cc
+5
-2
python/paddle/fluid/tests/unittests/ir/inference/test_trt_subgraph_pass.py
...id/tests/unittests/ir/inference/test_trt_subgraph_pass.py
+5
-0
未找到文件。
paddle/fluid/inference/api/analysis_predictor.cc
浏览文件 @
f860de4a
...
...
@@ -1100,6 +1100,7 @@ USE_TRT_CONVERTER(skip_layernorm);
USE_TRT_CONVERTER
(
slice
);
USE_TRT_CONVERTER
(
scale
);
USE_TRT_CONVERTER
(
stack
);
USE_TRT_CONVERTER
(
clip
);
#endif
namespace
paddle_infer
{
...
...
paddle/fluid/inference/api/paddle_api.h
浏览文件 @
f860de4a
...
...
@@ -307,7 +307,7 @@ class PD_INFER_DECL PaddlePredictor {
/// This will save the IO copy for transfering inputs and outputs to predictor
/// workspace
/// and get some performance improvement.
/// To use it, one should call the AnalysisConfig.SwitchUseFeedFetchOp(
tru
e)
/// To use it, one should call the AnalysisConfig.SwitchUseFeedFetchOp(
fals
e)
/// and then use the `GetInputTensor` and `GetOutputTensor`
/// to directly write or read the input/output tensors.
/// \return Whether the run is successful
...
...
paddle/fluid/inference/tensorrt/convert/CMakeLists.txt
浏览文件 @
f860de4a
...
...
@@ -4,7 +4,7 @@ nv_library(tensorrt_converter
batch_norm_op.cc activation_op.cc softmax_op.cc concat_op.cc dropout_op.cc
pad_op.cc split_op.cc prelu_op.cc leaky_relu_op.cc gelu_op.cc layer_norm_op.cc multihead_matmul_op.cc
shuffle_channel_op.cc swish_op.cc instance_norm_op.cc stack_op.cc
emb_eltwise_layernorm.cc skip_layernorm.cc scale_op.cc slice_op.cc hard_sigmoid_op.cc hard_swish_op.cc
emb_eltwise_layernorm.cc skip_layernorm.cc scale_op.cc slice_op.cc hard_sigmoid_op.cc hard_swish_op.cc
clip_op.cc
DEPS tensorrt_engine tensorrt_plugin operator scope framework_proto op_registry
)
nv_test
(
test_op_converter SRCS test_op_converter.cc DEPS
...
...
paddle/fluid/inference/tensorrt/convert/clip_op.cc
0 → 100644
浏览文件 @
f860de4a
/* Copyright (c) 2020 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
framework
{
class
Scope
;
namespace
proto
{
class
OpDesc
;
}
// namespace proto
}
// namespace framework
}
// namespace paddle
namespace
paddle
{
namespace
inference
{
namespace
tensorrt
{
/*
* ClipOp
*/
class
ClipOpConverter
:
public
OpConverter
{
public:
void
operator
()(
const
framework
::
proto
::
OpDesc
&
op
,
const
framework
::
Scope
&
scope
,
bool
test_mode
)
override
{
#if IS_TRT_VERSION_GE(5130)
VLOG
(
3
)
<<
"convert a paddle clip op to tensorrt IActivationLayer."
;
framework
::
OpDesc
op_desc
(
op
,
nullptr
);
// Declare inputs
auto
*
input
=
engine_
->
GetITensor
(
op_desc
.
Input
(
"X"
)[
0
]);
float
min
=
BOOST_GET_CONST
(
float
,
op_desc
.
GetAttr
(
"min"
));
float
max
=
BOOST_GET_CONST
(
float
,
op_desc
.
GetAttr
(
"max"
));
auto
*
layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Activation
,
*
input
,
nvinfer1
::
ActivationType
::
kCLIP
);
layer
->
setAlpha
(
min
);
layer
->
setBeta
(
max
);
auto
output_name
=
op_desc
.
Output
(
"Out"
)[
0
];
RreplenishLayerAndOutput
(
layer
,
"clip"
,
{
output_name
},
test_mode
);
#else
PADDLE_THROW
(
platform
::
errors
::
Fatal
(
"clip TRT converter is only supported on TRT "
"5.1.3.0 or higher version."
));
#endif
}
};
}
// namespace tensorrt
}
// namespace inference
}
// namespace paddle
REGISTER_TRT_OP_CONVERTER
(
clip
,
ClipOpConverter
);
paddle/fluid/inference/tensorrt/op_teller.cc
浏览文件 @
f860de4a
...
...
@@ -32,8 +32,10 @@ struct SimpleOpTypeSetTeller : public Teller {
#if IS_TRT_VERSION_GE(5130)
teller_set
.
insert
(
"relu6"
);
teller_set
.
insert
(
"hard_sigmoid"
);
teller_set
.
insert
(
"clip"
);
int8_teller_set
.
insert
(
"relu6"
);
int8_teller_set
.
insert
(
"hard_sigmoid"
);
int8_teller_set
.
insert
(
"clip"
);
#endif
#if IS_TRT_VERSION_GE(6000)
teller_set
.
insert
(
"fused_embedding_eltwise_layernorm"
);
...
...
@@ -132,8 +134,9 @@ bool OpTeller::Tell(const std::string& op_type, const framework::OpDesc& desc,
auto
*
var_desc
=
block
->
FindVar
(
var_name
);
const
auto
shape
=
var_desc
->
GetShape
();
if
(
shape
.
size
()
<
3
)
{
VLOG
(
1
)
<<
"matmul op dims < 3 not supported in tensorrt, but got dims "
<<
shape
.
size
()
<<
", so jump it."
;
VLOG
(
1
)
<<
"matmul op dims < 3 not supported in tensorrt, but got dims "
<<
shape
.
size
()
<<
", so jump it."
;
return
false
;
}
}
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_subgraph_pass.py
浏览文件 @
f860de4a
...
...
@@ -343,6 +343,11 @@ class TensorRTSubgraphPassHardSigmoidTest(TensorRTSubgraphPassActivationTest):
return
fluid
.
layers
.
hard_sigmoid
(
x
)
class
TensorRTSubgraphPassClipTest
(
TensorRTSubgraphPassActivationTest
):
def
append_act
(
self
,
x
):
return
fluid
.
layers
.
clip
(
x
,
0
,
1
)
class
TensorRTSubgraphPassTanhTest
(
TensorRTSubgraphPassActivationTest
):
def
append_act
(
self
,
x
):
return
fluid
.
layers
.
tanh
(
x
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录